Skip to content

Commit

Permalink
fix: set DOCKER_CONFIG dynamically (#336)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4547249)
  • Loading branch information
johnstcn committed Sep 26, 2024
1 parent fb50f83 commit 3d12008
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 8 additions & 1 deletion envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ func initDockerConfigJSON(logf log.Func, magicDir magicdir.MagicDir, dockerConfi
if dockerConfigBase64 == "" {
return noop, nil
}
cfgPath := filepath.Join(magicDir.Path(), "config.json")
cfgPath := magicDir.Join("config.json")
decoded, err := base64.StdEncoding.DecodeString(dockerConfigBase64)
if err != nil {
return noop, fmt.Errorf("decode docker config: %w", err)
Expand All @@ -1497,9 +1497,16 @@ func initDockerConfigJSON(logf log.Func, magicDir magicdir.MagicDir, dockerConfi
return noop, fmt.Errorf("write docker config: %w", err)
}
logf(log.LevelInfo, "Wrote Docker config JSON to %s", cfgPath)
oldDockerConfig := os.Getenv("DOCKER_CONFIG")
_ = os.Setenv("DOCKER_CONFIG", magicDir.Path())
newDockerConfig := os.Getenv("DOCKER_CONFIG")
logf(log.LevelInfo, "Set DOCKER_CONFIG to %s", newDockerConfig)
cleanup := func() error {
var cleanupErr error
cleanupOnce.Do(func() {
// Restore the old DOCKER_CONFIG value.
os.Setenv("DOCKER_CONFIG", oldDockerConfig)
logf(log.LevelInfo, "Restored DOCKER_CONFIG to %s", oldDockerConfig)
// Remove the Docker config secret file!
if cleanupErr = os.Remove(cfgPath); err != nil {
if !errors.Is(err, fs.ErrNotExist) {
Expand Down
2 changes: 0 additions & 2 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ ARG TARGETARCH
COPY envbuilder-${TARGETARCH} /.envbuilder/bin/envbuilder

ENV KANIKO_DIR /.envbuilder
# Kaniko looks for the Docker config at $DOCKER_CONFIG/config.json
ENV DOCKER_CONFIG /.envbuilder

ENTRYPOINT ["/.envbuilder/bin/envbuilder"]

0 comments on commit 3d12008

Please sign in to comment.