Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount,cache: internal lockfiles must not be part of user's cache content #4349

Merged
merged 3 commits into from
Oct 19, 2022

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Oct 18, 2022

Following PR introduces two change

  • --mount=type=cache must not add internal lockfiles to cache directory
    created by users instead store it in a different central directory with
    path as /base/buildah-cache/buildah-lockfiles.
    There are use-cases where users can wipe cache between the builds so
    lockfiles will be removed in unexpected manner and also its not okay to
    mix buildah's internal construct with user's cache content.

  • run: Single RUN can contain multiple --mount commands so lets append into
    lockedTargets so we collect lockfiles from all the --mount
    instructions.

Tryout example

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"

What type of PR is this?

/kind bug

What this PR does / why we need it:

How to verify it

Newly added integration test and old tests must not fail.

Which issue(s) this PR fixes:

Closes: #4342

Special notes for your reviewer:

Does this PR introduce a user-facing change?

mount,cache: lockfiles should not be created with user's cache content


// create a subdirectory inside `cacheParent` just to store lockfiles
buildahLockFilesDir = filepath.Join(cacheParent, buildahLockFilesDir)
err = os.MkdirAll(buildahLockFilesDir, os.FileMode(0755))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this lockdir need to be shared between different users? Should it be 0700? Does it matter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhatdan You are correct 0700 is better here.

@flouthoc flouthoc requested a review from rhatdan October 18, 2022 14:43
@rhatdan
Copy link
Member

rhatdan commented Oct 18, 2022

LGTM
@nalind @vrothberg @giuseppe @umohnani8 PTAL

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -33,6 +33,9 @@ const (
BuildahCacheDir = "buildah-cache"
// mount=type=cache allows users to lock a cache store while its being used by another build
BuildahCacheLockfile = "buildah-cache-lockfile"
// All the lockfiles are stored in a seperate directory inside `BuildahCacheDir`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in seperate

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

`--mount=type=cache` must not add internal lockfiles to cache directory
created by users instead store it in a different central directory with
path as `/base/buildah-cache/buildah-lockfiles`.

There are use-cases where users can wipe cache between the builds so
lockfiles will be removed in unexpected manner and also its not okay to
mix buildah's internal construct with user's cache content.

Helps in: containers#4342

Signed-off-by: Aditya R <[email protected]>
Single `RUN` can contain multiple `--mount` commands so lets append into
`lockedTargets` so we collect `lockfiles` from all the `--mount`
instructions.

Helps in: containers#4342

Signed-off-by: Aditya R <[email protected]>
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 <[email protected]>
@rhatdan
Copy link
Member

rhatdan commented Oct 19, 2022

/approve
/lgtm

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 19, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc, giuseppe, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [flouthoc,giuseppe,rhatdan]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit ea425a2 into containers:main Oct 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RUN --mount-type=cache,sharing=locked hangs in specific cases
4 participants