Skip to content

Commit

Permalink
Merge branch 'main' into fix/DEV-2739
Browse files Browse the repository at this point in the history
  • Loading branch information
osterman authored Dec 6, 2024
2 parents 8b52ee2 + 9e0ff68 commit 6d2e119
Show file tree
Hide file tree
Showing 22 changed files with 352 additions and 60 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Deploy Preview"

on:
workflow_run:
workflows: [Website Deploy Preview]
types:
- completed

env:
AWS_REGION: us-east-2
IAM_ROLE_ARN: arn:aws:iam::068007702576:role/cplive-plat-ue2-dev-atmos-docs-gha
IAM_ROLE_SESSION_NAME: cloudposse-atmos-ci-deploy-pr-${{ github.event.workflow_run.pull_requests.0.number }}
S3_BUCKET_NAME: cplive-plat-ue2-dev-atmos-docs-origin
PR_NUMBER: ${{ github.event.workflow_run.pull_requests.0.number }}
DEPLOYMENT_HOST: pr-${{ github.event.workflow_run.pull_requests.0.number }}.atmos-docs.ue2.dev.plat.cloudposse.org
ALGOLIA_INDEX_NAME: atmos-preview.tools
ALGOLIA_APP_ID: 32YOERUX83

# These permissions are needed to interact with the GitHub's OIDC Token endpoint
permissions:
id-token: write
contents: read

jobs:
website-deploy-preview:
# Do not deploy the website to the preview environment if the PR has the label 'website-no-deploy' or the workflow run failed
if: ${{ github.event.workflow_run.conclusion == 'success' && !contains(github.event.workflow_run.pull_requests.*.labels.*.name, 'website-no-deploy') }}
runs-on: ubuntu-latest
environment:
name: preview
url: https://${{ env.DEPLOYMENT_HOST }}

steps:
# https://github.com/marketplace/actions/configure-aws-credentials-action-for-github-actions
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.IAM_ROLE_ARN }}
role-session-name: ${{ env.IAM_ROLE_SESSION_NAME }}

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: website
path: website/build
run-id: ${{ github.event.workflow_run.id }}

- name: Copy Website to S3 Bucket PR Folder
run: |
cd website/build
aws sts get-caller-identity
aws s3 sync . s3://${{ env.S3_BUCKET_NAME }}/pr-${{ env.PR_NUMBER }}/ --delete
aws s3 ls s3://${{ env.S3_BUCKET_NAME }}/pr-${{ env.PR_NUMBER }}/ --recursive --human-readable --summarize
- name: ReIndex with Algolia
if: ${{ contains(github.event.workflow_run.pull_requests.*.labels.*.name, 'reindex') }}
env:
ALGOLIA_SCRAPER_API_KEY: ${{ secrets.ALGOLIA_SCRAPER_API_KEY }}
run: |
./website/algolia/reindex.sh
8 changes: 8 additions & 0 deletions .github/workflows/website-deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ jobs:
npm install --only=production
npm run build:site
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: website
path: website/build
if-no-files-found: error
retention-days: 1

- name: Copy Website to S3 Bucket PR Folder
run: |
cd website/build
Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func executeCustomCommand(
}
if component == "" || component == "<no value>" {
u.LogErrorAndExit(cliConfig, fmt.Errorf("the command defines an invalid 'component_config.component: %s' in '%s'",
commandConfig.ComponentConfig.Component, cfg.CliConfigFileName+cfg.DefaultStackConfigFileExtension))
commandConfig.ComponentConfig.Component, cfg.CliConfigFileName+u.DefaultStackConfigFileExtension))
}

// Process Go templates in the command's 'component_config.stack'
Expand All @@ -276,7 +276,7 @@ func executeCustomCommand(
}
if stack == "" || stack == "<no value>" {
u.LogErrorAndExit(cliConfig, fmt.Errorf("the command defines an invalid 'component_config.stack: %s' in '%s'",
commandConfig.ComponentConfig.Stack, cfg.CliConfigFileName+cfg.DefaultStackConfigFileExtension))
commandConfig.ComponentConfig.Stack, cfg.CliConfigFileName+u.DefaultStackConfigFileExtension))
}

