mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 18:13:42 +08:00 
			
		
		
		
	Merge pull request #2905 from crazy-max/bake-infer-auth-token
bake: infer git auth token from remote files to build request
This commit is contained in:
		
							
								
								
									
										28
									
								
								bake/bake.go
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								bake/bake.go
									
									
									
									
									
								
							@@ -1179,6 +1179,16 @@ func updateContext(t *build.Inputs, inp *Input) {
 | 
				
			|||||||
	t.ContextState = &st
 | 
						t.ContextState = &st
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func isRemoteContext(t build.Inputs, inp *Input) bool {
 | 
				
			||||||
 | 
						if build.IsRemoteURL(t.ContextPath) {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if inp != nil && build.IsRemoteURL(inp.URL) && !strings.HasPrefix(t.ContextPath, "cwd://") {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func collectLocalPaths(t build.Inputs) []string {
 | 
					func collectLocalPaths(t build.Inputs) []string {
 | 
				
			||||||
	var out []string
 | 
						var out []string
 | 
				
			||||||
	if t.ContextState == nil {
 | 
						if t.ContextState == nil {
 | 
				
			||||||
@@ -1338,7 +1348,23 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	bo.Platforms = platforms
 | 
						bo.Platforms = platforms
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bo.SecretSpecs = t.Secrets.ToPB()
 | 
						secrets := t.Secrets
 | 
				
			||||||
 | 
						if isRemoteContext(bi, inp) {
 | 
				
			||||||
 | 
							if _, ok := os.LookupEnv("BUILDX_BAKE_GIT_AUTH_TOKEN"); ok {
 | 
				
			||||||
 | 
								secrets = append(secrets, &buildflags.Secret{
 | 
				
			||||||
 | 
									ID:  llb.GitAuthTokenKey,
 | 
				
			||||||
 | 
									Env: "BUILDX_BAKE_GIT_AUTH_TOKEN",
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if _, ok := os.LookupEnv("BUILDX_BAKE_GIT_AUTH_HEADER"); ok {
 | 
				
			||||||
 | 
								secrets = append(secrets, &buildflags.Secret{
 | 
				
			||||||
 | 
									ID:  llb.GitAuthHeaderKey,
 | 
				
			||||||
 | 
									Env: "BUILDX_BAKE_GIT_AUTH_HEADER",
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						secrets = secrets.Normalize()
 | 
				
			||||||
 | 
						bo.SecretSpecs = secrets.ToPB()
 | 
				
			||||||
	secretAttachment, err := controllerapi.CreateSecrets(bo.SecretSpecs)
 | 
						secretAttachment, err := controllerapi.CreateSecrets(bo.SecretSpecs)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user