Skip to content

Commit

Permalink
Merge branch 'main' into add-component-docs-arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
RoseSecurity authored Oct 29, 2024
2 parents ac2f3e9 + a48ed22 commit e67ca58
Show file tree
Hide file tree
Showing 26 changed files with 408 additions and 168 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ on:
- main
- release/v*
paths-ignore:
- '.github/**'
- 'docs/**'
- 'examples/**'
- 'test/**'
- ".github/**"
- "docs/**"
- "examples/**"
- "test/**"

workflow_dispatch:

Expand Down Expand Up @@ -94,29 +94,29 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- uses: hadolint/[email protected]
id: hadolint
with:
dockerfile: Dockerfile
failure-threshold: warning
format: sarif
output-file: hadolint.sarif
# https://github.com/hadolint/hadolint?tab=readme-ov-file#rules
# DL3008 Pin versions in apt-get install
ignore: DL3008

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
# Path to SARIF file relative to the root of the repository
sarif_file: hadolint.sarif
# Optional category for the results (used to differentiate multiple results for one commit)
category: hadolint
wait-for-processing: true
- name: Check out code
uses: actions/checkout@v4

- uses: hadolint/[email protected]
id: hadolint
with:
dockerfile: Dockerfile
failure-threshold: warning
format: sarif
output-file: hadolint.sarif
# https://github.com/hadolint/hadolint?tab=readme-ov-file#rules
# DL3008 Pin versions in apt-get install
ignore: DL3008

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
# Path to SARIF file relative to the root of the repository
sarif_file: hadolint.sarif
# Optional category for the results (used to differentiate multiple results for one commit)
category: hadolint
wait-for-processing: true

# run localstack demo tests
localstack:
Expand Down Expand Up @@ -254,7 +254,7 @@ jobs:
# - demo-mock-architecture
# - demo-stack-templating
# - demo-multi-cloud
# - demo-vendoring
- demo-vendoring

timeout-minutes: 20
steps:
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ builds:
binary: atmos
ldflags:
# Set `atmos` version to the GitHub release tag using Go `ldflags`
- '-s -w -X "github.com/cloudposse/atmos/cmd.Version={{.Version}}"'
- '-s -w -X "github.com/cloudposse/atmos/pkg/version.Version={{.Version}}"'

archives:
- format: binary
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ get:
go get

build: get
env $(if $(GOOS),GOOS=$(GOOS)) $(if $(GOARCH),GOARCH=$(GOARCH)) go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/cmd.Version=${VERSION}'"
env $(if $(GOOS),GOOS=$(GOOS)) $(if $(GOARCH),GOARCH=$(GOARCH)) go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/pkg/version.Version=${VERSION}'"

version: build
chmod +x ./build/atmos
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

version="0.0.1"

go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/cmd.Version=$version'"
go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/version.Version=$version'"

# https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications
# https://blog.kowalczyk.info/article/vEja/embedding-build-number-in-go-executable.html
Expand Down
7 changes: 3 additions & 4 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
tuiUtils "github.com/cloudposse/atmos/internal/tui/utils"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/cloudposse/atmos/pkg/version"
)

var Version = "0.0.1"

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the CLI version",
Expand All @@ -27,14 +26,14 @@ var versionCmd = &cobra.Command{
u.LogErrorAndExit(schema.CliConfiguration{}, err)
}

u.PrintMessage(fmt.Sprintf("\U0001F47D Atmos %s on %s/%s", Version, runtime.GOOS, runtime.GOARCH))
u.PrintMessage(fmt.Sprintf("\U0001F47D Atmos %s on %s/%s", version.Version, runtime.GOOS, runtime.GOARCH))
fmt.Println()

// Check for the latest Atmos release on GitHub
latestReleaseTag, err := u.GetLatestGitHubRepoRelease("cloudposse", "atmos")
if err == nil && latestReleaseTag != "" {
latestRelease := strings.TrimPrefix(latestReleaseTag, "v")
currentRelease := strings.TrimPrefix(Version, "v")
currentRelease := strings.TrimPrefix(version.Version, "v")
if latestRelease != currentRelease {
printMessageToUpgradeToAtmosLatestRelease(latestRelease)
}
Expand Down
12 changes: 6 additions & 6 deletions examples/demo-helmfile/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ schemas:
components:
helmfile:
base_path: "components/helmfile"
use_eks: false
kubeconfig_path: "{{ .Env.KUBECONFIG }}"
helm_aws_profile_pattern: default
cluster_name_pattern: 'demo'

stacks:
base_path: "stacks"
Expand All @@ -31,10 +30,11 @@ commands:
description: "Run all tests"
steps:
- atmos validate stacks
# FIXME: `atmos helmfile apply` assumes EKS
#- atmos helmfile apply demo -s dev
- atmos helmfile generate varfile demo -s dev
- helmfile -f components/helmfile/nginx/helmfile.yaml apply --values dev-demo.helmfile.vars.yaml
- atmos helmfile apply demo -s dev

# This is equivalent to the following commands:
#- atmos helmfile generate varfile demo -s dev
#- helmfile -f components/helmfile/nginx/helmfile.yaml apply --values dev-demo.helmfile.vars.yaml

# Use Nested Custom Commands to provide easier interface for Docker Compose
- name: "k3s"
Expand Down
11 changes: 10 additions & 1 deletion examples/demo-vendoring/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ components:
deploy_run_init: true
init_run_reconfigure: true
auto_generate_backend_file: false

stacks:
base_path: "stacks"
included_paths:
Expand All @@ -19,3 +19,12 @@ stacks:
logs:
file: "/dev/stderr"
level: Info

# Custom CLI commands

# No arguments or flags are required
commands:
- name: "test"
description: "Run all tests"
steps:
- atmos vendor pull
6 changes: 6 additions & 0 deletions internal/exec/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/cloudposse/atmos/pkg/version"
)

