@@ -45,7 +45,7 @@ import (
4545 "github.com/docker/compose/v5/pkg/api"
4646)
4747
48- func (s * composeService ) doBuildClassic (ctx context.Context , project * types.Project , serviceToBuild types.Services , options api.BuildOptions ) (map [string ]string , error ) {
48+ func (s * composeService ) doBuildClassic (ctx context.Context , project * types.Project , imagesToBuild map [ string ] types.ContainerSpec , options api.BuildOptions ) (map [string ]string , error ) {
4949 imageIDs := map [string ]string {}
5050
5151 // Not using bake, additional_context: service:xx is implemented by building images in dependency order
@@ -82,14 +82,14 @@ func (s *composeService) doBuildClassic(ctx context.Context, project *types.Proj
8282
8383 err = InDependencyOrder (ctx , project , func (ctx context.Context , name string ) error {
8484 trace .SpanFromContext (ctx ).SetAttributes (attribute .String ("builder" , "classic" ))
85- service , ok := serviceToBuild [name ]
85+ spec , ok := imagesToBuild [name ]
8686 if ! ok {
8787 return nil
8888 }
8989
90- image := api .GetImageNameOrDefault ( service , project .Name )
90+ image := api .ImageNameOrDefault ( spec . Image , name , project .Name )
9191 s .events .On (buildingEvent (image ))
92- id , err := s .doBuildImage (ctx , project , service , options )
92+ id , err := s .doBuildImage (ctx , project , name , spec , options )
9393 if err != nil {
9494 return err
9595 }
@@ -118,37 +118,37 @@ func (s *composeService) doBuildClassic(ctx context.Context, project *types.Proj
118118}
119119
120120//nolint:gocyclo
121- func (s * composeService ) doBuildImage (ctx context.Context , project * types.Project , service types.ServiceConfig , options api.BuildOptions ) (string , error ) {
121+ func (s * composeService ) doBuildImage (ctx context.Context , project * types.Project , name string , spec types.ContainerSpec , options api.BuildOptions ) (string , error ) {
122122 var (
123123 buildCtx io.ReadCloser
124124 dockerfileCtx io.ReadCloser
125125 contextDir string
126126 relDockerfile string
127127 )
128128
129- if len (service .Build .Platforms ) > 1 {
129+ if len (spec .Build .Platforms ) > 1 {
130130 return "" , fmt .Errorf ("the classic builder doesn't support multi-arch build, set DOCKER_BUILDKIT=1 to use BuildKit" )
131131 }
132- if service .Build .Privileged {
132+ if spec .Build .Privileged {
133133 return "" , fmt .Errorf ("the classic builder doesn't support privileged mode, set DOCKER_BUILDKIT=1 to use BuildKit" )
134134 }
135- if len (service .Build .AdditionalContexts ) > 0 {
135+ if len (spec .Build .AdditionalContexts ) > 0 {
136136 return "" , fmt .Errorf ("the classic builder doesn't support additional contexts, set DOCKER_BUILDKIT=1 to use BuildKit" )
137137 }
138- if len (service .Build .SSH ) > 0 {
138+ if len (spec .Build .SSH ) > 0 {
139139 return "" , fmt .Errorf ("the classic builder doesn't support SSH keys, set DOCKER_BUILDKIT=1 to use BuildKit" )
140140 }
141- if len (service .Build .Secrets ) > 0 {
141+ if len (spec .Build .Secrets ) > 0 {
142142 return "" , fmt .Errorf ("the classic builder doesn't support secrets, set DOCKER_BUILDKIT=1 to use BuildKit" )
143143 }
144144
145- if service .Build .Labels == nil {
146- service .Build .Labels = make (map [string ]string )
145+ if spec .Build .Labels == nil {
146+ spec .Build .Labels = make (map [string ]string )
147147 }
148- service .Build .Labels [api .ImageBuilderLabel ] = "classic"
148+ spec .Build .Labels [api .ImageBuilderLabel ] = "classic"
149149
150- dockerfileName := dockerFilePath (service .Build .Context , service .Build .Dockerfile )
151- specifiedContext := service .Build .Context
150+ dockerfileName := dockerFilePath (spec .Build .Context , spec .Build .Dockerfile )
151+ specifiedContext := spec .Build .Context
152152 progBuff := s .stdout ()
153153 buildBuff := s .stdout ()
154154
@@ -251,8 +251,8 @@ func (s *composeService) doBuildImage(ctx context.Context, project *types.Projec
251251 RegistryToken : authConfig .RegistryToken ,
252252 }
253253 }
254- buildOpts := imageBuildOptions (s .getProxyConfig (), project , service , options )
255- imageName := api .GetImageNameOrDefault ( service , project .Name )
254+ buildOpts := imageBuildOptions (s .getProxyConfig (), project , spec , options )
255+ imageName := api .ImageNameOrDefault ( spec . Image , name , project .Name )
256256 buildOpts .Tags = append (buildOpts .Tags , imageName )
257257 buildOpts .Dockerfile = relDockerfile
258258 buildOpts .AuthConfigs = authConfigs
@@ -293,15 +293,15 @@ func (s *composeService) doBuildImage(ctx context.Context, project *types.Projec
293293 return imageID , nil
294294}
295295
296- func imageBuildOptions (proxyConfigs map [string ]string , project * types.Project , service types.ServiceConfig , options api.BuildOptions ) client.ImageBuildOptions {
297- config := service .Build
296+ func imageBuildOptions (proxyConfigs map [string ]string , project * types.Project , spec types.ContainerSpec , options api.BuildOptions ) client.ImageBuildOptions {
297+ config := spec .Build
298298 return client.ImageBuildOptions {
299299 Version : buildtypes .BuilderV1 ,
300300 Tags : config .Tags ,
301301 NoCache : config .NoCache ,
302302 Remove : true ,
303303 PullParent : config .Pull ,
304- BuildArgs : resolveAndMergeBuildArgs (proxyConfigs , project , service , options ),
304+ BuildArgs : resolveAndMergeBuildArgs (proxyConfigs , project , spec , options ),
305305 Labels : config .Labels ,
306306 NetworkMode : config .Network ,
307307 ExtraHosts : config .ExtraHosts .AsList (":" ),
0 commit comments