Skip to content

Commit ff220b4

Browse files
chore: warn if docker secret cleanup fails (#163)
1 parent be72259 commit ff220b4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

envbuilder.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"fmt"
1212
"io"
13+
"io/fs"
1314
"maps"
1415
"net"
1516
"net/http"
@@ -604,9 +605,14 @@ func Run(ctx context.Context, options Options) error {
604605

605606
// Remove the Docker config secret file!
606607
if options.DockerConfigBase64 != "" {
607-
err = os.Remove(filepath.Join(MagicDir, "config.json"))
608-
if err != nil && !os.IsNotExist(err) {
609-
return fmt.Errorf("remove docker config: %w", err)
608+
c := filepath.Join(MagicDir, "config.json")
609+
err = os.Remove(c)
610+
if err != nil {
611+
if !errors.Is(err, fs.ErrNotExist) {
612+
return fmt.Errorf("remove docker config: %w", err)
613+
} else {
614+
fmt.Fprintln(os.Stderr, "failed to remove the Docker config secret file: %w", c)
615+
}
610616
}
611617
}
612618

integration/integration_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,16 @@ func TestBuildFromDockerfile(t *testing.T) {
231231
ctr, err := runEnvbuilder(t, options{env: []string{
232232
"GIT_URL=" + srv.URL,
233233
"DOCKERFILE_PATH=Dockerfile",
234+
"DOCKER_CONFIG_BASE64=" + base64.StdEncoding.EncodeToString([]byte(`{"experimental": "enabled"}`)),
234235
}})
235236
require.NoError(t, err)
236237

237238
output := execContainer(t, ctr, "echo hello")
238239
require.Equal(t, "hello", strings.TrimSpace(output))
240+
241+
// Verify that the Docker configuration secret file is removed
242+
output = execContainer(t, ctr, "stat "+filepath.Join(envbuilder.MagicDir, "config.json"))
243+
require.Contains(t, output, "No such file or directory")
239244
}
240245

241246
func TestBuildPrintBuildOutput(t *testing.T) {

0 commit comments

Comments
 (0)