Skip to content

Commit

Permalink
don't bind if cache-dir isn't found or isn't dir
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh committed Oct 21, 2022
1 parent 0311d99 commit dd325e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 2 additions & 4 deletions pipelines/fetch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ pipeline:
if [ ! "${{inputs.expected-sha256}}" == "" ]; then
fn="/var/cache/melange/sha256:${{inputs.expected-sha256}}"
printf "Looking for $fn in cache\n"
if [ -f $fn ]; then
printf "Found $fn in cache\n"
printf "fetch: found $fn in cache\n"
cp $fn $bn
fi
else
fn="/var/cache/melange/sha512:${{inputs.expected-sha512}}"
printf "Looking for $fn in cache\n"
if [ -f $fn ]; then
printf "Found $fn in cache\n"
printf "fetch: found $fn in cache\n"
cp $fn $bn
fi
fi
Expand Down
9 changes: 8 additions & 1 deletion pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@ func (ctx *Context) WorkspaceCmd(args ...string) (*exec.Cmd, error) {
baseargs := []string{
"--bind", ctx.GuestDir, "/",
"--bind", ctx.WorkspaceDir, "/home/build",
"--bind", ctx.CacheDir, "/var/cache/melange",
"--bind", "/etc/resolv.conf", "/etc/resolv.conf",
"--unshare-pid",
"--dev", "/dev",
Expand All @@ -799,6 +798,14 @@ func (ctx *Context) WorkspaceCmd(args ...string) (*exec.Cmd, error) {
"--setenv", "SOURCE_DATE_EPOCH", fmt.Sprintf("%d", ctx.SourceDateEpoch.Unix()),
}

if ctx.CacheDir != "" {
if fi, err := os.Stat(ctx.CacheDir); err == nil && fi.IsDir() {
baseargs = append(baseargs, "--bind", ctx.CacheDir, "/var/cache/melange")
} else {
ctx.Logger.Printf("--cache-dir %s not a dir; skipping", ctx.CacheDir)
}
}

// Add any user-provided env vars
for k, v := range ctx.Configuration.Environment.Environment {
baseargs = append(baseargs, "--setenv", k, v)
Expand Down

0 comments on commit dd325e8

Please sign in to comment.