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

check local image matches the required platform #10546

Merged
merged 1 commit into from
May 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"github.com/moby/buildkit/session/sshforward/sshprovider"
"github.com/moby/buildkit/util/entitlements"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
Expand Down Expand Up @@ -247,9 +248,29 @@
images[name] = info.ID
}

for i := range project.Services {
imgName := api.GetImageNameOrDefault(project.Services[i], project.Name)
for i, service := range project.Services {
imgName := api.GetImageNameOrDefault(service, project.Name)
digest, ok := images[imgName]
if service.Platform != "" {
platform, err := platforms.Parse(service.Platform)
if err != nil {
return nil, err
}
inspect, _, err := s.apiClient().ImageInspectWithRaw(ctx, digest)
if err != nil {
return nil, err
}
actual := specs.Platform{
Architecture: inspect.Architecture,
OS: inspect.Os,
Variant: inspect.Variant,
}
if !platforms.NewMatcher(platform).Match(actual) {
return nil, errors.Errorf("image with reference %s was found but does not match the specified platform: wanted %s, actual: %s",
imgName, platforms.Format(platform), platforms.Format(actual))
}

Check warning on line 271 in pkg/compose/build.go

View check run for this annotation

Codecov / codecov/patch

pkg/compose/build.go#L255-L271

Added lines #L255 - L271 were not covered by tests
}

if ok {
project.Services[i].CustomLabels.Add(api.ImageDigestLabel, digest)
}
Expand Down