// Get the config for the component in the stack
Expand Down
5 changes: 4 additions & 1 deletion cmd/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ var workflowCmd = &cobra.Command{
Example: "atmos workflow\n" +
"atmos workflow <name> -f <file>\n" +
"atmos workflow <name> -f <file> -s <stack>\n" +
"atmos workflow <name> -f <file> --from-step <step-name>",
"atmos workflow <name> -f <file> --from-step <step-name>\n\n" +
"To resume the workflow from this step, run:\n" +
"atmos workflow deploy-infra -f workflow1 --from-step deploy-vpc\n\n" +
"For more details refer to https://atmos.tools/cli/commands/workflow/",
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Run: func(cmd *cobra.Command, args []string) {
err := e.ExecuteWorkflowCmd(cmd, args)
Expand Down
2 changes: 1 addition & 1 deletion examples/quick-start-advanced/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG GEODESIC_OS=debian
# https://atmos.tools/
# https://github.com/cloudposse/atmos
# https://github.com/cloudposse/atmos/releases
ARG ATMOS_VERSION=1.111.0
ARG ATMOS_VERSION=1.118.0

# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.5.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ components:
metadata:
# Point to the Terraform component
component: "test/template-functions-test2"
terraform_workspace: '{{ .vars.tenant }}-{{ .vars.environment }}-{{ .vars.stage }}-test'
settings:
spacelift:
workspace_enabled: false
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/zclconf/go-cty v1.15.1
golang.org/x/term v0.26.0
golang.org/x/term v0.27.0
gopkg.in/yaml.v3 v3.0.1
mvdan.cc/sh/v3 v3.10.0
)
Expand Down Expand Up @@ -247,7 +247,7 @@ require (
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/tools v0.22.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,10 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
Expand Down Expand Up @@ -1543,15 +1543,15 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
39 changes: 32 additions & 7 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ProcessYAMLConfigFiles(
stackFileName := strings.TrimSuffix(
strings.TrimSuffix(
u.TrimBasePathFromPath(stackBasePath+"/", p),
cfg.DefaultStackConfigFileExtension),
u.DefaultStackConfigFileExtension),
".yml",
)

Expand Down Expand Up @@ -371,8 +371,33 @@ func ProcessYAMLConfigFile(
impWithExt := imp
ext := filepath.Ext(imp)
if ext == "" {
ext = cfg.DefaultStackConfigFileExtension
impWithExt = imp + ext
extensions := []string{
u.YamlFileExtension,
u.YmlFileExtension,
u.YamlTemplateExtension,
u.YmlTemplateExtension,
}

found := false
for _, extension := range extensions {
testPath := path.Join(basePath, imp+extension)
if _, err := os.Stat(testPath); err == nil {
impWithExt = imp + extension
found = true
break
}
}

if !found {
// Default to .yaml if no file is found
impWithExt = imp + u.DefaultStackConfigFileExtension
}
} else if ext == u.YamlFileExtension || ext == u.YmlFileExtension {
// Check if there's a template version of this file
templatePath := impWithExt + u.TemplateExtension
if _, err := os.Stat(path.Join(basePath, templatePath)); err == nil {
impWithExt = templatePath
}
}

impWithExtPath := path.Join(basePath, impWithExt)
Expand Down Expand Up @@ -452,7 +477,7 @@ func ProcessYAMLConfigFile(
importRelativePathWithExt := strings.Replace(importFile, basePath+"/", "", 1)
ext2 := filepath.Ext(importRelativePathWithExt)
if ext2 == "" {
ext2 = cfg.DefaultStackConfigFileExtension
ext2 = u.DefaultStackConfigFileExtension
}
importRelativePathWithoutExt := strings.TrimSuffix(importRelativePathWithExt, ext2)
importsConfig[importRelativePathWithoutExt] = yamlConfigRaw
Expand Down Expand Up @@ -493,7 +518,7 @@ func ProcessStackConfig(
stackName := strings.TrimSuffix(
strings.TrimSuffix(
u.TrimBasePathFromPath(stacksBasePath+"/", stack),
cfg.DefaultStackConfigFileExtension),
u.DefaultStackConfigFileExtension),
".yml",
)

Expand Down Expand Up @@ -1859,13 +1884,13 @@ func CreateComponentStackMap(

for stack, components := range stackComponentMap["terraform"] {
for _, component := range components {
componentStackMap["terraform"][component] = append(componentStackMap["terraform"][component], strings.Replace(stack, cfg.DefaultStackConfigFileExtension, "", 1))
componentStackMap["terraform"][component] = append(componentStackMap["terraform"][component], strings.Replace(stack, u.DefaultStackConfigFileExtension, "", 1))
}
}

for stack, components := range stackComponentMap["helmfile"] {
for _, component := range components {
componentStackMap["helmfile"][component] = append(componentStackMap["helmfile"][component], strings.Replace(stack, cfg.DefaultStackConfigFileExtension, "", 1))
componentStackMap["helmfile"][component] = append(componentStackMap["helmfile"][component], strings.Replace(stack, u.DefaultStackConfigFileExtension, "", 1))
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
}
return nil
}

varFile := constructTerraformComponentVarfileName(info)
planFile := constructTerraformComponentPlanfileName(info)

// Print component variables and write to file
// Don't process variables when executing `terraform workspace` commands
if info.SubCommand != "workspace" {
Expand Down
4 changes: 4 additions & 0 deletions internal/exec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ func ProcessStacks(
if i, ok := configAndStacksInfo.ComponentSection[cfg.CommandSectionName].(string); ok {
configAndStacksInfo.Command = i
}

if i, ok := configAndStacksInfo.ComponentSection[cfg.WorkspaceSectionName].(string); ok {
configAndStacksInfo.TerraformWorkspace = i
}
}

// Spacelift stack
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func ExecuteWorkflowCmd(cmd *cobra.Command, args []string) error {
// If the workflow file is specified without an extension, use the default extension
ext := filepath.Ext(workflowPath)
if ext == "" {
ext = cfg.DefaultStackConfigFileExtension
ext = u.DefaultStackConfigFileExtension
workflowPath = workflowPath + ext
}

Expand Down
29 changes: 23 additions & 6 deletions internal/exec/workflow_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strings"

Expand Down Expand Up @@ -70,11 +71,10 @@ func ExecuteWorkflow(
commandType = "atmos"
}

var err error
if commandType == "shell" {
commandName := fmt.Sprintf("%s-step-%d", workflow, stepIdx)
if err := ExecuteShell(cliConfig, command, commandName, ".", []string{}, dryRun); err != nil {
return err
}
err = ExecuteShell(cliConfig, command, commandName, ".", []string{}, dryRun)
} else if commandType == "atmos" {
args := strings.Fields(command)

Expand All @@ -101,12 +101,29 @@ func ExecuteWorkflow(
logFunc(cliConfig, fmt.Sprintf("Stack: %s", finalStack))
}

if err := ExecuteShellCommand(cliConfig, "atmos", args, ".", []string{}, dryRun, ""); err != nil {
return err
}
err = ExecuteShellCommand(cliConfig, "atmos", args, ".", []string{}, dryRun, "")
} else {
return fmt.Errorf("invalid workflow step type '%s'. Supported types are 'atmos' and 'shell'", commandType)
}

if err != nil {
workflowFileName := filepath.Base(workflowPath)
workflowFileName = strings.TrimSuffix(workflowFileName, filepath.Ext(workflowFileName))

failedMsg := color.New(color.FgRed).Sprintf("\nStep '%s' failed!", step.Name)

u.LogDebug(cliConfig, fmt.Sprintf("\nCommand failed: %s", command))
u.LogDebug(cliConfig, fmt.Sprintf("Error: %v", err))

resumeMsg := color.New(color.FgGreen).Sprintf(
"\nTo resume the workflow from this step, run:\natmos workflow %s -f %s --from-step %s",
workflow,
workflowFileName,
step.Name,
)

return fmt.Errorf("%s\n%s", failedMsg, resumeMsg)
}
}

return nil
Expand Down
8 changes: 3 additions & 5 deletions pkg/config/const.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package config

const (
DefaultStackConfigFileExtension = ".yaml"
DefaultVendoringManifestFileExtension = ".yaml"
CliConfigFileName = "atmos"
SystemDirConfigFilePath = "/usr/local/etc/atmos"
WindowsAppDataEnvVar = "LOCALAPPDATA"
CliConfigFileName = "atmos"
SystemDirConfigFilePath = "/usr/local/etc/atmos"
WindowsAppDataEnvVar = "LOCALAPPDATA"

// GlobalOptionsFlag is a custom flag to specify helmfile `GLOBAL OPTIONS`
// https://github.com/roboll/helmfile#cli-reference
Expand Down
Loading

0 comments on commit 6d2e119

Please sign in to comment.