diff --git a/envbuilder.go b/envbuilder.go index 92ffc84f..9117132d 100644 --- a/envbuilder.go +++ b/envbuilder.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "io" + "io/fs" "maps" "net" "net/http" @@ -604,9 +605,14 @@ func Run(ctx context.Context, options Options) error { // Remove the Docker config secret file! if options.DockerConfigBase64 != "" { - err = os.Remove(filepath.Join(MagicDir, "config.json")) - if err != nil && !os.IsNotExist(err) { - return fmt.Errorf("remove docker config: %w", err) + c := filepath.Join(MagicDir, "config.json") + err = os.Remove(c) + if err != nil { + if !errors.Is(err, fs.ErrNotExist) { + return fmt.Errorf("remove docker config: %w", err) + } else { + fmt.Fprintln(os.Stderr, "failed to remove the Docker config secret file: %w", c) + } } } diff --git a/integration/integration_test.go b/integration/integration_test.go index 7e41d600..ca0ec0b6 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -231,11 +231,16 @@ func TestBuildFromDockerfile(t *testing.T) { ctr, err := runEnvbuilder(t, options{env: []string{ "GIT_URL=" + srv.URL, "DOCKERFILE_PATH=Dockerfile", + "DOCKER_CONFIG_BASE64=" + base64.StdEncoding.EncodeToString([]byte(`{"experimental": "enabled"}`)), }}) require.NoError(t, err) output := execContainer(t, ctr, "echo hello") require.Equal(t, "hello", strings.TrimSpace(output)) + + // Verify that the Docker configuration secret file is removed + output = execContainer(t, ctr, "stat "+filepath.Join(envbuilder.MagicDir, "config.json")) + require.Contains(t, output, "No such file or directory") } func TestBuildPrintBuildOutput(t *testing.T) {