@@ -37,6 +37,7 @@ import (
37
37
"github.com/moby/buildkit/session/sshforward/sshprovider"
38
38
"github.com/moby/buildkit/util/entitlements"
39
39
specs "github.com/opencontainers/image-spec/specs-go/v1"
40
+ "github.com/pkg/errors"
40
41
41
42
"github.com/docker/compose/v2/pkg/api"
42
43
"github.com/docker/compose/v2/pkg/progress"
@@ -247,9 +248,29 @@ func (s *composeService) getLocalImagesDigests(ctx context.Context, project *typ
247
248
images [name ] = info .ID
248
249
}
249
250
250
- for i := range project .Services {
251
- imgName := api .GetImageNameOrDefault (project . Services [ i ] , project .Name )
251
+ for i , service := range project .Services {
252
+ imgName := api .GetImageNameOrDefault (service , project .Name )
252
253
digest , ok := images [imgName ]
254
+ if service .Platform != "" {
255
+ platform , err := platforms .Parse (service .Platform )
256
+ if err != nil {
257
+ return nil , err
258
+ }
259
+ inspect , _ , err := s .apiClient ().ImageInspectWithRaw (ctx , digest )
260
+ if err != nil {
261
+ return nil , err
262
+ }
263
+ actual := specs.Platform {
264
+ Architecture : inspect .Architecture ,
265
+ OS : inspect .Os ,
266
+ Variant : inspect .Variant ,
267
+ }
268
+ if ! platforms .NewMatcher (platform ).Match (actual ) {
269
+ return nil , errors .Errorf ("image with reference %s was found but does not match the specified platform: wanted %s, actual: %s" ,
270
+ imgName , platforms .Format (platform ), platforms .Format (actual ))
271
+ }
272
+ }
273
+
253
274
if ok {
254
275
project .Services [i ].CustomLabels .Add (api .ImageDigestLabel , digest )
255
276
}
0 commit comments