@@ -1179,6 +1179,16 @@ func updateContext(t *build.Inputs, inp *Input) {
1179
1179
t .ContextState = & st
1180
1180
}
1181
1181
1182
+ func isRemoteContext (t build.Inputs , inp * Input ) bool {
1183
+ if build .IsRemoteURL (t .ContextPath ) {
1184
+ return true
1185
+ }
1186
+ if inp != nil && build .IsRemoteURL (inp .URL ) && ! strings .HasPrefix (t .ContextPath , "cwd://" ) {
1187
+ return true
1188
+ }
1189
+ return false
1190
+ }
1191
+
1182
1192
func collectLocalPaths (t build.Inputs ) []string {
1183
1193
var out []string
1184
1194
if t .ContextState == nil {
@@ -1338,7 +1348,23 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
1338
1348
}
1339
1349
bo .Platforms = platforms
1340
1350
1341
- bo .SecretSpecs = t .Secrets .ToPB ()
1351
+ secrets := t .Secrets
1352
+ if isRemoteContext (bi , inp ) {
1353
+ if _ , ok := os .LookupEnv ("BUILDX_BAKE_GIT_AUTH_TOKEN" ); ok {
1354
+ secrets = append (secrets , & buildflags.Secret {
1355
+ ID : llb .GitAuthTokenKey ,
1356
+ Env : "BUILDX_BAKE_GIT_AUTH_TOKEN" ,
1357
+ })
1358
+ }
1359
+ if _ , ok := os .LookupEnv ("BUILDX_BAKE_GIT_AUTH_HEADER" ); ok {
1360
+ secrets = append (secrets , & buildflags.Secret {
1361
+ ID : llb .GitAuthHeaderKey ,
1362
+ Env : "BUILDX_BAKE_GIT_AUTH_HEADER" ,
1363
+ })
1364
+ }
1365
+ }
1366
+ secrets = secrets .Normalize ()
1367
+ bo .SecretSpecs = secrets .ToPB ()
1342
1368
secretAttachment , err := controllerapi .CreateSecrets (bo .SecretSpecs )
1343
1369
if err != nil {
1344
1370
return nil , err
0 commit comments