Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed Apr 10, 2024
1 parent 357bae4 commit 4ab6c43
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
22 changes: 7 additions & 15 deletions cmd/adhoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import (
"github.com/runatlantis/atlantis/server/legacy"
"github.com/runatlantis/atlantis/server/logging"
adhoc "github.com/runatlantis/atlantis/server/neptune/adhoc"
adhocHelpers "github.com/runatlantis/atlantis/server/neptune/adhoc/adhocexecutionhelpers"
adhocconfig "github.com/runatlantis/atlantis/server/neptune/adhoc/config"
neptune "github.com/runatlantis/atlantis/server/neptune/temporalworker/config"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/github"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform"
)

type Adhoc struct{}
Expand Down Expand Up @@ -58,18 +55,13 @@ func (a *Adhoc) NewServer(userConfig legacy.UserConfig, config legacy.Config) (S
DownloadURL: userConfig.TFDownloadURL,
LogFilters: globalCfg.TerraformLogFilter,
},
DataDir: userConfig.DataDir,
TemporalCfg: globalCfg.Temporal,
GithubCfg: globalCfg.Github,
App: appConfig,
CtxLogger: ctxLogger,
StatsNamespace: userConfig.StatsNamespace,
Metrics: globalCfg.Metrics,
AdhocExecutionParams: adhocHelpers.AdhocTerraformWorkflowExecutionParams{
Revision: "",
TerraformRoots: []terraform.Root{},
GithubRepo: github.Repo{},
},
DataDir: userConfig.DataDir,
TemporalCfg: globalCfg.Temporal,
GithubCfg: globalCfg.Github,
App: appConfig,
CtxLogger: ctxLogger,
StatsNamespace: userConfig.StatsNamespace,
Metrics: globalCfg.Metrics,
GithubHostname: userConfig.GithubHostname,
GithubAppID: userConfig.GithubAppID,
GithubAppKeyFile: userConfig.GithubAppKeyFile,
Expand Down
8 changes: 3 additions & 5 deletions server/neptune/adhoc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/palantir/go-githubapp/githubapp"
"github.com/runatlantis/atlantis/server/config/valid"
"github.com/runatlantis/atlantis/server/logging"
adhoc "github.com/runatlantis/atlantis/server/neptune/adhoc/adhocexecutionhelpers"
neptune "github.com/runatlantis/atlantis/server/neptune/temporalworker/config"
)

Expand All @@ -20,10 +19,9 @@ type Config struct {

StatsNamespace string

DataDir string
CtxLogger logging.Logger
App githubapp.Config
AdhocExecutionParams adhoc.AdhocTerraformWorkflowExecutionParams
DataDir string
CtxLogger logging.Logger
App githubapp.Config

GithubAppID int64
GithubAppKeyFile string
Expand Down
74 changes: 42 additions & 32 deletions server/neptune/adhoc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@ import (
)

type Server struct {
Logger logging.Logger
CronScheduler *internalSync.CronScheduler
Crons []*internalSync.Cron
HTTPServerProxy *neptune_http.ServerProxy
Port int
StatsScope tally.Scope
StatsCloser io.Closer
TemporalClient *temporal.ClientWrapper
TerraformActivities *activities.Terraform
GithubActivities *activities.Github
AdhocExecutionParams adhoc.AdhocTerraformWorkflowExecutionParams
TerraformTaskQueue string
RootConfigBuilder *root_config.Builder
GithubRetriever *adhocGithubHelpers.AdhocGithubRetriever
Logger logging.Logger
CronScheduler *internalSync.CronScheduler
Crons []*internalSync.Cron
HTTPServerProxy *neptune_http.ServerProxy
Port int
StatsScope tally.Scope
StatsCloser io.Closer
TemporalClient *temporal.ClientWrapper
TerraformActivities *activities.Terraform
GithubActivities *activities.Github
TerraformTaskQueue string
RootConfigBuilder *root_config.Builder
GithubRetriever *adhocGithubHelpers.AdhocGithubRetriever
Repo string
Root string
Revision string
}

func NewServer(config *adhocconfig.Config) (*Server, error) {
Expand Down Expand Up @@ -222,17 +224,16 @@ func NewServer(config *adhocconfig.Config) (*Server, error) {
Frequency: 1 * time.Minute,
},
},
HTTPServerProxy: httpServerProxy,
Port: config.ServerCfg.Port,
StatsScope: scope,
StatsCloser: statsCloser,
TemporalClient: temporalClient,
TerraformActivities: terraformActivities,
TerraformTaskQueue: config.TemporalCfg.TerraformTaskQueue,
GithubActivities: githubActivities,
AdhocExecutionParams: config.AdhocExecutionParams,
RootConfigBuilder: rootConfigBuilder,
GithubRetriever: githubRetriever,
HTTPServerProxy: httpServerProxy,
Port: config.ServerCfg.Port,
StatsScope: scope,
StatsCloser: statsCloser,
TemporalClient: temporalClient,
TerraformActivities: terraformActivities,
TerraformTaskQueue: config.TemporalCfg.TerraformTaskQueue,
GithubActivities: githubActivities,
RootConfigBuilder: rootConfigBuilder,
GithubRetriever: githubRetriever,
}
return &server, nil
}
Expand All @@ -241,18 +242,18 @@ func NewServer(config *adhocconfig.Config) (*Server, error) {
// then executes the Terraform workflow. Note normally this workflow is executed
// when a request is made to the server, but we are manually executing it here,
// since we don't care about requests in adhoc mode.
func (s Server) manuallyExecuteTerraformWorkflow(adhocExecutionParams adhoc.AdhocTerraformWorkflowExecutionParams) (interface{}, error) {
func (s Server) manuallyExecuteTerraformWorkflow(repo ghClient.Repo, revision string, root terraform.Root) (interface{}, error) {
request := workflows.TerraformRequest{
Revision: adhocExecutionParams.Revision,
Revision: revision,
WorkflowMode: terraform.Adhoc,
Root: adhocExecutionParams.TerraformRoot,
Repo: adhocExecutionParams.GithubRepo,
Root: root,
Repo: repo,
}
options := client.StartWorkflowOptions{
TaskQueue: s.TerraformTaskQueue,
SearchAttributes: map[string]interface{}{
"atlantis_repository": adhocExecutionParams.AtlantisRepo,
"atlantis_root": adhocExecutionParams.AtlantisRoot,
"atlantis_repository": repo.GetFullName(),
"atlantis_root": root.Name,
},
}

Expand Down Expand Up @@ -290,9 +291,18 @@ func (s Server) Start() error {
wg.Add(1)
go func() {
defer wg.Done()
_, err := s.manuallyExecuteTerraformWorkflow(s.AdhocExecutionParams)

adhocExecutionParams, err := adhoc.ConstructAdhocExecParamsWithRootCfgBuilderAndRepoRetriever(ctx, s.Repo, s.Revision, s.GithubRetriever, s.RootConfigBuilder)
if err != nil {
s.Logger.Error(err.Error())
return
}

for _, root := range adhocExecutionParams.TerraformRoots {
_, err := s.manuallyExecuteTerraformWorkflow(adhocExecutionParams.GithubRepo, adhocExecutionParams.Revision, root)
if err != nil {
s.Logger.Error(err.Error())
}
}
}()

Expand Down

0 comments on commit 4ab6c43

Please sign in to comment.