Skip to content

Commit

Permalink
Merge pull request #4650 from flouthoc/cache-to-with-mount
Browse files Browse the repository at this point in the history
stage_executor,cache-to: attempt to push cache only when `cacheKey` is valid
  • Loading branch information
rhatdan authored Mar 11, 2023
2 parents eed3aa2 + db50985 commit bae9047
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion imagebuildah/stage_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ func (s *StageExecutor) Execute(ctx context.Context, base string) (imgID string,
// Try to push this cache to remote repository only
// if cache was present on local storage and not
// pulled from remote source while processing this
if len(s.executor.cacheTo) != 0 && (!pulledAndUsedCacheImage || cacheID == "") {
if len(s.executor.cacheTo) != 0 && (!pulledAndUsedCacheImage || cacheID == "") && needsCacheKey {
logCachePush(cacheKey)
if err = s.pushCache(ctx, imgID, cacheKey); err != nil {
return "", nil, err
Expand Down
5 changes: 3 additions & 2 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4619,6 +4619,7 @@ ADD somefile somefile
FROM alpine
RUN echo hello
COPY --from=0 hello hello
RUN --mount=type=cache,id=YfHI60aApFM-target,target=/target echo world > /target/hello
_EOF

start_registry
Expand All @@ -4636,7 +4637,7 @@ _EOF
run printf "STEP 5/5: ADD somefile somefile\n--> Pushing cache"
step4=$output
# First run step in second stage should not be pushed since its already pushed
run printf "STEP 2/3: RUN echo hello\n--> Using cache"
run printf "STEP 2/4: RUN echo hello\n--> Using cache"
step5=$output
# Last step is `COPY --from=0 hello hello' so it must be committed and pushed
# actual output is `[2/2] STEP 3/3: COPY --from=0 hello hello\n[2/2] COMMIT test\n-->Pushing cache`
Expand Down Expand Up @@ -4672,7 +4673,7 @@ _EOF
run printf "STEP 5/5: ADD somefile somefile\n--> Cache pulled from remote"
step4=$output
# First run step in second stage should not be pulled since its already pulled
run printf "STEP 2/3: RUN echo hello\n--> Using cache"
run printf "STEP 2/4: RUN echo hello\n--> Using cache"
step5=$output
run printf "COPY --from=0 hello hello\n--> Cache pulled from remote"
step6=$output
Expand Down

0 comments on commit bae9047

Please sign in to comment.