Skip to content

Commit

Permalink
test: cleaning cache must not clean lockfiles
Browse files Browse the repository at this point in the history
Use-cases as shown in below containerfile cleans cache between the
builds, in previous commits we have ensured that buildah lockfiles will
not be part of user's cache content hence following use-case must paas

```
FROM quay.io/centos/centos:7

ARG WIPE_CACHE

RUN --mount=type=cache,target=/cache1,sharing=locked \
    --mount=type=cache,target=/cache2 \
    set -ex; \
    ls -l /cache1; \
    if [[ -v WIPE_CACHE ]]; then \
      >&2 echo "Wiping cache"; \
      find /cache1 -mindepth 1 -delete; \
    fi; \
    echo "foo" > /cache1/foo.txt; \
    ls -l /cache1; \
    chmod --recursive g=u /cache1; \
    : ;

RUN --mount=type=cache,target=/cache1,sharing=locked \
    >&2 echo "Never get here"
```

Closes: containers#4342

Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed Oct 19, 2022
1 parent 6838cbc commit 7ec6529
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ load helpers
expect_output --substring "options use-vc"
}

#Verify https://github.com/containers/buildah/issues/4342
@test "buildkit-mount type=cache should not hang if cache is wiped in between" {
containerfile=$BUDFILES/cache-mount-locked/Containerfile
run_buildah build $WITH_POLICY_JSON -t source -f $containerfile $BUDFILES/cache-mount-locked
# build should be success and must contain `hello` from `file` in last step
expect_output --substring "hello"
}

# Test for https://github.com/containers/buildah/pull/4295
@test "build test warning for preconfigured TARGETARCH, TARGETOS, TARGETPLATFORM or TARGETVARIANT" {
_prefetch alpine
Expand Down
21 changes: 21 additions & 0 deletions tests/bud/cache-mount-locked/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM quay.io/centos/centos:7

ARG WIPE_CACHE

COPY file .

RUN --mount=type=cache,target=/cache1,sharing=locked \
--mount=type=cache,target=/cache2 \
set -ex; \
ls -l /cache1; \
if [[ -v WIPE_CACHE ]]; then \
>&2 echo "Wiping cache"; \
find /cache1 -mindepth 1 -delete; \
fi; \
echo "foo" > /cache1/foo.txt; \
ls -l /cache1; \
chmod --recursive g=u /cache1; \
: ;

# Cache was wiped-out but lock should not hang here: https://github.com/containers/buildah/issues/4342
RUN --mount=type=cache,target=/cache1,sharing=locked cat file
1 change: 1 addition & 0 deletions tests/bud/cache-mount-locked/file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello

0 comments on commit 7ec6529

Please sign in to comment.