// processHelp processes help commands
Expand Down Expand Up @@ -45,6 +46,11 @@ func processHelp(componentType string, command string) error {
u.PrintMessage(" - double-dash '--' can be used to signify the end of the options for Atmos and the start of the additional " +
"native arguments and flags for the 'terraform' commands. " +
"For example: atmos terraform plan <component> -s <stack> -- -refresh=false -lock=false")

u.PrintMessage(fmt.Sprintf(" - '--append-user-agent' flag sets the TF_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. "+
"Example: 'Atmos/%s (Cloud Posse; +https://atmos.tools)'. "+
"If not specified, defaults to 'atmos %s'\n", version.Version, version.Version))

}

if componentType == "helmfile" {
Expand Down
10 changes: 10 additions & 0 deletions internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
// https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_in_automation
info.ComponentEnvList = append(info.ComponentEnvList, "TF_IN_AUTOMATION=true")

// Set 'TF_APPEND_USER_AGENT' ENV var based on precedence
// Precedence: Environment Variable > atmos.yaml > Default
appendUserAgent := cliConfig.Components.Terraform.AppendUserAgent
if envUA, exists := os.LookupEnv("TF_APPEND_USER_AGENT"); exists && envUA != "" {
appendUserAgent = envUA
}
if appendUserAgent != "" {
info.ComponentEnvList = append(info.ComponentEnvList, fmt.Sprintf("TF_APPEND_USER_AGENT=%s", appendUserAgent))
}

// Print ENV vars if they are found in the component's stack config
if len(info.ComponentEnvList) > 0 {
u.LogDebug(cliConfig, "\nUsing ENV vars:")
Expand Down
14 changes: 14 additions & 0 deletions internal/exec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
cfg.DeployRunInitFlag,
cfg.InitRunReconfigure,
cfg.AutoGenerateBackendFileFlag,
cfg.AppendUserAgentFlag,
cfg.FromPlanFlag,
cfg.PlanFileFlag,
cfg.HelpFlag1,
Expand Down Expand Up @@ -668,6 +669,19 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche
info.TerraformDir = terraformDirFlagParts[1]
}

if arg == cfg.AppendUserAgentFlag {
if len(inputArgsAndFlags) <= (i + 1) {
return info, fmt.Errorf("invalid flag: %s", arg)
}
info.AppendUserAgent = inputArgsAndFlags[i+1]
} else if strings.HasPrefix(arg+"=", cfg.AppendUserAgentFlag) {
var appendUserAgentFlagParts = strings.Split(arg, "=")
if len(appendUserAgentFlagParts) != 2 {
return info, fmt.Errorf("invalid flag: %s", arg)
}
info.AppendUserAgent = appendUserAgentFlagParts[1]
}

if arg == cfg.HelmfileCommandFlag {
if len(inputArgsAndFlags) <= (i + 1) {
return info, fmt.Errorf("invalid flag: %s", arg)
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/cloudposse/atmos/pkg/version"
)

var (
Expand Down Expand Up @@ -43,6 +44,7 @@ var (
DeployRunInit: true,
InitRunReconfigure: true,
AutoGenerateBackendFile: true,
AppendUserAgent: fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version),
},
Helmfile: schema.Helmfile{
BasePath: "components/helmfile",
Expand Down Expand Up @@ -105,6 +107,7 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks

// Default configuration values
v.SetDefault("components.helmfile.use_eks", true)
v.SetDefault("components.terraform.append_user_agent", fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version))

// Process config in system folder
configFilePath1 := ""
Expand Down Expand Up @@ -243,6 +246,11 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks
cliConfig.BasePath = configAndStacksInfo.AtmosBasePath
}

// After unmarshalling, ensure AppendUserAgent is set if still empty
if cliConfig.Components.Terraform.AppendUserAgent == "" {
cliConfig.Components.Terraform.AppendUserAgent = fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version)
}

