mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
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
This commit is contained in:
5
.github/workflows/docker.yml
vendored
5
.github/workflows/docker.yml
vendored
@@ -30,7 +30,7 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
@@ -54,3 +54,6 @@ jobs:
|
|||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
20
Dockerfile
20
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
|
FROM node:lts
|
||||||
|
|
||||||
RUN mkdir -p /usr/src/app && \
|
RUN mkdir -p /usr/src/app && \
|
||||||
@@ -7,11 +23,11 @@ WORKDIR /usr/src/app
|
|||||||
ARG NODE_ENV
|
ARG NODE_ENV
|
||||||
ENV NODE_ENV $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
|
USER node
|
||||||
|
|
||||||
RUN npm install --only=prod && \
|
RUN npm rebuild && \
|
||||||
npm cache clean --force
|
npm cache clean --force
|
||||||
|
|
||||||
COPY --chown=node:node . /usr/src/app
|
COPY --chown=node:node . /usr/src/app
|
||||||
|
|||||||
Reference in New Issue
Block a user