Skip to content

Commit 3f3b25a

Browse files
feat: add support for building docker actions with private registries (#1557)
This commit adds a new `LoadDockerAuthConfigs` function, which loads all registry auths that are configured on the host and sends them with the build command to the docker daemon. This is needed in case act builds a docker action and the images referenced in that docker action are located on private registries or otherwise require authentication (e.g. to get a higher rate limit). The code is adapted from how the docker cli works: https://github.com/docker/cli/blob/257ff41304bf121bdf1acdf00a1c7a896ed038d1/cli/command/image/build.go#L323-L332 Co-authored-by: Markus Wolf <[email protected]> Co-authored-by: Markus Wolf <[email protected]>
1 parent 3ac756b commit 3f3b25a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

pkg/container/docker_auth.go

+21
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,24 @@ func LoadDockerAuthConfig(ctx context.Context, image string) (types.AuthConfig,
3838

3939
return types.AuthConfig(authConfig), nil
4040
}
41+
42+
func LoadDockerAuthConfigs(ctx context.Context) map[string]types.AuthConfig {
43+
logger := common.Logger(ctx)
44+
config, err := config.Load(config.Dir())
45+
if err != nil {
46+
logger.Warnf("Could not load docker config: %v", err)
47+
return nil
48+
}
49+
50+
if !config.ContainsAuth() {
51+
config.CredentialsStore = credentials.DetectDefaultStore(config.CredentialsStore)
52+
}
53+
54+
creds, _ := config.GetAllCredentials()
55+
authConfigs := make(map[string]types.AuthConfig, len(creds))
56+
for k, v := range creds {
57+
authConfigs[k] = types.AuthConfig(v)
58+
}
59+
60+
return authConfigs
61+
}

pkg/container/docker_build.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
4141

4242
tags := []string{input.ImageTag}
4343
options := types.ImageBuildOptions{
44-
Tags: tags,
45-
Remove: true,
46-
Platform: input.Platform,
44+
Tags: tags,
45+
Remove: true,
46+
Platform: input.Platform,
47+
AuthConfigs: LoadDockerAuthConfigs(ctx),
4748
}
4849
var buildContext io.ReadCloser
4950
if input.Container != nil {

0 commit comments

Comments
 (0)