From ba4a9980e2cd13c7b927ef4faed7cf1537ba194c Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Thu, 25 Feb 2021 19:13:32 -0300 Subject: [PATCH 1/3] Take `platform` in account on pulling the images Signed-off-by: Ulysses Souza --- local/compose/pull.go | 1 + 1 file changed, 1 insertion(+) diff --git a/local/compose/pull.go b/local/compose/pull.go index dd66bf0e5..9c4772fe0 100644 --- a/local/compose/pull.go +++ b/local/compose/pull.go @@ -96,6 +96,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project) error stream, err := s.apiClient.ImagePull(ctx, service.Image, moby.ImagePullOptions{ RegistryAuth: base64.URLEncoding.EncodeToString(buf), + Platform: service.Platform, }) if err != nil { w.Event(progress.Event{ From a8d45d22ccca8bf7b30c2bad5bb60d322da77c10 Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Sat, 27 Feb 2021 07:43:37 -0300 Subject: [PATCH 2/3] Take platform in account on compose build Signed-off-by: Ulysses Souza --- local/compose/build.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/local/compose/build.go b/local/compose/build.go index 5a6f1f9f8..a2cae6565 100644 --- a/local/compose/build.go +++ b/local/compose/build.go @@ -26,12 +26,14 @@ import ( "github.com/docker/compose-cli/api/compose" "github.com/compose-spec/compose-go/types" + "github.com/containerd/containerd/platforms" "github.com/docker/buildx/build" "github.com/docker/buildx/driver" _ "github.com/docker/buildx/driver/docker" // required to get default driver registered "github.com/docker/buildx/util/progress" "github.com/docker/docker/errdefs" bclient "github.com/moby/buildkit/client" + specs "github.com/opencontainers/image-spec/specs-go/v1" ) func (s *composeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { @@ -41,7 +43,10 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti if service.Build != nil { imageName := getImageName(service, project.Name) imagesToBuild = append(imagesToBuild, imageName) - buildOptions := s.toBuildOptions(service, project.WorkingDir, imageName) + buildOptions, err := s.toBuildOptions(service, project.WorkingDir, imageName) + if err != nil { + return err + } buildOptions.Pull = options.Pull buildOptions.BuildArgs = options.Args opts[imageName] = buildOptions @@ -75,7 +80,10 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types. continue } imagesToBuild = append(imagesToBuild, imageName) - opts[imageName] = s.toBuildOptions(service, project.WorkingDir, imageName) + opts[imageName], err = s.toBuildOptions(service, project.WorkingDir, imageName) + if err != nil { + return err + } continue } if service.Image != "" { @@ -148,7 +156,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opts return err } -func (s *composeService) toBuildOptions(service types.ServiceConfig, contextPath string, imageTag string) build.Options { +func (s *composeService) toBuildOptions(service types.ServiceConfig, contextPath string, imageTag string) (build.Options, error) { var tags []string tags = append(tags, imageTag) @@ -157,6 +165,15 @@ func (s *composeService) toBuildOptions(service types.ServiceConfig, contextPath } var buildArgs map[string]string + var plats []specs.Platform + if service.Platform != "" { + p, err := platforms.Parse(service.Platform) + if err != nil { + return build.Options{}, err + } + plats = append(plats, p) + } + return build.Options{ Inputs: build.Inputs{ ContextPath: path.Join(contextPath, service.Build.Context), @@ -166,7 +183,8 @@ func (s *composeService) toBuildOptions(service types.ServiceConfig, contextPath Tags: tags, Target: service.Build.Target, Exports: []bclient.ExportEntry{{Type: "image", Attrs: map[string]string{}}}, - } + Platforms: plats, + }, nil } func flatten(in types.MappingWithEquals) map[string]string { From 939ace331cc0ecdb4a8796c640f6ed38fb997e2d Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Thu, 4 Mar 2021 20:08:41 -0300 Subject: [PATCH 3/3] Add platform on creating containers Signed-off-by: Ulysses Souza --- local/compose/convergence.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/local/compose/convergence.go b/local/compose/convergence.go index fe0571a56..c8e96de24 100644 --- a/local/compose/convergence.go +++ b/local/compose/convergence.go @@ -23,9 +23,11 @@ import ( "time" "github.com/compose-spec/compose-go/types" + "github.com/containerd/containerd/platforms" moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" + specs "github.com/opencontainers/image-spec/specs-go/v1" "golang.org/x/sync/errgroup" "github.com/docker/compose-cli/api/compose" @@ -278,7 +280,15 @@ func (s *composeService) createMobyContainer(ctx context.Context, project *types if err != nil { return err } - created, err := s.apiClient.ContainerCreate(ctx, containerConfig, hostConfig, networkingConfig, nil, name) + var plat *specs.Platform + if service.Platform != "" { + p, err := platforms.Parse(service.Platform) + if err != nil { + return err + } + plat = &p + } + created, err := s.apiClient.ContainerCreate(ctx, containerConfig, hostConfig, networkingConfig, plat, name) if err != nil { return err }