Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Build amd64 images explicitly to avoid cross-platform issues #224

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6a9bd21
Initial commit
alexlokshin-czi Apr 7, 2022
e181555
Added visualization of platform data
alexlokshin-czi Apr 7, 2022
2158dd0
Added unit tests
alexlokshin-czi Apr 7, 2022
5afd194
Warning the user of a platform mismatch
alexlokshin-czi Apr 8, 2022
773a051
Appeasing the linter
alexlokshin-czi Apr 8, 2022
88f51c0
Updated coverage
alexlokshin-czi Apr 8, 2022
6116691
Updated dependencies
alexlokshin-czi Apr 8, 2022
cfce81c
Updated coverage
alexlokshin-czi Apr 8, 2022
c9f9346
Improved coverage
alexlokshin-czi Apr 8, 2022
8ed1208
Added clarity to variable names
alexlokshin-czi Apr 8, 2022
0cb7b9d
Fixing the linter
alexlokshin-czi Apr 8, 2022
9c20cc2
Not sharing the env vars
alexlokshin-czi Apr 8, 2022
03cdbf1
Stopping at the platform specified in docker compose if it is not com…
alexlokshin-czi Apr 11, 2022
4bfe2e7
Removed the trailing space
alexlokshin-czi Apr 11, 2022
7f73718
Updated coverage
alexlokshin-czi Apr 11, 2022
736df69
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 11, 2022
f624876
Fixing the merge issues
alexlokshin-czi Apr 11, 2022
701e98f
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 11, 2022
ec95cb8
Dealing with locally set DOCKER_DEFAULT_PLATFORM env variable
alexlokshin-czi Apr 11, 2022
872fe1c
Merge branch 'alokshin/amd64' of https://github.com/chanzuckerberg/ha…
alexlokshin-czi Apr 11, 2022
03f9e40
Upgraded some dependencies
alexlokshin-czi Apr 11, 2022
2b7ad4e
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 11, 2022
9172f04
Responding to code review and coverage improvement
alexlokshin-czi Apr 12, 2022
5e2a03c
Merge branch 'alokshin/amd64' of https://github.com/chanzuckerberg/ha…
alexlokshin-czi Apr 12, 2022
bf47ead
Added a conflict message
alexlokshin-czi Apr 12, 2022
bcf0843
Updated per code review
alexlokshin-czi Apr 12, 2022
c256bc3
Updated coverage
alexlokshin-czi Apr 12, 2022
94322a3
Updated coverage
alexlokshin-czi Apr 12, 2022
f0f423f
Added a target runtime comment per code review
alexlokshin-czi Apr 12, 2022
45cbb6d
Responding to code review.
alexlokshin-czi Apr 12, 2022
37ab80d
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 14, 2022
0e6e817
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 14, 2022
705dd4b
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 14, 2022
f53648e
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 14, 2022
dcba02c
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 18, 2022
6ff6b20
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 20, 2022
1ea7406
Merge branch 'main' into alokshin/amd64
alexlokshin-czi Apr 21, 2022
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
2 changes: 1 addition & 1 deletion COVERAGE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
41.04
41.04
2 changes: 1 addition & 1 deletion cmd/COVERAGE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.2
8.0
18 changes: 17 additions & 1 deletion cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ var getCmd = &cobra.Command{
tablePrinter = util.NewTablePrinter(headings)

tablePrinter.AddRow("Environment", bootstrapConfig.Env)
tablePrinter.AddRow("Docker")
tablePrinter.AddRow(" Target platform", happyConfig.GetTargetContainerPlatform())
tablePrinter.AddRow(" Container Architecture", util.GetUserContainerPlatform())
tablePrinter.AddRow("TFE", "")
tablePrinter.AddRow(" Environment Workspace", fmt.Sprintf("%s/app/%s/workspaces/env-%s", tfeUrl, tfeOrg, bootstrapConfig.Env))
tablePrinter.AddRow(" Stack Workspace", fmt.Sprintf("%s/app/%s/workspaces/%s-%s", tfeUrl, tfeOrg, bootstrapConfig.Env, stackName))
Expand Down Expand Up @@ -161,8 +164,22 @@ var getCmd = &cobra.Command{
if len(arnSegments) < 3 {
continue
}

taskId := arnSegments[len(arnSegments)-1]
tablePrinter.AddRow(" ARN", taskArn)
if len(task.Attributes) > 0 {
for _, attribute := range task.Attributes {
if *attribute.Name == "ecs.cpu-architecture" {
arch, err := util.GetSystemContainerPlatform(*attribute.Value)
if err != nil {
return errors.Wrap(err, "unable to get system container platform")
}
tablePrinter.AddRow(" System Architecture", arch)
break
}
}
}

tablePrinter.AddRow(" Status", *task.LastStatus)
tablePrinter.AddRow(" Containers")
for _, containerDefinition := range taskDefinition.ContainerDefinitions {
Expand All @@ -184,7 +201,6 @@ var getCmd = &cobra.Command{

}
}

tablePrinter.Print()
return nil
},
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.15.4
github.com/aws/aws-sdk-go-v2/service/ssm v1.24.1
github.com/aws/smithy-go v1.11.2 // indirect
github.com/containerd/containerd v1.6.2 // indirect
github.com/containerd/containerd v1.6.2
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
Expand Down Expand Up @@ -78,18 +78,18 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5 // indirect
github.com/opencontainers/image-spec v1.0.2-0.20211117181255-693428a734f5
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b // indirect
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 // indirect
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3 // indirect
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
google.golang.org/genproto v0.0.0-20220407135246-8d918b4c0f5b // indirect
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 h1:tkVvjkPTB7pnW3jnid7kNyAMPVWllTNOf/qKDze4p9o=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 h1:iU7T1X1J6yxDr0rda54sWGkHgOp5XJrqm79gcNlC2VM=
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand All @@ -269,8 +269,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b h1:vI32FkLJNAWtGD4BwkThwEy6XS7ZLLMHkSkYfF8M0W0=
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3 h1:EN5+DfgmRMvRUrMGERW2gQl3Vc+Z7ZMnI/xdEpPSf0c=
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -301,8 +301,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 h1:QyVthZKMsyaQwBTJE04jdNN0Pp5Fn9Qga0mrgxyERQM=
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f h1:8w7RhxzTVgUzw/AH/9mUV5q0vMgy40SQRursCcfmkCw=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
Expand Down Expand Up @@ -336,8 +336,8 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20220407135246-8d918b4c0f5b h1:3AW6JOOEaupTAfey305izk2PXQTWf4wC6nVHgga3xJs=
google.golang.org/genproto v0.0.0-20220407135246-8d918b4c0f5b/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac h1:qSNTkEN+L2mvWcLgJOR+8bdHX9rN/IdU3A1Ghpfb1Rg=
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/artifact_builder/COVERAGE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79.6
77.5
32 changes: 31 additions & 1 deletion pkg/artifact_builder/artifact_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
backend "github.com/chanzuckerberg/happy/pkg/backend/aws"
"github.com/chanzuckerberg/happy/pkg/config"
"github.com/chanzuckerberg/happy/pkg/profiler"
"github.com/chanzuckerberg/happy/pkg/util"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -192,7 +193,36 @@ func (ab *ArtifactBuilder) RetagImages(

func (ab *ArtifactBuilder) Build() error {
defer ab.Profiler.AddRuntime(time.Now(), "Build")
return ab.config.DockerComposeBuild()
targetPlatformDefinedInDockerCompose, err := ab.checkTargetPlatformDefinedInDockerCompose()
if err != nil {
return errors.Wrap(err, "unable to check target platform defined in docker-compose")
}

// If targetPlatformDefinedInDockerCompose is true,it means that target platform matches the one define in happy config,
// and we can skip setting the DOCKER_DEFAULT_PLATFORM env variable on build.
return ab.config.DockerComposeBuild(targetPlatformDefinedInDockerCompose)
}

func (ab *ArtifactBuilder) checkTargetPlatformDefinedInDockerCompose() (bool, error) {
targetPlatformDefinedInDockerCompose := false
if ab.config.targetContainerPlatform != util.GetUserContainerPlatform() {
log.Warnf("Your local container platform is %s, but we are building images for %s.", util.GetUserContainerPlatform(), ab.config.targetContainerPlatform)

data, err := ab.config.DockerComposeConfig()
if err != nil {
return false, errors.Wrap(err, "unable to open docker compose file")
}
for serviceName, service := range data.Services {
if service.Platform != "" {
if service.Platform != ab.config.targetContainerPlatform {
// Passing DOCKER_DEFAULT_PLATFORM into the docker process conflicts with the platform specified in the docker-compose.ymml itself
return false, errors.Errorf("Service '%s' has a platform '%s' specified in docker compose file, it is not possible to build the image. Please remove this setting.", serviceName, service.Platform)
}
targetPlatformDefinedInDockerCompose = true
}
}
}
return targetPlatformDefinedInDockerCompose, nil
}

func (ab *ArtifactBuilder) RegistryLogin(ctx context.Context) error {
Expand Down
3 changes: 3 additions & 0 deletions pkg/artifact_builder/artifact_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ func TestCheckTagExists(t *testing.T) {
r.NoError(err)
err = artifactBuilder.Push([]string{"latest"})
r.NoError(err)

_, err = artifactBuilder.checkTargetPlatformDefinedInDockerCompose()
alexlokshin-czi marked this conversation as resolved.
Show resolved Hide resolved
r.NoError(err)
}

func TestBuildAndPush(t *testing.T) {
Expand Down
15 changes: 9 additions & 6 deletions pkg/artifact_builder/builder_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ type ServiceBuild struct {
}

type ServiceConfig struct {
Image string `yaml:"image"`
Build *ServiceBuild `yaml:"build"`
Network map[string]interface{} `yaml:"networks"`
Image string `yaml:"image"`
Build *ServiceBuild `yaml:"build"`
Network map[string]interface{} `yaml:"networks"`
Platform string `yaml:"platform"`
}

type ConfigData struct {
Services map[string]ServiceConfig `yaml:"services"`
}

type BuilderConfig struct {
composeFile string
composeEnvFile string
dockerRepo string
composeFile string
composeEnvFile string
dockerRepo string
targetContainerPlatform string

profile *config.Profile

Expand All @@ -47,6 +49,7 @@ func (b *BuilderConfig) WithBootstrap(bootstrap *config.Bootstrap) *BuilderConfi
func (b *BuilderConfig) WithHappyConfig(happyConfig *config.HappyConfig) *BuilderConfig {
b.composeEnvFile = happyConfig.GetDockerComposeEnvFile()
b.dockerRepo = happyConfig.GetDockerRepo()
b.targetContainerPlatform = happyConfig.GetTargetContainerPlatform()
return b
}

Expand Down
41 changes: 32 additions & 9 deletions pkg/artifact_builder/docker_compose.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package artifact_builder

import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/chanzuckerberg/happy/pkg/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
)

type DockerCommand string

const (
DockerCommandConfig DockerCommand = "config"
DockerCommandBuild DockerCommand = "build"
DockerCommandConfig DockerCommand = "config"
DockerCommandBuild DockerCommand = "build"
DockerDefaultPlatformEnvVar string = "DOCKER_DEFAULT_PLATFORM"
)

func (bc *BuilderConfig) DockerComposeBuild() error {
_, err := bc.invokeDockerCompose(DockerCommandBuild)
func (bc *BuilderConfig) DockerComposeBuild(targetPlatformDefinedInDockerCompose bool) error {
_, err := bc.invokeDockerCompose(DockerCommandBuild, targetPlatformDefinedInDockerCompose)
return err
}

func (bc *BuilderConfig) DockerComposeConfig() (*ConfigData, error) {
configDataBytes, err := bc.invokeDockerCompose(DockerCommandConfig)
configDataBytes, err := bc.invokeDockerCompose(DockerCommandConfig, false)
if err != nil {
return nil, err
}
Expand All @@ -36,7 +40,7 @@ func (bc *BuilderConfig) DockerComposeConfig() (*ConfigData, error) {
}

// 'docker-compose' was incorporated into 'docker' itself.
func (bc *BuilderConfig) invokeDockerCompose(command DockerCommand) ([]byte, error) {
func (bc *BuilderConfig) invokeDockerCompose(command DockerCommand, targetPlatformDefinedInDockerCompose bool) ([]byte, error) {
composeArgs := []string{"docker", "compose", "--file", bc.composeFile}
if len(bc.composeEnvFile) > 0 {
composeArgs = append(composeArgs, "--env-file", bc.composeEnvFile)
Expand All @@ -47,7 +51,15 @@ func (bc *BuilderConfig) invokeDockerCompose(command DockerCommand) ([]byte, err

envVars := bc.GetBuildEnv()
envVars = append(envVars, os.Environ()...)
envVars = append(envVars, "DOCKER_BUILDKIT=1")
alexlokshin-czi marked this conversation as resolved.
Show resolved Hide resolved

// Specifying platform in the docker compose conflicts with the DOCKER_DEFAULT_PLATFORM env var:
// multiple platforms feature is currently not supported for docker driver. Please switch to a different driver (eg. "docker buildx create --use")
envVars = filterOutTargetPlatformEnv(envVars)
if !targetPlatformDefinedInDockerCompose {
if bc.targetContainerPlatform != util.GetUserContainerPlatform() {
envVars = append(envVars, fmt.Sprintf("%s=%s", DockerDefaultPlatformEnvVar, bc.targetContainerPlatform))
}
}

docker, err := bc.GetExecutor().LookPath("docker")
if err != nil {
Expand All @@ -61,7 +73,8 @@ func (bc *BuilderConfig) invokeDockerCompose(command DockerCommand) ([]byte, err
Stdin: os.Stdin,
Stderr: os.Stderr,
}
logrus.Infof("executing: %s", cmd.String())
log.Infof("executing: %s", cmd.String())

switch command {
case DockerCommandConfig:
output, err := bc.GetExecutor().Output(cmd)
Expand All @@ -72,3 +85,13 @@ func (bc *BuilderConfig) invokeDockerCompose(command DockerCommand) ([]byte, err
return []byte{}, errors.Wrap(err, "unable to process docker compose output")
}
}

func filterOutTargetPlatformEnv(envVars []string) []string {
filteredEnvVars := []string{}
for _, envVar := range envVars {
if !strings.Contains(envVar, DockerDefaultPlatformEnvVar) {
filteredEnvVars = append(filteredEnvVars, envVar)
}
}
return filteredEnvVars
}
2 changes: 1 addition & 1 deletion pkg/config/COVERAGE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
69.1
69.7
28 changes: 22 additions & 6 deletions pkg/config/happy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ import (
"gopkg.in/yaml.v3"
)

const (
DefaultTargetContainerPlatform string = "linux/amd64"
)

type Environment struct {
AWSProfile *string `yaml:"aws_profile"`
SecretARN string `yaml:"secret_arn"`
TerraformDirectory string `yaml:"terraform_directory"`
DeleteProtected bool `yaml:"delete_protected"`
AutoRunMigrations bool `yaml:"auto_run_migrations"`
TaskLaunchType LaunchType `yaml:"task_launch_type"`
AWSProfile *string `yaml:"aws_profile"`
SecretARN string `yaml:"secret_arn"`
TerraformDirectory string `yaml:"terraform_directory"`
DeleteProtected bool `yaml:"delete_protected"`
AutoRunMigrations bool `yaml:"auto_run_migrations"`
LogGroupPrefix string `yaml:"log_group_prefix"`
TaskLaunchType LaunchType `yaml:"task_launch_type"`
TargetContainerPlatform string `yaml:"target_container_platform"`
}

type ConfigData struct {
Expand Down Expand Up @@ -184,6 +190,16 @@ func (s *HappyConfig) TaskLaunchType() LaunchType {
return taskLaunchType
}

func (s *HappyConfig) GetTargetContainerPlatform() string {
envConfig := s.getEnvConfig()

if len(strings.TrimSpace(envConfig.TargetContainerPlatform)) == 0 {
return DefaultTargetContainerPlatform
}

return envConfig.TargetContainerPlatform
}

func (s *HappyConfig) TerraformVersion() string {
return s.getData().TerraformVersion
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/config/happy_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ func TestNewHappConfig(t *testing.T) {
{"prod", aws.String("test-prod"), "happy/env-prod-config", ".happy/terraform/envs/prod", "FARGATE", false},
}

r := require.New(t)

targetPlatforms := map[string]bool{}
for idx, testCase := range testData {
t.Run(fmt.Sprintf("%d", idx), func(t *testing.T) {
r := require.New(t)

config, err := NewTestHappyConfig(t, testFilePath, testCase.env)
r.NoError(err)

Expand All @@ -50,8 +51,11 @@ func TestNewHappConfig(t *testing.T) {
r.Equal(testCase.wantSecretArn, val)
val = config.TaskLaunchType().String()
r.Equal(testCase.wantTaskLaunchType, val)
targetPlatforms[config.GetTargetContainerPlatform()] = true
})
}

r.Len(targetPlatforms, 2)
}

func TestProfile(t *testing.T) {
Expand Down
Loading