Skip to content

Commit

Permalink
Do not process stack configs when executing command `atmos vendor pul…
Browse files Browse the repository at this point in the history
…l` and the `--stack` flag is not specified (#740)

* modify InitCliConfig in ExecuteVendorPullCommand

* check stack flag is set on vendor pull

* remove 	checkAtmosConfig() from vendor pull

* Refactor vendor pull command to check Atmos configuration before execution

* add AtomsValidateOption option to checkAtmosConfig

* Refactor checkAtmosConfig function to use AtmosValidateOption instead of AtomsValidateOption

* Refactor vendor pull command to use WithStackValidation option for checking the stack

* modify comment

* updates

---------

Co-authored-by: Andriy Knysh <[email protected]>
Co-authored-by: aknysh <[email protected]>
  • Loading branch information
3 people authored Oct 30, 2024
1 parent a48ed22 commit 682d6e5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
37 changes: 31 additions & 6 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ import (
u "github.com/cloudposse/atmos/pkg/utils"
)

// ValidateConfig holds configuration options for Atmos validation.
// CheckStack determines whether stack configuration validation should be performed.
type ValidateConfig struct {
CheckStack bool
// Other configuration fields
}

type AtmosValidateOption func(*ValidateConfig)

func WithStackValidation(check bool) AtmosValidateOption {
return func(cfg *ValidateConfig) {
cfg.CheckStack = check
}
}

// processCustomCommands processes and executes custom commands
func processCustomCommands(
cliConfig schema.CliConfiguration,
Expand Down Expand Up @@ -323,17 +338,27 @@ func cloneCommand(orig *schema.Command) (*schema.Command, error) {
}

// checkAtmosConfig checks Atmos config
func checkAtmosConfig() {
func checkAtmosConfig(opts ...AtmosValidateOption) {
vCfg := &ValidateConfig{
CheckStack: true, // Default value true to check the stack
}

// Apply options
for _, opt := range opts {
opt(vCfg)
}

cliConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, false)
if err != nil {
u.LogErrorAndExit(cliConfig, err)
}

atmosConfigExists, err := u.IsDirectory(cliConfig.StacksBaseAbsolutePath)

if !atmosConfigExists || err != nil {
printMessageForMissingAtmosConfig(cliConfig)
os.Exit(0)
if vCfg.CheckStack {
atmosConfigExists, err := u.IsDirectory(cliConfig.StacksBaseAbsolutePath)
if !atmosConfigExists || err != nil {
printMessageForMissingAtmosConfig(cliConfig)
os.Exit(0)
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/vendor_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ var vendorPullCmd = &cobra.Command{
Long: `This command executes 'atmos vendor pull' CLI commands`,
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Run: func(cmd *cobra.Command, args []string) {
// Check Atmos configuration
checkAtmosConfig()
// WithStackValidation is a functional option that enables/disables stack configuration validation
// based on whether the --stack flag is provided
checkAtmosConfig(WithStackValidation(cmd.Flag("stack").Changed))

err := e.ExecuteVendorPullCmd(cmd, args)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions examples/quick-start-advanced/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Geodesic: https://github.com/cloudposse/geodesic/
ARG GEODESIC_VERSION=3.2.0
ARG GEODESIC_VERSION=3.3.0
ARG GEODESIC_OS=debian

# Atmos
# https://atmos.tools/
# https://github.com/cloudposse/atmos
# https://github.com/cloudposse/atmos/releases
ARG ATMOS_VERSION=1.93.0
ARG ATMOS_VERSION=1.97.0

# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.9.8
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ require (
github.com/arsham/figurine v1.3.0
github.com/bmatcuk/doublestar/v4 v4.7.1
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.1.1
github.com/charmbracelet/lipgloss v0.13.0
github.com/charmbracelet/bubbletea v1.1.2
github.com/charmbracelet/lipgloss v0.13.1
github.com/elewis787/boa v0.1.2
github.com/fatih/color v1.17.0
github.com/fatih/color v1.18.0
github.com/go-git/go-git/v5 v5.12.0
github.com/google/go-containerregistry v0.20.2
github.com/google/go-github/v59 v59.0.0
Expand Down Expand Up @@ -90,7 +90,7 @@ require (
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chainguard-dev/git-urls v1.0.2 // indirect
github.com/charmbracelet/x/ansi v0.2.3 // indirect
github.com/charmbracelet/x/ansi v0.4.0 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,12 @@ github.com/chainguard-dev/git-urls v1.0.2 h1:pSpT7ifrpc5X55n4aTTm7FFUE+ZQHKiqpiw
github.com/chainguard-dev/git-urls v1.0.2/go.mod h1:rbGgj10OS7UgZlbzdUQIQpT0k/D4+An04HJY7Ol+Y/o=
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
github.com/charmbracelet/bubbletea v1.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqKOCvppbPY=
github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4=
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY=
github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/bubbletea v1.1.2 h1:naQXF2laRxyLyil/i7fxdpiz1/k06IKquhm4vBfHsIc=
github.com/charmbracelet/bubbletea v1.1.2/go.mod h1:9HIU/hBV24qKjlehyj8z1r/tR9TYTQEag+cWZnuXo8E=
github.com/charmbracelet/lipgloss v0.13.1 h1:Oik/oqDTMVA01GetT4JdEC033dNzWoQHdWnHnQmXE2A=
github.com/charmbracelet/lipgloss v0.13.1/go.mod h1:zaYVJ2xKSKEnTEEbX6uAHabh2d975RJ+0yfkFpRBz5U=
github.com/charmbracelet/x/ansi v0.4.0 h1:NqwHA4B23VwsDn4H3VcNX1W1tOmgnvY1NDx5tOXdnOU=
github.com/charmbracelet/x/ansi v0.4.0/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
Expand Down Expand Up @@ -492,8 +492,8 @@ github.com/evanphx/json-patch/v5 v5.5.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2Vvl
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/vendor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ExecuteVendorPullCommand(cmd *cobra.Command, args []string) error {
// system dir, home dir, current dir, ENV vars, command-line arguments
cliConfig, err := cfg.InitCliConfig(info, processStacks)
if err != nil {
return err
return fmt.Errorf("failed to initialize CLI config: %w", err)
}

dryRun, err := flags.GetBool("dry-run")
Expand Down
2 changes: 1 addition & 1 deletion website/docs/integrations/atlantis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ on:
branches: [ main ]
env:
ATMOS_VERSION: 1.93.0
ATMOS_VERSION: 1.97.0
ATMOS_CLI_CONFIG_PATH: ./
jobs:
Expand Down

0 comments on commit 682d6e5

Please sign in to comment.