-
Notifications
You must be signed in to change notification settings - Fork 8
Use Corepack for selecting package manager #28
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,20 +10,18 @@ ONBUILD ARG YARN_VERSION | |
| # Allow installation as non-root user | ||
| ONBUILD RUN npm config set unsafe-perm true | ||
|
|
||
| # All but package.json is optional | ||
| ONBUILD COPY package.json yarn.lock* .yarnrc* .npmrc* npm-shrinkwrap.json* package-lock.json* pnpm-lock.yaml* ./ | ||
| ONBUILD COPY . ./ | ||
|
|
||
| # Install dependencies for native builds | ||
| # This is in one giant command to keep the image size small | ||
| # TODO: When Finnbuild uses Docker 1.13, we can use --squash, which means this won't have to be one giant command | ||
| ONBUILD RUN apk upgrade -U && \ | ||
| apk add --no-cache --virtual build-dependencies make gcc g++ python git || \ | ||
| apk add --no-cache --virtual build-dependencies make gcc g++ python3 git && \ | ||
| corepack enable && \ | ||
| corepack prepare --activate --all && \ | ||
| install-dependencies.sh && \ | ||
| rm /usr/local/bin/yarn && npm uninstall --loglevel warn --global pnpm && npm uninstall --loglevel warn --global npm && \ | ||
| apk del build-dependencies | ||
|
|
||
| ONBUILD COPY . ./ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly better to do the copy as late as possible so Docker can reuse the layer which installs build dependencies, corepack and node dependencies when only changing some production code (this has nothing to do with package managers).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I think we need to copy any lock file here and all the other files later. I am not 100% sure about that but we definetly need package.json copied here before we run any of the commands. I would really love if we could make it so that we don't have to hard code each package managers lock files into this. Any suggestions on how to avoid hard coding such? |
||
|
|
||
| ONBUILD RUN chown -R node:node . | ||
| ONBUILD USER node | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,9 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # This script does `yarn install` if a `yarn.lock` file is present, otherwise `npm install` | ||
|
|
||
| set -e | ||
|
|
||
| if [[ -n "${FAIL_ON_DIRTY_LOCKFILE}" ]]; then | ||
| if [[ "${YARN_VERSION:0:2}" == "2." ]]; then | ||
| YARN_OPTS="--immutable" | ||
| else | ||
| YARN_OPTS="--frozen-lockfile" | ||
| fi | ||
| NPM_CMD="ci" | ||
| else | ||
| YARN_OPTS="" | ||
| NPM_CMD="install" | ||
| fi | ||
| # Execute install with corepack, return true to ignore errors from non matching package managers | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any way we could allow users to provide args/flags for these commands?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to corepack or the package manager? Or both.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The package manager commands. My concern is if a user wants to pass some args to their package manager of choice, how do we enable that? Not sure if Docker's ENV would work to pass args down, or if there's another way. e.g. pseudocode |
||
| corepack yarn install || true | ||
| corepack pnpm install || true | ||
| corepack npm ci || true | ||
|
|
||
| if [[ -f "/home/node/src/yarn.lock" || -f "/home/node/src/.yarnrc.yml" || -f "/home/node/src/.yarnrc" ]]; then | ||
| if [[ -n $YARN_VERSION ]]; then | ||
| yarn set version $YARN_VERSION | ||
| fi | ||
| yarn install $YARN_OPTS | ||
| # Check if the installed tree is correct. Install all dependencies if not | ||
| yarn check --verify-tree || NODE_ENV=development yarn install | ||
| yarn cache clean | ||
| elif [[ -f "/home/node/src/pnpm-lock.yaml" ]]; then | ||
| pnpm i --prefer-frozen-lockfile --prod | ||
| elif [[ -f "/home/node/src/package-lock.json" || -f "/home/node/src/npm-shrinkwrap.json" ]]; then | ||
| npm $NPM_CMD | ||
| npm cache clean --force | ||
| else | ||
| npm install | ||
| npm cache clean --force | ||
| fi | ||
Uh oh!
There was an error while loading. Please reload this page.