Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed Mar 19, 2024
1 parent d565404 commit 708a582
Showing 1 changed file with 53 additions and 12 deletions.
65 changes: 53 additions & 12 deletions server/neptune/adhoc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/runatlantis/atlantis/server/neptune/lyft/feature"
"github.com/runatlantis/atlantis/server/neptune/sync/crons"
ghClient "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform"
"github.com/runatlantis/atlantis/server/vcs/provider/github"

assetfs "github.com/elazarl/go-bindata-assetfs"
Expand All @@ -34,23 +35,24 @@ import (
"github.com/runatlantis/atlantis/server/static"
"github.com/uber-go/tally/v4"
"github.com/urfave/negroni"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/interceptor"
"go.temporal.io/sdk/worker"
)

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

TerraformTaskQueue string
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 AdhocTerraformWorkflowExecutionParams
TerraformTaskQueue string
}

func NewServer(config *adhocconfig.Config) (*Server, error) {
Expand Down Expand Up @@ -172,6 +174,39 @@ func NewServer(config *adhocconfig.Config) (*Server, error) {
return &server, nil
}

type AdhocTerraformWorkflowExecutionParams struct {
AtlantisRoot string
AtlantisRepo string
Revision string
DeploymentID string
// TODO: in separate PR, fill in github.Repo and terraform.Root (need helper funcs to get those)
}

// This function constructs the request we want to send to the temporal client,
// 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 AdhocTerraformWorkflowExecutionParams) (interface{}, error) {

Check failure on line 189 in server/neptune/adhoc/server.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

(Server).manuallyExecuteTerraformWorkflow - result 1 (error) is always nil (unparam)
request := workflows.TerraformRequest{
DeploymentID: adhocExecutionParams.DeploymentID,
Revision: adhocExecutionParams.Revision,
WorkflowMode: terraform.Adhoc,
}
options := client.StartWorkflowOptions{
TaskQueue: s.TerraformTaskQueue,
SearchAttributes: map[string]interface{}{
"atlantis_repository": adhocExecutionParams.AtlantisRepo,
"atlantis_root": adhocExecutionParams.AtlantisRoot,
},
}

res, err := s.TemporalClient.ExecuteWorkflow(context.Background(), options, workflows.Terraform, request)
if err != nil {
s.Logger.Error(err.Error())
}
return res, nil
}

func (s Server) Start() error {
defer s.shutdown()

Expand All @@ -191,6 +226,12 @@ func (s Server) Start() error {
s.Logger.InfoContext(ctx, "Shutting down terraform worker, resource clean up may still be occurring in the background")
}()

_, err := s.manuallyExecuteTerraformWorkflow(s.adhocExecutionParams)
if err != nil {
s.Logger.Error(err.Error())
return err
}

// Ensure server gracefully drains connections when stopped.
stop := make(chan os.Signal, 1)
// Stop on SIGINTs and SIGTERMs.
Expand Down

0 comments on commit 708a582

Please sign in to comment.