Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**
!Dockerfile
!patches/
!patches/*.patch
51 changes: 51 additions & 0 deletions .github/scripts/npm-archive-smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh
set -eu

workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
export npm_config_cache="$workdir/npm-cache"
cd "$workdir"

mkdir package modified consumer
printf '%s\n' '{"name":"npm-archive-smoke","version":"1.0.0","main":"index.js","bin":"index.js"}' > package/package.json
printf '%s\n' '#!/usr/bin/env node' 'module.exports = "archive smoke";' > package/index.js
npm pack --offline --ignore-scripts --pack-destination "$workdir" ./package
archive="$workdir/npm-archive-smoke-1.0.0.tgz"

printf '%s\n' '{"name":"npm-archive-consumer","version":"1.0.0","private":true}' > consumer/package.json
npm install --prefix consumer --offline --ignore-scripts --no-audit --no-fund "$archive"
node -e 'if (require("./consumer/node_modules/npm-archive-smoke") !== "archive smoke") process.exit(1)'
test -x consumer/node_modules/npm-archive-smoke/index.js

cp package/package.json modified/package.json
printf '%s\n' '#!/usr/bin/env node' 'module.exports = "second archive";' > modified/index.js
npm pack --offline --ignore-scripts --pack-destination "$workdir/modified" ./modified
npm diff --offline --ignore-scripts --diff-name-only \
--diff="file:$archive" --diff="file:$workdir/modified/$(basename "$archive")" > diff.txt
grep -Fx index.js diff.txt

npm_cli=$(readlink -f "$(command -v npm)")
npm_dir=$(dirname "$(dirname "$npm_cli")")
npm ls --prefix "$npm_dir" tar --all
# npm 10 resolves a separate pacote bundle from its audit calculator.
node --input-type=module - "$npm_dir" "$archive" <<'JS'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import { resolve } from 'node:path'

const [npmDir, archivePath] = process.argv.slice(2)
const calculatorRequire = createRequire(`${npmDir}/node_modules/@npmcli/metavuln-calculator/package.json`)
const pacote = calculatorRequire('pacote')
const destination = resolve('calculator-pacote')
await pacote.extract(`file:${archivePath}`, destination, { cache: process.env.npm_config_cache })
assert.match(await readFile(`${destination}/index.js`, 'utf8'), /archive smoke/)
JS
node_version=$(node -p 'process.versions.node')
header="node-v$node_version/include/node/node.h"
mkdir -p "headers/$(dirname "$header")"
printf '%s\n' '#define BEEVELOP_NPM_ARCHIVE_SMOKE 1' > "headers/$header"
tar -C headers -czf node-headers-smoke.tgz "node-v$node_version"
node "$npm_dir/node_modules/node-gyp/bin/node-gyp.js" install "$node_version" \
--devdir="$workdir/gyp-cache" --tarball="$workdir/node-headers-smoke.tgz"
grep -Fx '#define BEEVELOP_NPM_ARCHIVE_SMOKE 1' "gyp-cache/$node_version/include/node/node.h"
4 changes: 4 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ jobs:
virtualenv --no-download /tmp/virtualenv
/tmp/virtualenv/bin/python -m pip --version
SH
- name: Smoke-test npm package archives
env:
PLATFORM: ${{ matrix.platform }}
run: docker run --rm --network none --platform "$PLATFORM" -i nodejs-python:smoke sh < .github/scripts/npm-archive-smoke.sh

publish:
needs: validate
Expand Down
34 changes: 30 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,51 @@ FROM node-24 AS node-arm64
FROM node:22.23.5-bookworm-slim@sha256:be979e5523c76fa4d5ca4ebd3099078f220aa47ec39c48ad5b5df9314debd6eb AS node-arm

FROM node-${TARGETARCH} AS runtime
ARG TARGETARCH

LABEL org.opencontainers.image.title="Beevelop Node.js and Python" \
org.opencontainers.image.description="Node.js, npm, Yarn Classic, and Debian Python tooling" \
org.opencontainers.image.source="https://github.com/beevelop/docker-nodejs-python" \
org.opencontainers.image.licenses="MIT"

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# Keep these version-specific ports until the official Node images bundle npm with tar 8.
RUN --mount=type=bind,source=patches,target=/tmp/npm-patches \
set -eu; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gnupg \
lsb-release \
patch \
python-is-python3 \
python3 \
python3-dev \
python3-pip \
python3-venv \
python3-virtualenv \
&& rm -rf /var/lib/apt/lists/*
python3-virtualenv; \
case "$TARGETARCH" in \
amd64|arm64) npm_version=11.21.3 ;; \
arm) npm_version=10.9.9 ;; \
*) echo "Unsupported npm archive patch architecture: $TARGETARCH" >&2; exit 1 ;; \
esac; \
npm_dir=/usr/local/lib/node_modules/npm; \
npm_tar_dir="$npm_dir/node_modules/tar"; \
test "$(npm --version)" = "$npm_version"; \
test "$(node -p "require('$npm_tar_dir/package.json').version")" = 7.5.22; \
tmp_dir=$(mktemp -d); \
trap 'rm -rf "$tmp_dir"' EXIT; \
curl --fail --silent --show-error --location --retry 4 \
https://registry.npmjs.org/tar/-/tar-8.1.2.tgz \
--output "$tmp_dir/npm-tar.tgz"; \
printf '%s %s\n' cb37600ca3ea445944601b532553fdd614f6cf24f069d4730002e519c7261a1358b9c576889c928502d3752021fd863d79f2e68cd8e492db2f03085583a4a27f "$tmp_dir/npm-tar.tgz" \
| sha512sum --check --strict; \
patch --batch --forward --fuzz=0 -p1 -d "$npm_dir" < "/tmp/npm-patches/npm-$npm_version-tar-8.patch"; \
rm -rf "$npm_tar_dir"; \
mkdir "$npm_tar_dir"; \
tar -xzf "$tmp_dir/npm-tar.tgz" -C "$npm_tar_dir" --strip-components=1 --no-same-owner; \
apt-get purge -y patch; \
rm -rf /var/lib/apt/lists/*

ENV TERM=xterm

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Use Node.js, npm, Yarn Classic, and Python in the same build environment. The im

The 32-bit ARM build uses the maintained Node.js 22 Docker Official Image. Node.js 22 is scheduled to reach end of life on April 30, 2027. Plan to move ARM builds to `linux/arm64` before then. [Node.js image platforms](https://github.com/nodejs/docker-node/blob/main/versions.json) · [Node.js release schedule](https://github.com/nodejs/Release/blob/main/schedule.json)

The image keeps npm 11.21.3 on Node.js 24 and npm 10.9.9 on Node.js 22. Both bundles use the SHA-512-verified tar 8.1.2 package and version-specific archive API patches. The patches can be removed separately when the official images for each Node.js line include npm with tar 8 support. [Upstream tar advisory](https://github.com/advisories/GHSA-7c32-79xj-j3jp)

## Use the image

```sh
Expand All @@ -33,9 +35,10 @@ From the cloned repository:
```sh
docker buildx build --load -t nodejs-python:local .
docker run --rm nodejs-python:local bash -ec 'node --version; npm --version; yarn --version; python --version; python -m venv /tmp/venv; /tmp/venv/bin/python -m pip --version'
docker run --rm --network none -i nodejs-python:local sh < .github/scripts/npm-archive-smoke.sh
```

Set `--platform linux/arm/v7` on both commands to verify the 32-bit ARM image on a machine configured for that architecture or emulation.
Set `--platform linux/arm/v7` on the build and run commands to verify the 32-bit ARM image on a machine configured for that architecture or emulation.

## Publishing

Expand Down
Loading