@@ -63,7 +63,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
63
63
if service .Build != nil {
64
64
imageName := getImageName (service , project .Name )
65
65
imagesToBuild = append (imagesToBuild , imageName )
66
- buildOptions , err := s .toBuildOptions (project , service , imageName )
66
+ buildOptions , err := s .toBuildOptions (project , service , imageName , options . SSHs )
67
67
if err != nil {
68
68
return err
69
69
}
@@ -81,15 +81,6 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
81
81
Attrs : map [string ]string {"ref" : image },
82
82
})
83
83
}
84
-
85
- if len (options .SSHs ) > 0 || len (service .Build .SSH ) > 0 {
86
- sshAgentProvider , err := sshAgentProvider (append (service .Build .SSH , options .SSHs ... ))
87
- if err != nil {
88
- return err
89
- }
90
- buildOptions .Session = append (buildOptions .Session , sshAgentProvider )
91
- }
92
-
93
84
opts [imageName ] = buildOptions
94
85
}
95
86
}
@@ -168,7 +159,7 @@ func (s *composeService) getBuildOptions(project *types.Project, images map[stri
168
159
if localImagePresent && service .PullPolicy != types .PullPolicyBuild {
169
160
continue
170
161
}
171
- opt , err := s .toBuildOptions (project , service , imageName )
162
+ opt , err := s .toBuildOptions (project , service , imageName , []types. SSHKey {} )
172
163
if err != nil {
173
164
return nil , err
174
165
}
@@ -218,7 +209,7 @@ func (s *composeService) doBuild(ctx context.Context, project *types.Project, op
218
209
return s .doBuildBuildkit (ctx , project , opts , mode )
219
210
}
220
211
221
- func (s * composeService ) toBuildOptions (project * types.Project , service types.ServiceConfig , imageTag string ) (build.Options , error ) {
212
+ func (s * composeService ) toBuildOptions (project * types.Project , service types.ServiceConfig , imageTag string , sshKeys []types. SSHKey ) (build.Options , error ) {
222
213
var tags []string
223
214
tags = append (tags , imageTag )
224
215
@@ -252,6 +243,17 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
252
243
return build.Options {}, err
253
244
}
254
245
246
+ sessionConfig := []session.Attachable {
247
+ authprovider .NewDockerAuthProvider (s .stderr ()),
248
+ }
249
+ if len (sshKeys ) > 0 || len (service .Build .SSH ) > 0 {
250
+ sshAgentProvider , err := sshAgentProvider (append (service .Build .SSH , sshKeys ... ))
251
+ if err != nil {
252
+ return build.Options {}, err
253
+ }
254
+ sessionConfig = append (sessionConfig , sshAgentProvider )
255
+ }
256
+
255
257
return build.Options {
256
258
Inputs : build.Inputs {
257
259
ContextPath : service .Build .Context ,
@@ -269,9 +271,7 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
269
271
Labels : service .Build .Labels ,
270
272
NetworkMode : service .Build .Network ,
271
273
ExtraHosts : service .Build .ExtraHosts ,
272
- Session : []session.Attachable {
273
- authprovider .NewDockerAuthProvider (s .stderr ()),
274
- },
274
+ Session : sessionConfig ,
275
275
}, nil
276
276
}
277
277
0 commit comments