From f117782b861e8aad5b6ef827932f1e54d01f8a79 Mon Sep 17 00:00:00 2001 From: Dmitry Kireev Date: Thu, 27 Nov 2025 19:30:07 +0000 Subject: [PATCH] Remove Kubernetes deployment manager and update CI workflows - chore(ci): upgrade GitHub Actions versions in run.unit-tests.yml and run.e2e-tests.yml workflows - chore(ci): upgrade GitHub Actions versions in release-prod.build-and-publish.yml and release-dev workflows - chore(terraform): bump AWS provider version constraint to ~> 4.0 in multiple example environments - chore(terraform): bump modules versions in bastion-tunnel-monorepo environment - test(terraform): add test for terraform version 1.14.0 in e2e tests - refactor(ecs): add getPlatform() method to determine Docker build platform with fallback to env var and default - refactor(ecs): replace direct platform assignment with getPlatform() usage in build and push steps - chore(config): remove deprecated K8s struct from internal config as Kubernetes manager is deleted - refactor(manager/k8s): delete entire Kubernetes deployment manager implementation as it is no longer used --- .../release-dev.build-and-publish.yml | 2 +- ...release-dev.create-release-and-publish.yml | 6 +- .../release-prod.build-and-publish.yml | 6 +- .github/workflows/run.e2e-tests.yml | 36 +- .github/workflows/run.unit-tests.yml | 12 +- .../.ize/env/testnut/main.tf | 4 +- .../.ize/env/testnut/versions.tf | 2 +- .../.ize/env/testnut/versions.tf | 2 +- .../.ize/env/testnut/pecan.tf | 2 +- .../.ize/env/testnut/versions.tf | 2 +- internal/config/app.go | 16 - internal/manager/ecs/ecs.go | 27 +- internal/manager/k8s/k8s.go | 376 ------------------ tests/e2e/terraform_test.go | 31 ++ 14 files changed, 90 insertions(+), 434 deletions(-) delete mode 100644 internal/manager/k8s/k8s.go diff --git a/.github/workflows/release-dev.build-and-publish.yml b/.github/workflows/release-dev.build-and-publish.yml index ccb7c522..617c1ea2 100644 --- a/.github/workflows/release-dev.build-and-publish.yml +++ b/.github/workflows/release-dev.build-and-publish.yml @@ -19,7 +19,7 @@ jobs: go-version: '1.23' - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/release-dev.create-release-and-publish.yml b/.github/workflows/release-dev.create-release-and-publish.yml index 759ed3ac..71ce6bf8 100644 --- a/.github/workflows/release-dev.create-release-and-publish.yml +++ b/.github/workflows/release-dev.create-release-and-publish.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check Out Repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Delete Release uses: dev-drprasad/delete-tag-and-release@v0.2.1 @@ -45,12 +45,12 @@ jobs: - name: Create Github Release id: create_release - uses: actions/create-release@v1 + uses: softprops/action-gh-release@v2 env: GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token with: tag_name: 0.0.0-dev - release_name: Dev Release + name: Dev Release prerelease: true body: | Most recent dev release diff --git a/.github/workflows/release-prod.build-and-publish.yml b/.github/workflows/release-prod.build-and-publish.yml index 76daf2f5..0a157d46 100644 --- a/.github/workflows/release-prod.build-and-publish.yml +++ b/.github/workflows/release-prod.build-and-publish.yml @@ -17,7 +17,7 @@ jobs: go-version: '1.23' - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -63,10 +63,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout current repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Checkout homebrew-ize repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: hazelops/homebrew-ize # Ize homebrew repo path: ${{ github.workspace }}/homebrew-ize # Local folder to copy file diff --git a/.github/workflows/run.e2e-tests.yml b/.github/workflows/run.e2e-tests.yml index 039d02e9..07daea81 100644 --- a/.github/workflows/run.e2e-tests.yml +++ b/.github/workflows/run.e2e-tests.yml @@ -24,12 +24,12 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: 1.18.x - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Build run: | @@ -37,7 +37,7 @@ jobs: make bin - name: Upload Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ize-${{ matrix.os }}-${{ github.sha }} path: ${{ github.workspace }}/ize @@ -62,24 +62,26 @@ jobs: echo "ENV=${{ github.job }}-$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PROD }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }} aws-region: ${{ env.AWS_REGION }} + env: + AWS_PROFILE: # This is required due to a bug https://stackoverflow.com/a/77731682 - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: 1.18.x - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Prepare Test Environment run: mv "${{ env.IZE_EXAMPLES_PATH }}/.ize/env/testnut" "${{ env.IZE_EXAMPLES_PATH }}/.ize/env/${{ env.ENV }}" - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: ize-${{ matrix.os }}-${{ github.sha }} path: bin @@ -126,24 +128,26 @@ jobs: echo "ENV=${{ github.job }}-$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PROD }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }} aws-region: ${{ env.AWS_REGION }} + env: + AWS_PROFILE: # This is required due to a bug https://stackoverflow.com/a/77731682 - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: 1.18.x - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Prepare Test Environment run: mv "${{ env.IZE_EXAMPLES_PATH }}/.ize/env/testnut" "${{ env.IZE_EXAMPLES_PATH }}/.ize/env/${{ env.ENV }}" - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: ize-${{ matrix.os }}-${{ github.sha }} path: bin @@ -197,24 +201,26 @@ jobs: echo "ENV=${{ github.job }}-$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PROD }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }} aws-region: ${{ env.AWS_REGION }} + env: + AWS_PROFILE: # This is required due to a bug https://stackoverflow.com/a/77731682 - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: 1.18.x - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Prepare Test Environment run: mv "${{ env.IZE_EXAMPLES_PATH }}/.ize/env/testnut" "${{ env.IZE_EXAMPLES_PATH }}/.ize/env/${{ env.ENV }}" - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: ize-${{ matrix.os }}-${{ github.sha }} path: bin diff --git a/.github/workflows/run.unit-tests.yml b/.github/workflows/run.unit-tests.yml index 43023310..31c93894 100644 --- a/.github/workflows/run.unit-tests.yml +++ b/.github/workflows/run.unit-tests.yml @@ -27,12 +27,12 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: 1.18.x - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Build run: | @@ -40,7 +40,7 @@ jobs: make bin - name: Upload Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ize-${{ matrix.os }}-${{ github.sha }} path: ${{ github.workspace }}/ize @@ -51,10 +51,10 @@ jobs: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: 1.18 @@ -90,4 +90,4 @@ jobs: report_paths: './report.xml' - name: Upload coverage to Codecov - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 diff --git a/examples/bastion-tunnel-monorepo/.ize/env/testnut/main.tf b/examples/bastion-tunnel-monorepo/.ize/env/testnut/main.tf index e92cfd8e..5becaa80 100644 --- a/examples/bastion-tunnel-monorepo/.ize/env/testnut/main.tf +++ b/examples/bastion-tunnel-monorepo/.ize/env/testnut/main.tf @@ -34,7 +34,7 @@ module "vpc" { module "nat_instance" { source = "hazelops/ec2-nat/aws" - version = "~> 2.0" + version = "~> 3.0" enabled = true env = var.env vpc_id = module.vpc.vpc_id @@ -79,7 +79,7 @@ module "ec2_profile" { module "bastion" { source = "hazelops/ec2-openvpn-connector/aws" - version = "~>0.2" + version = "~> 0.4" vpn_enabled = false env = var.env diff --git a/examples/bastion-tunnel-monorepo/.ize/env/testnut/versions.tf b/examples/bastion-tunnel-monorepo/.ize/env/testnut/versions.tf index 03a50665..8f85030b 100644 --- a/examples/bastion-tunnel-monorepo/.ize/env/testnut/versions.tf +++ b/examples/bastion-tunnel-monorepo/.ize/env/testnut/versions.tf @@ -2,7 +2,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "~> 3.0" + version = "~> 4.0" } } required_version = ">= 0.13" diff --git a/examples/ecs-apps-monorepo/.ize/env/testnut/versions.tf b/examples/ecs-apps-monorepo/.ize/env/testnut/versions.tf index 970268d9..8f85030b 100644 --- a/examples/ecs-apps-monorepo/.ize/env/testnut/versions.tf +++ b/examples/ecs-apps-monorepo/.ize/env/testnut/versions.tf @@ -2,7 +2,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 3.0" + version = "~> 4.0" } } required_version = ">= 0.13" diff --git a/examples/sls-apps-monorepo/.ize/env/testnut/pecan.tf b/examples/sls-apps-monorepo/.ize/env/testnut/pecan.tf index 87ebab38..c9d614be 100644 --- a/examples/sls-apps-monorepo/.ize/env/testnut/pecan.tf +++ b/examples/sls-apps-monorepo/.ize/env/testnut/pecan.tf @@ -1,6 +1,6 @@ module "pecan" { source = "registry.terraform.io/hazelops/sls-app/aws" - version = "~> 0.2" + version = "0.2.1" name = "pecan" parameters = { ROOT_DOMAIN_NAME = var.root_domain_name diff --git a/examples/sls-apps-monorepo/.ize/env/testnut/versions.tf b/examples/sls-apps-monorepo/.ize/env/testnut/versions.tf index 970268d9..8f85030b 100644 --- a/examples/sls-apps-monorepo/.ize/env/testnut/versions.tf +++ b/examples/sls-apps-monorepo/.ize/env/testnut/versions.tf @@ -2,7 +2,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 3.0" + version = "~> 4.0" } } required_version = ">= 0.13" diff --git a/internal/config/app.go b/internal/config/app.go index f3f0da7c..c0ff8a39 100644 --- a/internal/config/app.go +++ b/internal/config/app.go @@ -16,22 +16,6 @@ type Ecs struct { DependsOn []string `mapstructure:"depends_on,omitempty"` } -type K8s struct { - Name string `mapstructure:",omitempty"` - Path string `mapstructure:",omitempty"` - Image string `mapstructure:",omitempty"` - Cluster string `mapstructure:",omitempty"` - TaskDefinitionRevision string `mapstructure:"task_definition_revision"` - DockerRegistry string `mapstructure:"docker_registry,omitempty"` - Timeout int `mapstructure:",omitempty"` - Unsafe bool `mapstructure:",omitempty"` - SkipDeploy bool `mapstructure:"skip_deploy,omitempty"` - Icon string `mapstructure:"icon,omitempty"` - AwsProfile string `mapstructure:"aws_profile,omitempty"` - AwsRegion string `mapstructure:"aws_region,omitempty"` - DependsOn []string `mapstructure:"depends_on,omitempty"` -} - type Serverless struct { Name string `mapstructure:",omitempty"` File string `mapstructure:",omitempty"` diff --git a/internal/manager/ecs/ecs.go b/internal/manager/ecs/ecs.go index a809814d..02806a4c 100644 --- a/internal/manager/ecs/ecs.go +++ b/internal/manager/ecs/ecs.go @@ -60,6 +60,23 @@ func (e *Manager) prepare() { } } +// getPlatform returns the platform to use for Docker builds and pushes. +// Priority: PreferRuntime=docker-arm64 (backward compatibility) > DOCKER_DEFAULT_PLATFORM env var > default (linux/amd64) +func (e *Manager) getPlatform() string { + // First, check PreferRuntime for backward compatibility with existing configs + if e.Project.PreferRuntime == "docker-arm64" { + return "linux/arm64" + } + + // Then check DOCKER_DEFAULT_PLATFORM environment variable + if platform := os.Getenv("DOCKER_DEFAULT_PLATFORM"); platform != "" { + return platform + } + + // Default to linux/amd64 + return "linux/amd64" +} + // Deploy deploys app container to ECS via ECS deploy func (e *Manager) Deploy(ui terminal.UI) error { e.prepare() @@ -236,10 +253,7 @@ func (e *Manager) Push(ui terminal.UI) error { tagLatest := fmt.Sprintf("%s-latest", e.Project.Env) imageUri := fmt.Sprintf("%s/%s", e.App.DockerRegistry, image) - platform := "linux/amd64" - if e.Project.PreferRuntime == "docker-arm64" { - platform = "linux/arm64" - } + platform := e.getPlatform() r := docker.NewRegistry(*repository.RepositoryUri, token, platform) @@ -293,10 +307,7 @@ func (e *Manager) Build(ui terminal.UI) error { cache := []string{fmt.Sprintf("%s:%s", imageUri, fmt.Sprintf("%s-latest", e.Project.Env))} - platform := "linux/amd64" - if e.Project.PreferRuntime == "docker-arm64" { - platform = "linux/arm64" - } + platform := e.getPlatform() b := docker.NewBuilder( buildArgs, diff --git a/internal/manager/k8s/k8s.go b/internal/manager/k8s/k8s.go deleted file mode 100644 index fd7bfd74..00000000 --- a/internal/manager/k8s/k8s.go +++ /dev/null @@ -1,376 +0,0 @@ -package k8s - -import ( - "context" - "encoding/base64" - "encoding/json" - "fmt" - "os" - "path" - "path/filepath" - "time" - - "github.com/hazelops/ize/internal/aws/utils" - "github.com/hazelops/ize/internal/config" - "github.com/hazelops/ize/pkg/templates" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecr" - "github.com/docker/docker/api/types" - "github.com/hazelops/ize/internal/docker" - "github.com/hazelops/ize/pkg/terminal" - "github.com/pterm/pterm" - "github.com/sirupsen/logrus" -) - -const k8sDeployImage = "hazelops/k8s-deploy:latest" - -type Manager struct { - Project *config.Project - App *config.K8s -} - -func (e *Manager) prepare() { - if e.App.Path == "" { - appsPath := e.Project.AppsPath - if !filepath.IsAbs(appsPath) { - appsPath = filepath.Join(os.Getenv("PWD"), appsPath) - } - - e.App.Path = filepath.Join(appsPath, e.App.Name) - } else { - rootDir := e.Project.RootDir - - if !filepath.IsAbs(e.App.Path) { - e.App.Path = filepath.Join(rootDir, e.App.Path) - } - } - - if len(e.App.Cluster) == 0 { - e.App.Cluster = fmt.Sprintf("%s-%s", e.Project.Env, e.Project.Namespace) - } - - if len(e.App.DockerRegistry) == 0 { - e.App.DockerRegistry = e.Project.DockerRegistry - } - - if e.App.Timeout == 0 { - e.App.Timeout = 300 - } -} - -// Deploy deploys app container to k8s via k8s deploy -func (e *Manager) Deploy(ui terminal.UI) error { - e.prepare() - - sg := ui.StepGroup() - defer sg.Wait() - - if len(e.App.AwsRegion) != 0 && len(e.App.AwsProfile) != 0 { - sess, err := utils.GetSession(&utils.SessionConfig{ - Region: e.App.AwsRegion, - Profile: e.App.AwsProfile, - }) - if err != nil { - return fmt.Errorf("can't get session: %w", err) - } - - e.Project.SettingAWSClient(sess) - } - - if e.App.SkipDeploy { - s := sg.Add("%s: deploy will be skipped", e.App.Name) - defer func() { s.Abort(); time.Sleep(50 * time.Millisecond) }() - s.Done() - return nil - } - - if e.App.Unsafe && e.Project.PreferRuntime == "native" { - pterm.Warning.Println(templates.Dedent(` - deployment will be accelerated (unsafe): - - Health Check Interval: 5s - - Health Check Timeout: 2s - - Healthy Threshold Count: 2 - - Unhealthy Threshold Count: 2`)) - } - - s := sg.Add("%s: deploying app container...", e.App.Name) - defer func() { s.Abort(); time.Sleep(50 * time.Millisecond) }() - - if e.App.Image == "" { - e.App.Image = fmt.Sprintf("%s/%s:%s", - e.App.DockerRegistry, - fmt.Sprintf("%s-%s", e.Project.Namespace, e.App.Name), - fmt.Sprintf("%s-%s", e.Project.Env, "latest")) - } - - if e.Project.PreferRuntime == "native" { - err := e.deployLocal(s.TermOutput()) - pterm.SetDefaultOutput(os.Stdout) - if err != nil { - return fmt.Errorf("unable to deploy app: %w", err) - } - } else { - err := e.deployWithDocker(s.TermOutput()) - if err != nil { - return fmt.Errorf("unable to deploy app: %w", err) - } - } - - s.Done() - s = sg.Add("%s: deployment completed!", e.App.Name) - s.Done() - - return nil -} - -func (e *Manager) Redeploy(ui terminal.UI) error { - e.prepare() - - sg := ui.StepGroup() - defer sg.Wait() - - if len(e.App.AwsRegion) != 0 && len(e.App.AwsProfile) != 0 { - sess, err := utils.GetSession(&utils.SessionConfig{ - Region: e.App.AwsRegion, - Profile: e.App.AwsProfile, - }) - if err != nil { - return fmt.Errorf("can't get session: %w", err) - } - - e.Project.SettingAWSClient(sess) - } - - s := sg.Add("%s: redeploying app container...", e.App.Name) - defer func() { s.Abort(); time.Sleep(50 * time.Millisecond) }() - - if e.Project.PreferRuntime == "native" { - err := e.redeployLocal(s.TermOutput()) - pterm.SetDefaultOutput(os.Stdout) - if err != nil { - return fmt.Errorf("unable to redeploy app: %w", err) - } - } else { - err := e.redeployWithDocker(s.TermOutput()) - if err != nil { - return fmt.Errorf("unable to redeploy app: %w", err) - } - } - - s.Done() - s = sg.Add("%s: redeployment completed!", e.App.Name) - s.Done() - - return nil -} - -func (e *Manager) Push(ui terminal.UI) error { - e.prepare() - - sg := ui.StepGroup() - defer sg.Wait() - - s := sg.Add("%s: push app image...", e.App.Name) - defer func() { s.Abort(); time.Sleep(50 * time.Millisecond) }() - - if len(e.App.Image) != 0 { - s.Update("%s: pushing app image... (skipped, using %s) ", e.App.Name, e.App.Image) - s.Done() - - return nil - } - - image := fmt.Sprintf("%s-%s", e.Project.Namespace, e.App.Name) - - svc := e.Project.AWSClient.ECRClient - - var repository *ecr.Repository - - dro, err := svc.DescribeRepositories(&ecr.DescribeRepositoriesInput{ - RepositoryNames: []*string{aws.String(image)}, - }) - if err != nil { - return fmt.Errorf("can't describe repositories: %w", err) - } - - if dro == nil || len(dro.Repositories) == 0 { - logrus.Info("no ECR repository detected, creating", "name", image) - - out, err := svc.CreateRepository(&ecr.CreateRepositoryInput{ - RepositoryName: aws.String(image), - }) - if err != nil { - return fmt.Errorf("unable to create repository: %w", err) - } - - repository = out.Repository - } else { - repository = dro.Repositories[0] - } - - gat, err := svc.GetAuthorizationToken(&ecr.GetAuthorizationTokenInput{}) - if err != nil { - return fmt.Errorf("unable to get authorization token: %w", err) - } - - if len(gat.AuthorizationData) == 0 { - return fmt.Errorf("no authorization tokens provided") - } - - upToken := *gat.AuthorizationData[0].AuthorizationToken - data, err := base64.StdEncoding.DecodeString(upToken) - if err != nil { - return fmt.Errorf("unable to decode authorization token: %w", err) - } - - auth := types.AuthConfig{ - Username: "AWS", - Password: string(data[4:]), - } - - authBytes, _ := json.Marshal(auth) - - token := base64.URLEncoding.EncodeToString(authBytes) - - tagLatest := fmt.Sprintf("%s-latest", e.Project.Env) - imageUri := fmt.Sprintf("%s/%s", e.App.DockerRegistry, image) - platform := "linux/amd64" - if e.Project.PreferRuntime == "docker-arm64" { - platform = "linux/arm64" - } - - r := docker.NewRegistry(*repository.RepositoryUri, token, platform) - - err = r.Push(context.Background(), s.TermOutput(), imageUri, []string{e.Project.Tag, tagLatest}) - if err != nil { - return fmt.Errorf("can't push image: %w", err) - } - - s.Done() - - return nil -} - -func (e *Manager) Build(ui terminal.UI) error { - e.prepare() - - sg := ui.StepGroup() - defer sg.Wait() - - s := sg.Add("%s: building app container...", e.App.Name) - defer func() { s.Abort(); time.Sleep(50 * time.Millisecond) }() - - if len(e.App.Image) != 0 { - s.Update("%s: building app container... (skipped, using %s)", e.App.Name, e.App.Image) - - s.Done() - return nil - } - - image := fmt.Sprintf("%s-%s", e.Project.Namespace, e.App.Name) - imageUri := fmt.Sprintf("%s/%s", e.App.DockerRegistry, image) - - relProjectPath, err := filepath.Rel(e.Project.RootDir, e.App.Path) - if err != nil { - return fmt.Errorf("unable to get relative path: %w", err) - } - - buildArgs := map[string]*string{ - "PROJECT_PATH": &relProjectPath, - "APP_PATH": &relProjectPath, - "APP_NAME": &e.App.Name, - } - - tags := []string{ - image, - fmt.Sprintf("%s:%s", imageUri, e.Project.Tag), - fmt.Sprintf("%s:%s", imageUri, fmt.Sprintf("%s-latest", e.Project.Env)), - } - - dockerfile := path.Join(e.App.Path, "Dockerfile") - - cache := []string{fmt.Sprintf("%s:%s", imageUri, fmt.Sprintf("%s-latest", e.Project.Env))} - - platform := "linux/amd64" - if e.Project.PreferRuntime == "docker-arm64" { - platform = "linux/arm64" - } - - b := docker.NewBuilder( - buildArgs, - tags, - dockerfile, - cache, - platform, - ) - - err = b.Build(ui, s, e.Project.RootDir) - if err != nil { - return fmt.Errorf("unable to build image: %w", err) - } - - s.Done() - - return nil -} - -func definitionsToBulletItems(definitions *k8s.ListTaskDefinitionsOutput) []pterm.BulletListItem { - var items []pterm.BulletListItem - for _, arn := range definitions.TaskDefinitionArns { - items = append(items, pterm.BulletListItem{Level: 0, Text: *arn}) - } - - return items -} - -func (e *Manager) Destroy(ui terminal.UI, autoApprove bool) error { - sg := ui.StepGroup() - defer sg.Wait() - - s := sg.Add("%s: destroying task defintions...", e.App.Name) - defer func() { s.Abort(); time.Sleep(time.Millisecond * 200) }() - - name := fmt.Sprintf("%s-%s", e.Project.Env, e.App.Name) - - svc := e.Project.AWSClient.k8sClient - - definitions, err := svc.ListTaskDefinitions(&k8s.ListTaskDefinitionsInput{ - FamilyPrefix: &name, - Sort: aws.String(k8s.SortOrderDesc), - }) - if err != nil { - return fmt.Errorf("can't get list task definitions of '%s': %v", name, err) - } - - if !autoApprove { - pterm.SetDefaultOutput(s.TermOutput()) - - pterm.Printfln("this will destroy the following:") - pterm.DefaultBulletList.WithItems(definitionsToBulletItems(definitions)).Render() - - isContinue, err := pterm.DefaultInteractiveConfirm.WithDefaultText("Continue?").Show() - if err != nil { - return err - } - - if !isContinue { - return fmt.Errorf("destroying was canceled") - } - } - - for _, tda := range definitions.TaskDefinitionArns { - _, err := e.Project.AWSClient.k8sClient.DeregisterTaskDefinition(&k8s.DeregisterTaskDefinitionInput{ - TaskDefinition: tda, - }) - if err != nil { - return fmt.Errorf("can't deregister task definition '%s': %v", *tda, err) - } - } - - s.Done() - s = sg.Add("%s: destroying completed!", e.App.Name) - s.Done() - - return nil -} diff --git a/tests/e2e/terraform_test.go b/tests/e2e/terraform_test.go index 5af82c3e..b840c616 100644 --- a/tests/e2e/terraform_test.go +++ b/tests/e2e/terraform_test.go @@ -164,6 +164,37 @@ func TestIzeTerraformVersion_1_2_7(t *testing.T) { } } +func TestIzeTerraformVersion_1_14_0(t *testing.T) { + + terraformVersion := "1.14.0" + + if examplesRootDir == "" { + t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") + } + + ize := NewBinary(t, izeBinary, examplesRootDir) + + stdout, stderr, err := ize.RunRaw(fmt.Sprintf("--terraform-version=%s", terraformVersion), "terraform", "version") + + if err != nil { + t.Errorf("error: %s", err) + } + + if stderr != "" { + t.Errorf("unexpected stderr output ize terraform version: %s", err) + } + + if !strings.Contains(stdout, fmt.Sprintf("Terraform v%s", terraformVersion)) { + t.Errorf("No success message detected after terraform version:\n%s", stdout) + } else { + t.Log(fmt.Sprintf("PASS: v%s: terraform version", terraformVersion)) + } + + if os.Getenv("RUNNER_DEBUG") == "1" { + t.Log(stdout) + } +} + func TestIzeTerraformInit(t *testing.T) { if examplesRootDir == "" { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH")