From 0417e5f16cf52a4f1e6081a1a9f1c5619108a592 Mon Sep 17 00:00:00 2001 From: Opliko Date: Fri, 28 Apr 2023 19:00:34 +0200 Subject: [PATCH] ci: multi-platform docker image (#11479) * ci: multi-platform build * ci: remove riscv as node doesn't support it * ci: correct step name it's no longer logging in to docker hub * ci: remove less common architectures * ci: github actions cache for docker builds * fix: use `--omit` flag to actually avoid installing dev dependencies * feat: two-stage build * feat: add platform-specific rebuild * fix: run install if target arch is different from build arch * fix: whitespace * fix: correct build order * fix: remove unnecessary conditional * fix: remove unnecessary platofm specifier * fix: correct copy --- .github/workflows/docker.yml | 5 ++++- Dockerfile | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 476c80778f..b2fb2070c7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,7 +30,7 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Login to Docker Hub + - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: registry: ghcr.io @@ -54,3 +54,6 @@ jobs: file: ./Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8a5b7ae9bb..d7277a3389 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,19 @@ +FROM --platform=$BUILDPLATFORM node:lts as npm + +RUN mkdir -p /usr/src/build && \ + chown -R node:node /usr/src/build +WORKDIR /usr/src/build + +ARG NODE_ENV +ENV NODE_ENV $NODE_ENV + +COPY --chown=node:node install/package.json /usr/src/build/package.json + +USER node + +RUN npm install --omit=dev + + FROM node:lts RUN mkdir -p /usr/src/app && \ @@ -7,11 +23,11 @@ WORKDIR /usr/src/app ARG NODE_ENV ENV NODE_ENV $NODE_ENV -COPY --chown=node:node install/package.json /usr/src/app/package.json +COPY --chown=node:node --from=npm /usr/src/build /usr/src/app USER node -RUN npm install --only=prod && \ +RUN npm rebuild && \ npm cache clean --force COPY --chown=node:node . /usr/src/app