From a044db23c5032ae594ff579a2aa3cbc13cdbf9d9 Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Thu, 4 Jul 2024 12:30:46 +0200 Subject: [PATCH] build(docker): use cross platform builds (#29983) --- tools/docker/Dockerfile | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 2ff2a4965c..42bb4c1fb3 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -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 . ./ @@ -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 # -------------------------------------- @@ -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 \ -- GitLab