Skip to content

Commit

Permalink
fix: dir error using buildkit service
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Dec 1, 2023
1 parent e88792a commit 25d8b47
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/build/dockerfile-x.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -81,6 +82,18 @@ func loadDockerfileX(ctx context.Context, c client.Client, src *dockerui.Source)
return nil
}

func EnsureDir(filePath string, perm os.FileMode) error {
// Extract the directory part of the file path.
dir := filepath.Dir(filePath)

// Check if the directory exists.
if _, err := os.Stat(dir); os.IsNotExist(err) {
// The directory does not exist, so create it.
return os.MkdirAll(dir, perm)
}
return nil
}

func tryDockerfileX(ctx context.Context, c client.Client, filename string) (result string, err error) {
var lastMissingFile string

Expand All @@ -90,7 +103,9 @@ func tryDockerfileX(ctx context.Context, c client.Client, filename string) (resu
}

uniqFilename := fmt.Sprintf("%s_%d", filename, time.Now().Unix())

if err = EnsureDir(uniqFilename, 0755); err != nil {
return "", fmt.Errorf("Error creating parent dir for file '%s': %s\n", uniqFilename, err)
}
if err = ioutil.WriteFile(uniqFilename, xdockerfile, 0644); err != nil {
return "", fmt.Errorf("Error writing to file '%s': %s\n", uniqFilename, err)
}
Expand Down

0 comments on commit 25d8b47

Please sign in to comment.