Skip to content
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

build(docker): use cross platform builds #29983

Merged
merged 13 commits into from
Jul 4, 2024
30 changes: 24 additions & 6 deletions tools/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,34 @@ FROM ghcr.io/renovatebot/base-image:2.24.0-full@sha256:323eb53c3a1706e6bf87d4e8e
# --------------------------------------
# build image
# --------------------------------------
FROM slim-base as build
FROM --platform=$BUILDPLATFORM ghcr.io/renovatebot/base-image:2.24.0@sha256:f659e0c7589ef608805887ab0d668f67c4b5d5ce0612e62538b17322a92f928d AS build

ARG TARGETPLATFORM
ARG BUILDPLATFORM

RUN set -ex; \
echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM"; \
uname -a; \
true

WORKDIR /usr/local/renovate

ENV CI=1 npm_config_modules_cache_max_age=0
ENV CI=1 npm_config_modules_cache_max_age=0 \
npm_config_loglevel=info \
ARCH=arm64

COPY pnpm-lock.yaml ./

# trim `linux/` from TARGETPLATFORM
# replace `amd64` with `x64` for `node`
# set `npm_config_arch` for `prebuild-install`
# set `npm_config_platform_arch` for `install-artifact-from-github`
# only fetch deps from lockfile https://pnpm.io/cli/fetch
RUN corepack pnpm fetch --prod
RUN set -ex; \
arch=${TARGETPLATFORM:6}; \
export npm_config_arch=${arch/amd64/x64} npm_config_platform_arch=${arch/amd64/x64}; \
corepack pnpm fetch --prod; \
true

COPY . ./

Expand All @@ -33,10 +51,11 @@ RUN set -ex; \

# test
COPY tools/docker/bin/ /usr/local/bin/
# RE2 doesn't work on cross compile
ENV RENOVATE_X_IGNORE_RE2=true
RUN set -ex; \
renovate --version; \
renovate-config-validator; \
node -e "new require('re2')('.*').exec('test')"; \
true

# --------------------------------------
Expand Down Expand Up @@ -68,8 +87,7 @@ RUN set -ex; \

RUN set -ex; \
renovate --version; \
renovate-config-validator; \
node -e "new require('re2')('.*').exec('test')"; \
node -e "new require('re2')('.*').exec('test');new require('better-sqlite3')(':memory:')"; \
true

LABEL \
Expand Down