Skip to content

Commit e13247e

Browse files
authored
build: use static node binary on docker images (#30324)
1 parent c219c8f commit e13247e

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

renovate.json

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
"matchDepNames": ["ghcr.io/renovatebot/base-image"],
4040
"matchUpdateTypes": ["major", "minor"],
4141
"semanticCommitType": "feat"
42+
},
43+
{
44+
"description": "set build scope for node updates",
45+
"matchPackageNames": ["node"],
46+
"matchFileNames": [".nvmrc", "tools/docker/Dockerfile"],
47+
"semanticCommitType": "build"
48+
},
49+
{
50+
"description": "set branch prefix for node major updates to split from minor updates",
51+
"matchPackageNames": ["node"],
52+
"matchUpdateTypes": ["major"],
53+
"additionalBranchPrefix": "major"
4254
}
4355
],
4456
"customManagers": [

tools/docker/Dockerfile

+21-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ FROM ghcr.io/renovatebot/base-image:2.28.0-full@sha256:0e3a859452ece1442faa693c7
1515
# --------------------------------------
1616
FROM --platform=$BUILDPLATFORM ghcr.io/renovatebot/base-image:2.28.0@sha256:0abd37cc5818199aad69b226537fade5047bae1ca1a987f855453d9eed19a795 AS build
1717

18+
# We want a specific node version here
19+
# renovate: datasource=node-version
20+
RUN install-tool node 20.15.1
21+
22+
WORKDIR /usr/local/renovate
23+
1824
ARG TARGETPLATFORM
1925
ARG BUILDPLATFORM
2026

@@ -23,11 +29,21 @@ RUN set -ex; \
2329
uname -a; \
2430
true
2531

26-
WORKDIR /usr/local/renovate
32+
# fetch static node binary
33+
# trim `linux/` from TARGETPLATFORM
34+
# replace `amd64` with `x64` for `node`
35+
RUN set -ex; \
36+
ver=$(node --version); \
37+
arch=${TARGETPLATFORM:6}; \
38+
temp_dir="$(mktemp -d)"; \
39+
curl -fsSL https://nodejs.org/dist/${ver}/node-${ver}-linux-${arch/amd64/x64}.tar.xz -o ${temp_dir}/node.tar.xz; \
40+
bsdtar --strip 1 -C ${temp_dir} -xf ${temp_dir}/node.tar.xz; \
41+
cp ${temp_dir}/bin/node ./node; \
42+
true
2743

44+
# fetch npm packages
2845
ENV CI=1 npm_config_modules_cache_max_age=0 \
29-
npm_config_loglevel=info \
30-
ARCH=arm64
46+
npm_config_loglevel=info
3147

3248
COPY pnpm-lock.yaml ./
3349

@@ -44,20 +60,11 @@ RUN set -ex; \
4460

4561
COPY . ./
4662

47-
# install
63+
# install npm packages
4864
RUN set -ex; \
4965
corepack pnpm install --prod --offline --ignore-scripts; \
5066
true
5167

52-
# test
53-
COPY tools/docker/bin/ /usr/local/bin/
54-
# RE2 doesn't work on cross compile
55-
ENV RENOVATE_X_IGNORE_RE2=true
56-
RUN set -ex; \
57-
renovate --version; \
58-
renovate-config-validator; \
59-
true
60-
6168
# --------------------------------------
6269
# final image
6370
# --------------------------------------
@@ -87,7 +94,7 @@ RUN set -ex; \
8794

8895
RUN set -ex; \
8996
renovate --version; \
90-
node -e "new require('re2')('.*').exec('test');new require('better-sqlite3')(':memory:')"; \
97+
/usr/local/renovate/node -e "new require('re2')('.*').exec('test');new require('better-sqlite3')(':memory:')"; \
9198
true
9299

93100
LABEL \

tools/docker/bin/renovate

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ if [[ -f "/usr/local/etc/env" && -z "${CONTAINERBASE_ENV+x}" ]]; then
55
. /usr/local/etc/env
66
fi
77

8-
node "${RENOVATE_NODE_ARGS[@]}" /usr/local/renovate/dist/renovate.js "$@"
8+
/usr/local/renovate/node "${RENOVATE_NODE_ARGS[@]}" /usr/local/renovate/dist/renovate.js "$@"

tools/docker/bin/renovate-config-validator

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ if [[ -f "/usr/local/etc/env" && -z "${CONTAINERBASE_ENV+x}" ]]; then
55
. /usr/local/etc/env
66
fi
77

8-
node /usr/local/renovate/dist/config-validator.js "$@"
8+
/usr/local/renovate/node /usr/local/renovate/dist/config-validator.js "$@"

0 commit comments

Comments
 (0)