Skip to content

Commit

Permalink
Merge pull request #455 from hazelops/IZE-485-mac-os-platform-linux-a…
Browse files Browse the repository at this point in the history
…md-64-by-default-for-arm-64-platforms

add amd64 platform by default
  • Loading branch information
psihachina authored Sep 16, 2022
2 parents 7d8abb5 + 9e87c2f commit 63049ad
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ var buildExample = templates.Examples(`
# Build app with explicitly specified config file passed via environment variable.
export IZE_CONFIG_FILE=/path/to/config
ize build <app name>
# Build app for arm64
ize build <app name> --prefer-runtime docker-arm64
`)

func NewBuildFlags(project *config.Project) *BuildOptions {
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/ize.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func newRootCmd(project *config.Project) *cobra.Command {
cmd.PersistentFlags().StringP("aws-region", "r", "", "(required) set AWS region (overrides value in ize.toml and IZE_AWS_REGION / AWS_REGION if any of them are set)")
cmd.PersistentFlags().StringP("namespace", "n", "", "(required) set namespace (overrides value in ize.toml and IZE_NAMESPACE / NAMESPACE if any of them are set)")
cmd.PersistentFlags().String("terraform-version", "", "set terraform-version")
cmd.PersistentFlags().String("prefer-runtime", "native", "set prefer runtime (native or docker)")
cmd.PersistentFlags().String("prefer-runtime", "native", "set prefer runtime (native, docker or docker-arm64)")
cmd.Flags().StringP("tag", "t", "", "set tag")

cmd.AddCommand(
Expand Down
5 changes: 4 additions & 1 deletion internal/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ type Builder struct {
Tags []string
Dockerfile string
CacheFrom []string
Platform string
}

func NewBuilder(buildArgs map[string]*string, tags []string, dockerfile string, cacheFrom []string) Builder {
func NewBuilder(buildArgs map[string]*string, tags []string, dockerfile string, cacheFrom []string, platform string) Builder {
return Builder{
BuildArgs: buildArgs,
Tags: tags,
Dockerfile: dockerfile,
CacheFrom: cacheFrom,
Platform: platform,
}
}

Expand Down Expand Up @@ -113,6 +115,7 @@ func (b *Builder) buildWithDocker(
Dockerfile: relDockerfile,
Tags: tags,
BuildArgs: buildArgs,
Platform: b.Platform,
}

resp, err := cli.ImageBuild(context.Background(), buildCtx, buildOpts)
Expand Down
5 changes: 4 additions & 1 deletion internal/docker/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
type Registry struct {
Registry string
Token string
Platform string
}

func NewRegistry(registry, token string) Registry {
func NewRegistry(registry, token, platform string) Registry {
return Registry{
Registry: registry,
Token: token,
Platform: platform,
}
}

Expand All @@ -45,6 +47,7 @@ func (r *Registry) Push(ctx context.Context, w io.Writer, image string, tags []s
resp, err := cli.ImagePush(ctx, image+":"+tags[0], types.ImagePushOptions{
RegistryAuth: r.Token,
All: true,
Platform: r.Platform,
})
if err != nil {
return fmt.Errorf("unable to push image: %s", err)
Expand Down
12 changes: 11 additions & 1 deletion internal/manager/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,12 @@ 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"
}

r := docker.NewRegistry(*repository.RepositoryUri, token)
r := docker.NewRegistry(*repository.RepositoryUri, token, platform)

err = r.Push(context.Background(), s.TermOutput(), imageUri, []string{e.Project.Tag, tagLatest})
if err != nil {
Expand Down Expand Up @@ -291,11 +295,17 @@ 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"
}

b := docker.NewBuilder(
buildArgs,
tags,
dockerfile,
cache,
platform,
)

err = b.Build(ui, s, e.Project.RootDir)
Expand Down

0 comments on commit 63049ad

Please sign in to comment.