Skip to content

Commit acfcf89

Browse files
committed
feat: enable Corepack (pnpm support, unbundle yarn)
This patch enables Corepack, allowing to use pnpm directly and unbundling yarn from the default image. Removing yarn also simplifies the image and the maintainance. This change as been discussed in nodejs#777. Closes nodejs#777, nodejs#1645, nodejs#1755.
1 parent 0fb3fac commit acfcf89

9 files changed

+35
-153
lines changed

.github/workflows/build-test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,6 @@ jobs:
9494

9595
- name: Test for yarn
9696
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} yarn --version
97+
98+
- name: Test for pnpm
99+
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} pnpm --version

CONTRIBUTING.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ Thank you for your contribution. Here are a set of guidelines for contributing t
66

77
New **Node.js** releases are released as soon as possible.
88

9-
New **NPM** releases are not tracked. We simply use the NPM version bundled in the corresponding Node.js release.
10-
11-
**Yarn** is updated to the latest version only when there is a new Node.js SemVer PATCH release (unless Yarn has received a security update), and it's updated only in the branch with the new release, preferably in the same PR. The `update.sh` script does this automatically when invoked with a specific branch, e.g. `./update.sh 6.10`.
9+
New package manager releases are not tracked. We simply use the versions provided by [Corepack](https://github.com/nodejs/corepack).
1210

1311
### Submitting a PR for a version update
1412

Dockerfile-alpine.template

+1-21
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,11 @@ RUN addgroup -g 1000 node \
5757
fi \
5858
&& rm -f "node-v$NODE_VERSION-linux-$ARCH-musl.tar.xz" \
5959
&& apk del .build-deps \
60+
&& corepack enable \
6061
# smoke tests
6162
&& node --version \
6263
&& npm --version
6364

64-
ENV YARN_VERSION 0.0.0
65-
66-
RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
67-
&& for key in \
68-
"${YARN_KEYS[@]}"
69-
; do \
70-
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
71-
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
72-
done \
73-
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
74-
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
75-
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
76-
&& mkdir -p /opt \
77-
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
78-
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
79-
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
80-
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
81-
&& apk del .build-deps-yarn \
82-
# smoke test
83-
&& yarn --version
84-
8565
COPY docker-entrypoint.sh /usr/local/bin/
8666
ENTRYPOINT ["docker-entrypoint.sh"]
8767

Dockerfile-debian.template

+1-20
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,11 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
3030
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
3131
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
3232
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
33+
&& corepack enable \
3334
# smoke tests
3435
&& node --version \
3536
&& npm --version
3637

37-
ENV YARN_VERSION 0.0.0
38-
39-
RUN set -ex \
40-
&& for key in \
41-
"${YARN_KEYS[@]}"
42-
; do \
43-
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
44-
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
45-
done \
46-
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
47-
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
48-
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
49-
&& mkdir -p /opt \
50-
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
51-
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
52-
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
53-
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
54-
# smoke test
55-
&& yarn --version
56-
5738
COPY docker-entrypoint.sh /usr/local/bin/
5839
ENTRYPOINT ["docker-entrypoint.sh"]
5940

Dockerfile-slim.template

+1-33
Original file line numberDiff line numberDiff line change
@@ -41,43 +41,11 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
4141
| xargs -r apt-mark manual \
4242
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
4343
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
44+
&& corepack enable \
4445
# smoke tests
4546
&& node --version \
4647
&& npm --version
4748

48-
ENV YARN_VERSION 0.0.0
49-
50-
RUN set -ex \
51-
&& savedAptMark="$(apt-mark showmanual)" \
52-
&& apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr --no-install-recommends \
53-
&& rm -rf /var/lib/apt/lists/* \
54-
&& for key in \
55-
"${YARN_KEYS[@]}"
56-
; do \
57-
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \
58-
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \
59-
done \
60-
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
61-
&& curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
62-
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
63-
&& mkdir -p /opt \
64-
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
65-
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
66-
&& ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
67-
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
68-
&& apt-mark auto '.*' > /dev/null \
69-
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \
70-
&& find /usr/local -type f -executable -exec ldd '{}' ';' \
71-
| awk '/=>/ { print $(NF-1) }' \
72-
| sort -u \
73-
| xargs -r dpkg-query --search \
74-
| cut -d: -f1 \
75-
| sort -u \
76-
| xargs -r apt-mark manual \
77-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
78-
# smoke test
79-
&& yarn --version
80-
8149
COPY docker-entrypoint.sh /usr/local/bin/
8250
ENTRYPOINT ["docker-entrypoint.sh"]
8351

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,10 @@ $ docker run node npm --loglevel=warn ...
146146
## Image Variants
147147

148148
The `node` images come in many flavors, each designed for a specific use case.
149-
All of the images contain pre-installed versions of `node`,
150-
[`npm`](https://www.npmjs.com/), and [`yarn`](https://yarnpkg.com). For each
151-
supported architecture, the supported variants are different. In the file:
152-
[versions.json](./versions.json), it lists all supported variants for all of
153-
the architectures that we support now.
149+
All of the images contain pre-installed versions of `node`.
150+
For each supported architecture, the supported variants are different.
151+
In the file: [versions.json](./versions.json), it lists all supported variants
152+
for all of the architectures that we support now.
154153

155154
### `node:<version>`
156155

docs/BestPractices.md

+15-44
Original file line numberDiff line numberDiff line change
@@ -27,62 +27,33 @@ Run with `NODE_ENV` set to `production`. This is the way you would pass in secre
2727
-e "NODE_ENV=production"
2828
```
2929

30-
## Global npm dependencies
31-
32-
If you need to install global npm dependencies, it is recommended to place those dependencies in the [non-root user](#non-root-user) directory. To achieve this, add the following line to your `Dockerfile`
30+
## Package Managers
3331

34-
```Dockerfile
35-
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
3632

37-
ENV PATH=$PATH:/home/node/.npm-global/bin # optionally if you want to run npm global bin without specifying path
38-
```
33+
Just use your package managers as you usually would.
34+
They will be automatically installed by [Corepack](https://github.com/nodejs/corepack), which is enabled by default.
3935

40-
## Upgrading/downgrading Yarn
36+
Corepack downloads your package managers the first time you use them.
37+
It honors the [`packageManager` field of your `package.json`](https://nodejs.org/api/packages.html#packagemanager)
38+
if defined.
4139

42-
### Local
43-
44-
If you need to upgrade/downgrade `yarn` for a local install, you can do so by issuing the following commands in your `Dockerfile`:
45-
46-
> Note that if you create some other directory which is not a descendant one from where you ran the command, you will end up using the global (dated) version. If you wish to upgrade `yarn` globally follow the instructions in the next section.
47-
48-
> When following the local install instructions, due to duplicated yarn the image will end up being bigger.
49-
50-
```Dockerfile
51-
FROM node:6
40+
As many production environments don't have network access,
41+
you probably want to bundle your package managers in your Docker image.
5242

53-
ENV YARN_VERSION 1.16.0
43+
To do so, add the following line to your `Dockerfile`:
5444

55-
RUN yarn policies set-version $YARN_VERSION
5645
```
57-
58-
### Global
59-
60-
```Dockerfile
61-
FROM node:6
62-
63-
ENV YARN_VERSION 1.16.0
64-
65-
RUN curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
66-
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
67-
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
68-
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
69-
&& rm yarn-v$YARN_VERSION.tar.gz
46+
RUN corepack prepare
7047
```
7148

72-
If you're using an Alpine-based image, `curl` won't be present, so you'll need to make sure it's installed while using it:
49+
## Global npm dependencies
7350

74-
```Dockerfile
75-
FROM node:6-alpine
51+
If you need to install global npm dependencies, it is recommended to place those dependencies in the [non-root user](#non-root-user) directory. To achieve this, add the following line to your `Dockerfile`:
7652

77-
ENV YARN_VERSION 1.5.1
53+
```Dockerfile
54+
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
7855

79-
RUN apk add --no-cache --virtual .build-deps-yarn curl \
80-
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
81-
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
82-
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
83-
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
84-
&& rm yarn-v$YARN_VERSION.tar.gz \
85-
&& apk del .build-deps-yarn
56+
ENV PATH=$PATH:/home/node/.npm-global/bin # optionally if you want to run npm global bin without specifying path
8657
```
8758

8859
## Handling Kernel Signals

keys/yarn.keys

-1
This file was deleted.

update.sh

+9-26
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ function usage() {
1212
1313
Examples:
1414
- update.sh # Update all images
15-
- update.sh -s # Update all images, skip updating Alpine and Yarn
15+
- update.sh -s # Update all images, skip updating Alpine
1616
- update.sh 8,10 # Update all variants of version 8 and 10
17-
- update.sh -s 8 # Update version 8 and variants, skip updating Alpine and Yarn
17+
- update.sh -s 8 # Update version 8 and variants, skip updating Alpine
1818
- update.sh 8 buster-slim,buster # Update only buster's slim and buster variants for version 8
19-
- update.sh -s 8 stretch # Update only stretch variant for version 8, skip updating Alpine and Yarn
19+
- update.sh -s 8 stretch # Update only stretch variant for version 8, skip updating Alpine
2020
- update.sh . alpine # Update the alpine variant for all versions
2121
2222
OPTIONS:
23-
-s Security update; skip updating the yarn and alpine versions.
23+
-s Security update; skip updating alpine version.
2424
-b CI config update only
2525
-h Show this message
2626
@@ -67,7 +67,6 @@ arch=$(get_arch)
6767

6868
if [ "${SKIP}" != true ]; then
6969
alpine_version=$(get_config "./" "alpine_version")
70-
yarnVersion="$(curl -sSL --compressed https://yarnpkg.com/latest-version)"
7170
fi
7271

7372
function in_versions_to_update() {
@@ -135,21 +134,16 @@ function update_node_version() {
135134
sed -Ei -e 's/^FROM (.*)/FROM '"$fromprefix"'\1/' "${dockerfile}-tmp"
136135
sed -Ei -e 's/^(ENV NODE_VERSION ).*/\1'"${nodeVersion}"'/' "${dockerfile}-tmp"
137136

138-
currentYarnVersion="$(grep "ENV YARN_VERSION" "${dockerfile}" | cut -d' ' -f3)"
139-
sed -Ei -e 's/^(ENV YARN_VERSION ).*/\1'"${currentYarnVersion}"'/' "${dockerfile}-tmp"
140-
141137
# shellcheck disable=SC1004
142138
new_line=' \\\
143139
'
144140

145141
# Add GPG keys
146-
for key_type in "node" "yarn"; do
147-
while read -r line; do
148-
pattern='"\$\{'$(echo "${key_type}" | tr '[:lower:]' '[:upper:]')'_KEYS\[@\]\}"'
149-
sed -Ei -e "s/([ \\t]*)(${pattern})/\\1${line}${new_line}\\1\\2/" "${dockerfile}-tmp"
150-
done < "keys/${key_type}.keys"
151-
sed -Ei -e "/${pattern}/d" "${dockerfile}-tmp"
152-
done
142+
while read -r line; do
143+
pattern='"\$\{'$(echo "node" | tr '[:lower:]' '[:upper:]')'_KEYS\[@\]\}"'
144+
sed -Ei -e "s/([ \\t]*)(${pattern})/\\1${line}${new_line}\\1\\2/" "${dockerfile}-tmp"
145+
done < "keys/node.keys"
146+
sed -Ei -e "/${pattern}/d" "${dockerfile}-tmp"
153147

154148
if is_alpine "${variant}"; then
155149
alpine_version="${variant#*alpine}"
@@ -169,17 +163,6 @@ function update_node_version() {
169163
sed -Ei -e "s/(debian:)name-slim/\\1${variant}/" "${dockerfile}-tmp"
170164
fi
171165

172-
if diff -q "${dockerfile}-tmp" "${dockerfile}" > /dev/null; then
173-
echo "${dockerfile} is already up to date!"
174-
else
175-
if [ "${SKIP}" = true ]; then
176-
# Get the currently used Yarn version
177-
yarnVersion="$(grep "ENV YARN_VERSION" "${dockerfile}" | cut -d' ' -f3)"
178-
fi
179-
sed -Ei -e 's/^(ENV YARN_VERSION ).*/\1'"${yarnVersion}"'/' "${dockerfile}-tmp"
180-
echo "${dockerfile} updated!"
181-
fi
182-
183166
# Required for POSIX sed
184167
if [ -f "${dockerfile}-tmp-e" ]; then
185168
rm "${dockerfile}-tmp-e"

0 commit comments

Comments
 (0)