Skip to content

Commit 87d84be

Browse files
committed
fix: image failures for non-root uses of yarn and pnpm
The lockfile generation tool `yarn` fails when used in the `phylum-ci` Docker image as a non-root user. An example of the failure can be seen from the output of the "smoke test," which is using `scripts/docker_tests.sh` to ensure basic functionality: ``` yarn --version Internal Error: EACCES: permission denied, open '/usr/local/corepack/lastKnownGood.json' Error: EACCES: permission denied, open '/usr/local/corepack/lastKnownGood.json' ``` The same behavior happens for `pnpm`. These are the tools installed by `corepack`, which changed recently to "Bump Known Good Release when downloading new version" (nodejs/corepack#364). Part of that change was to make use of the `COREPACK_DEFAULT_TO_LATEST` environment variable to *not* update the last known good version, but setting that to `0` does not appear to prevent *all* writes (or creating a file handle with write permission) to the `lastKnownGood.json` file. This fix simply modifies the file permissions for `lastKnownGood.json` so that non-root users can read and write to it. This approach may seem specific to a file that may change name or location in the future, but the alternative method of adding `${COREPACK_HOME}` to the list of directories that get updated with a `chmod -vR 777` was deemed to be too blunt and therefore less desirable.
1 parent 8aafce3 commit 87d84be

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ RUN \
280280
# Create a git config file in a location accessible for $HOME-less users
281281
# Ref: https://git-scm.com/docs/git-config#FILES
282282
mkdir -vp "${XDG_CONFIG_HOME}/git" && touch "${XDG_CONFIG_HOME}/git/config"; \
283-
# Ensure the XDG directories have permissions for non-root users
283+
# Ensure the XDG and Corepack directories have permissions for non-root users
284284
mkdir -vp "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_STATE_HOME}" "${XDG_CACHE_HOME}"; \
285285
chmod -vR 777 "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_STATE_HOME}" "${XDG_CACHE_HOME}"; \
286+
chmod -v 666 "${COREPACK_HOME}/lastKnownGood.json"; \
286287
#
287288
# Final cleanup
288289
apt-get remove --yes --auto-remove \

0 commit comments

Comments
 (0)