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

add amd64 platform by default #455

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -70,7 +70,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 @@ -231,8 +231,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 @@ -277,11 +281,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