// Check config
err = checkConfig(cliConfig)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (

DeployRunInitFlag = "--deploy-run-init"
AutoGenerateBackendFileFlag = "--auto-generate-backend-file"
AppendUserAgentFlag = "--append-user-agent"
InitRunReconfigure = "--init-run-reconfigure"

FromPlanFlag = "--from-plan"
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ func processEnvVars(cliConfig *schema.CliConfiguration) error {
cliConfig.Logs.Level = logsLevel
}

tfAppendUserAgent := os.Getenv("ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT")
if len(tfAppendUserAgent) > 0 {
u.LogTrace(*cliConfig, fmt.Sprintf("Found ENV var ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT=%s", tfAppendUserAgent))
cliConfig.Components.Terraform.AppendUserAgent = tfAppendUserAgent
}

listMergeStrategy := os.Getenv("ATMOS_SETTINGS_LIST_MERGE_STRATEGY")
if len(listMergeStrategy) > 0 {
u.LogTrace(*cliConfig, fmt.Sprintf("Found ENV var ATMOS_SETTINGS_LIST_MERGE_STRATEGY=%s", listMergeStrategy))
Expand Down
2 changes: 2 additions & 0 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type TemplatesSettingsGomplate struct {
type Terraform struct {
BasePath string `yaml:"base_path" json:"base_path" mapstructure:"base_path"`
ApplyAutoApprove bool `yaml:"apply_auto_approve" json:"apply_auto_approve" mapstructure:"apply_auto_approve"`
AppendUserAgent string `yaml:"append_user_agent" json:"append_user_agent" mapstructure:"append_user_agent"`
DeployRunInit bool `yaml:"deploy_run_init" json:"deploy_run_init" mapstructure:"deploy_run_init"`
InitRunReconfigure bool `yaml:"init_run_reconfigure" json:"init_run_reconfigure" mapstructure:"init_run_reconfigure"`
AutoGenerateBackendFile bool `yaml:"auto_generate_backend_file" json:"auto_generate_backend_file" mapstructure:"auto_generate_backend_file"`
Expand Down Expand Up @@ -132,6 +133,7 @@ type ArgsAndFlagsInfo struct {
DeployRunInit string
InitRunReconfigure string
AutoGenerateBackendFile string
AppendUserAgent string
UseTerraformPlan bool
PlanFile string
DryRun bool
Expand Down
5 changes: 5 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package version

// Version holds the current version of the Atmos CLI.
// It can be set dynamically during build time using ldflags.
var Version = "0.0.1" // Default version; will be overridden during build
14 changes: 8 additions & 6 deletions website/docs/cli/commands/terraform/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --re
atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr ./errors.txt

atmos terraform plan test/test-component -s tenant1-ue2-dev -- -refresh=false -lock=false

atmos terraform plan test/test-component -s tenant1-ue2-dev --append-user-agent "Acme/1.0 (Build 1234; arm64)"
```

## Arguments
Expand All @@ -124,12 +126,12 @@ atmos terraform plan test/test-component -s tenant1-ue2-dev -- -refresh=false -l

## Flags

| Flag | Description | Alias | Required |
| :------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------- | :---- | :------- |
| `--stack` | Atmos stack | `-s` | yes |
| `--dry-run` | Dry run | | no |
| `--redirect-stderr` | File descriptor to redirect `stderr` to.<br/>Errors can be redirected to any file or any standard file descriptor<br/>(including `/dev/null`) | | no |

| Flag | Description | Alias | Required |
| :------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------- | :---- | :------- |
| `--stack` | Atmos stack | `-s` | yes |
| `--dry-run` | Dry run | | no |
| `--redirect-stderr` | File descriptor to redirect `stderr` to.<br/>Errors can be redirected to any file or any standard file descriptor<br/>(including `/dev/null`) | | no |
| `--append-user-agent` | Append a custom User-Agent to Terraform requests. Can also be set using the ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT environment variable.| | no |
<br />

:::note
Expand Down
2 changes: 0 additions & 2 deletions website/docs/core-concepts/deploy/deploy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Intro from '@site/src/components/Intro';
Once you're done developing your components and configuring them with stacks, you can deploy them with a single command or in a CI/CD pipeline.
</Intro>


In Atmos, when we talk about "Deployment," it refers to taking the [fully rendered and deep-merged configuration](/core-concepts/describe) of a [stack](/core-concepts/stacks) and provisioning an instance of one of the components. We call this a "component instance," and it's simply a component that has been deployed in a specific stack.

### Deployment in Atmos
Expand Down Expand Up @@ -40,7 +39,6 @@ All configurations in Atmos are defined in YAML. If you can write a Terraform mo
- [Spacelift](/integrations/spacelift): Our Spacelift integrations support dependency order application.
- [Atlantis](/integrations/atlantis): By customizing the template generated for Atlantis, similar dependency handling can probably be achieved, although we do not have any documentation on this.


### Automate Cold Starts

Atmos supports [workflows](/core-concepts/workflows), which provide a convenient way to automate deployments, especially for cold starts. A cold start is when you go from zero to a full deployment, typically occurring on day zero in the life cycle of your resources.
Loading

0 comments on commit e67ca58

Please sign in to comment.