mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
Merge pull request #1354 from ulyssessouza/fix-pull-arch
Take `platform` in account on pulling and building images
This commit is contained in:
commit
3f600281e6
@ -26,12 +26,14 @@ import (
|
|||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
|
"github.com/containerd/containerd/platforms"
|
||||||
"github.com/docker/buildx/build"
|
"github.com/docker/buildx/build"
|
||||||
"github.com/docker/buildx/driver"
|
"github.com/docker/buildx/driver"
|
||||||
_ "github.com/docker/buildx/driver/docker" // required to get default driver registered
|
_ "github.com/docker/buildx/driver/docker" // required to get default driver registered
|
||||||
"github.com/docker/buildx/util/progress"
|
"github.com/docker/buildx/util/progress"
|
||||||
"github.com/docker/docker/errdefs"
|
"github.com/docker/docker/errdefs"
|
||||||
bclient "github.com/moby/buildkit/client"
|
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 {
|
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 {
|
if service.Build != nil {
|
||||||
imageName := getImageName(service, project.Name)
|
imageName := getImageName(service, project.Name)
|
||||||
imagesToBuild = append(imagesToBuild, imageName)
|
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.Pull = options.Pull
|
||||||
buildOptions.BuildArgs = options.Args
|
buildOptions.BuildArgs = options.Args
|
||||||
opts[imageName] = buildOptions
|
opts[imageName] = buildOptions
|
||||||
@ -75,7 +80,10 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
imagesToBuild = append(imagesToBuild, imageName)
|
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
|
continue
|
||||||
}
|
}
|
||||||
if service.Image != "" {
|
if service.Image != "" {
|
||||||
@ -148,7 +156,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opts
|
|||||||
return err
|
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
|
var tags []string
|
||||||
tags = append(tags, imageTag)
|
tags = append(tags, imageTag)
|
||||||
|
|
||||||
@ -157,6 +165,15 @@ func (s *composeService) toBuildOptions(service types.ServiceConfig, contextPath
|
|||||||
}
|
}
|
||||||
var buildArgs map[string]string
|
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{
|
return build.Options{
|
||||||
Inputs: build.Inputs{
|
Inputs: build.Inputs{
|
||||||
ContextPath: path.Join(contextPath, service.Build.Context),
|
ContextPath: path.Join(contextPath, service.Build.Context),
|
||||||
@ -166,7 +183,8 @@ func (s *composeService) toBuildOptions(service types.ServiceConfig, contextPath
|
|||||||
Tags: tags,
|
Tags: tags,
|
||||||
Target: service.Build.Target,
|
Target: service.Build.Target,
|
||||||
Exports: []bclient.ExportEntry{{Type: "image", Attrs: map[string]string{}}},
|
Exports: []bclient.ExportEntry{{Type: "image", Attrs: map[string]string{}}},
|
||||||
}
|
Platforms: plats,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func flatten(in types.MappingWithEquals) map[string]string {
|
func flatten(in types.MappingWithEquals) map[string]string {
|
||||||
|
@ -23,9 +23,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
|
"github.com/containerd/containerd/platforms"
|
||||||
moby "github.com/docker/docker/api/types"
|
moby "github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
@ -280,7 +282,15 @@ func (s *composeService) createMobyContainer(ctx context.Context, project *types
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -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{
|
stream, err := s.apiClient.ImagePull(ctx, service.Image, moby.ImagePullOptions{
|
||||||
RegistryAuth: base64.URLEncoding.EncodeToString(buf),
|
RegistryAuth: base64.URLEncoding.EncodeToString(buf),
|
||||||
|
Platform: service.Platform,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Event(progress.Event{
|
w.Event(progress.Event{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user