Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func init() {
workflowCmd.PersistentFlags().StringP("file", "f", "", "atmos workflow <name> -f <file>")
workflowCmd.PersistentFlags().Bool("dry-run", false, "atmos workflow <name> -f <file> --dry-run")
workflowCmd.PersistentFlags().StringP("stack", "s", "", "atmos workflow <name> -f <file> -s <stack>")
workflowCmd.PersistentFlags().String("from-step", "", "atmos workflow <name> -f <file> --from-step <step-name>")

err := workflowCmd.MarkPersistentFlagRequired("file")
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions examples/complete/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Geodesic: https://github.com/cloudposse/geodesic/
ARG GEODESIC_VERSION=1.6.0
ARG GEODESIC_VERSION=1.7.0
ARG GEODESIC_OS=debian
# atmos: https://github.com/cloudposse/atmos
ARG ATMOS_VERSION=1.20.0
ARG ATMOS_VERSION=1.22.0
# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.3.6
ARG TF_VERSION=1.3.7

FROM cloudposse/geodesic:${GEODESIC_VERSION}-${GEODESIC_OS}

Expand Down
3 changes: 3 additions & 0 deletions examples/complete/stacks/workflows/workflow1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ workflows:
description: Test workflow
steps:
- command: echo Command 1
name: step1
type: shell
- command: echo Command 2
name: step2
type: shell
- command: echo Command 3
name: step3
type: shell
- command: echo Command 4
type: shell
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/open-policy-agent/opa v0.48.0
github.com/otiai10/copy v1.9.0
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.37.0
github.com/santhosh-tekuri/jsonschema/v5 v5.1.1
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.14.0
Expand Down Expand Up @@ -121,6 +122,7 @@ require (
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sync v0.1.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw=
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
Comment thread
aknysh marked this conversation as resolved.
github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA=
github.com/santhosh-tekuri/jsonschema/v5 v5.1.1 h1:lEOLY2vyGIqKWUI9nzsOJRV3mb3WC9dXYORsLEUcoeY=
github.com/santhosh-tekuri/jsonschema/v5 v5.1.1/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
Expand Down Expand Up @@ -605,6 +607,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
16 changes: 6 additions & 10 deletions internal/exec/worflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func ExecuteWorkflowCmd(cmd *cobra.Command, args []string) error {
return err
}

fromStep, err := flags.GetString("from-step")
if err != nil {
return err
}

var workflowPath string
if u.IsPathAbsolute(workflowFile) {
workflowPath = workflowFile
Expand Down Expand Up @@ -93,19 +98,10 @@ func ExecuteWorkflowCmd(cmd *cobra.Command, args []string) error {
workflowDefinition = i
}

u.PrintInfo(fmt.Sprintf("\nExecuting the workflow '%s' from '%s'\n", workflow, workflowPath))
fmt.Println()

err = u.PrintAsYAML(workflowDefinition)
if err != nil {
return err
}

err = executeWorkflowSteps(workflow, workflowDefinition, dryRun, commandLineStack)
err = ExecuteWorkflow(workflow, workflowPath, &workflowDefinition, dryRun, commandLineStack, fromStep)
if err != nil {
return err
}

fmt.Println()
return nil
}
49 changes: 48 additions & 1 deletion internal/exec/worflow_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,58 @@ import (

cfg "github.com/cloudposse/atmos/pkg/config"
u "github.com/cloudposse/atmos/pkg/utils"

"github.com/samber/lo"
)

func executeWorkflowSteps(workflow string, workflowDefinition cfg.WorkflowDefinition, dryRun bool, commandLineStack string) error {
// ExecuteWorkflow executes an Atmos workflow
func ExecuteWorkflow(
workflow string,
workflowPath string,
workflowDefinition *cfg.WorkflowDefinition,
dryRun bool,
commandLineStack string,
fromStep string,
) error {
var steps = workflowDefinition.Steps

if len(steps) == 0 {
return fmt.Errorf("workflow '%s' does not have any steps defined", workflow)
}

// Check if the steps have the `name` attribute.
// If not, generate a friendly name consisting of a prefix of `step` and followed by the index of the
// step (the index starts with 1, so the first generated step name would be `step1`)
for index, step := range steps {
if step.Name == "" {
// When iterating through a slice with a range loop, if elements need to be changed,
// changing the returned value from the range is not changing the original slice element.
// That return value is a copy of the element.
// So doing changes to it will not affect the original elements.
// We need to access the element with the index returned from the range iterator and change it there.
// https://medium.com/@nsspathirana/common-mistakes-with-go-slices-95f2e9b362a9
steps[index].Name = fmt.Sprintf("step%d", index+1)
}
}

u.PrintInfo(fmt.Sprintf("\nExecuting the workflow '%s' from '%s'\n", workflow, workflowPath))

err := u.PrintAsYAML(workflowDefinition)
if err != nil {
return err
}

// If `--from-step` is specified, skip all the previous steps
if fromStep != "" {
steps = lo.DropWhile[cfg.WorkflowStep](steps, func(step cfg.WorkflowStep) bool {
return step.Name != fromStep
})

if len(steps) == 0 {
return fmt.Errorf("invalid '--from-step' flag. Workflow '%s' does not have a step with the name '%s'", workflow, fromStep)
}
}

for stepIdx, step := range steps {
var command = strings.TrimSpace(step.Command)
var commandType = strings.TrimSpace(step.Type)
Expand Down
13 changes: 9 additions & 4 deletions pkg/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,27 @@ type ConfigAndStacksInfo struct {
AtmosBasePath string
}

// Workflows

type WorkflowStep struct {
Name string `yaml:"name" json:"name" mapstructure:"name"`
Command string `yaml:"command" json:"command" mapstructure:"command"`
Stack string `yaml:"stack" json:"stack" mapstructure:"stack"`
Type string `yaml:"type" json:"type" mapstructure:"type"`
Stack string `yaml:"stack,omitempty" json:"stack,omitempty" mapstructure:"stack"`
Type string `yaml:"type,omitempty" json:"type,omitempty" mapstructure:"type"`
}

type WorkflowDefinition struct {
Description string `yaml:"description" json:"description" mapstructure:"description"`
Description string `yaml:"description,omitempty" json:"description,omitempty" mapstructure:"description"`
Steps []WorkflowStep `yaml:"steps" json:"steps" mapstructure:"steps"`
Stack string `yaml:"stack" json:"stack" mapstructure:"stack"`
Stack string `yaml:"stack,omitempty" json:"stack,omitempty" mapstructure:"stack"`
}

type WorkflowConfig map[string]WorkflowDefinition

type WorkflowFile map[string]WorkflowConfig

// EKS update-kubeconfig

type AwsEksUpdateKubeconfigContext struct {
Component string
Stack string
Expand Down
Loading