Skip to content

Commit 305a02c

Browse files
authored
Merge pull request #1974 from PathToLife/feature/docker-multiplatform-build
Docker multiplatform build support
2 parents 5a3b7bc + a42c7de commit 305a02c

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

.github/workflows/releases.yml

+14-10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525

2626
- name: Install
2727
run: |
28+
export DETECT_CHROMEDRIVER_VERSION=true
2829
npm ci
2930
npm run setheapsize
3031
@@ -61,12 +62,22 @@ jobs:
6162
tags: ${{ steps.image-metadata.outputs.tags }}
6263
labels: ${{ steps.image-metadata.outputs.labels }}
6364
containerfiles: ./Dockerfile
64-
platforms: linux/amd64
65+
platforms: linux/amd64,linux/arm64
6566
oci: true
67+
# enable build layer caching between platforms
68+
layers: true
6669
# Webpack seems to use a lot of open files, increase the max open file limit to accomodate.
6770
extra-args: |
6871
--ulimit nofile=10000
6972
73+
- name: Publish to GHCR
74+
uses: redhat-actions/push-to-registry@v2
75+
with:
76+
image: ${{ steps.build-image.outputs.image }}
77+
tags: ${{ steps.build-image.outputs.tags }}
78+
registry: ${{ env.REGISTRY }}
79+
username: ${{ env.REGISTRY_USER }}
80+
password: ${{ env.REGISTRY_PASSWORD }}
7081

7182
- name: Upload Release Assets
7283
id: upload-release-assets
@@ -81,13 +92,6 @@ jobs:
8192

8293
- name: Publish to NPM
8394
uses: JS-DevTools/npm-publish@v1
95+
if: false
8496
with:
85-
token: ${{ secrets.NPM_TOKEN }}
86-
87-
- name: Publish to GHCR
88-
uses: redhat-actions/push-to-registry@v2
89-
with:
90-
tags: ${{ steps.build-image.outputs.tags }}
91-
registry: ${{ env.REGISTRY }}
92-
username: ${{ env.REGISTRY_USER }}
93-
password: ${{ env.REGISTRY_PASSWORD }}
97+
token: ${{ secrets.NPM_TOKEN }}

Dockerfile

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
1-
FROM node:18-alpine AS build
1+
#####################################
2+
# Build the app to a static website #
3+
#####################################
4+
# Modifier --platform=$BUILDPLATFORM limits the platform to "BUILDPLATFORM" during buildx multi-platform builds
5+
# This is because npm "chromedriver" package is not compatiable with all platforms
6+
# For more info see: https://docs.docker.com/build/building/multi-platform/#cross-compilation
7+
FROM --platform=$BUILDPLATFORM node:18-alpine AS builder
28

9+
WORKDIR /app
10+
11+
COPY package.json .
12+
COPY package-lock.json .
13+
14+
# Install dependencies
15+
# --ignore-scripts prevents postinstall script (which runs grunt) as it depends on files other than package.json
16+
RUN npm ci --ignore-scripts
17+
18+
# Copy files needed for postinstall and build
319
COPY . .
4-
RUN npm ci
20+
21+
# npm postinstall runs grunt, which depends on files other than package.json
22+
RUN npm run postinstall
23+
24+
# Build the app
525
RUN npm run build
626

7-
FROM nginx:1.25-alpine3.18 AS cyberchef
27+
#########################################
28+
# Package static build files into nginx #
29+
#########################################
30+
# We are using Github Actions: redhat-actions/buildah-build@v2 which needs manual selection of arch in base image
31+
# Remove TARGETARCH if docker buildx is supported in the CI release as --platform=$TARGETPLATFORM will be automatically set
32+
ARG TARGETARCH
33+
ARG TARGETPLATFORM
34+
FROM ${TARGETARCH}/nginx:stable-alpine AS cyberchef
835

9-
COPY --from=build ./build/prod /usr/share/nginx/html/
36+
COPY --from=builder /app/build/prod /usr/share/nginx/html/

0 commit comments

Comments
 (0)