From f8b613b4e7cbb8ba8190711b8312bd3077300a2e Mon Sep 17 00:00:00 2001 From: PathToLife <12622625+PathToLife@users.noreply.github.com> Date: Thu, 13 Feb 2025 20:57:45 +1300 Subject: [PATCH 1/4] Docker multiplatform build support. Pending CI workflow test --- .github/workflows/releases.yml | 2 +- Dockerfile | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index a068ffbb..586dba7b 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -61,7 +61,7 @@ jobs: tags: ${{ steps.image-metadata.outputs.tags }} labels: ${{ steps.image-metadata.outputs.labels }} containerfiles: ./Dockerfile - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64,linux/arm/v7 oci: true # Webpack seems to use a lot of open files, increase the max open file limit to accomodate. extra-args: | diff --git a/Dockerfile b/Dockerfile index be4c8bad..09350891 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,30 @@ -FROM node:18-alpine AS build +##################################### +# Build the app to a static website # +##################################### +# Modifier --platform=$BUILDPLATFORM limits the platform to "BUILDPLATFORM" during buildx multi-platform builds +# This is because npm "chromedriver" package is not compatiable with all platforms +# For more info see: https://docs.docker.com/build/building/multi-platform/#cross-compilation +FROM --platform=$BUILDPLATFORM node:18-alpine AS builder +WORKDIR /app + +COPY package.json . +COPY package-lock.json . + +# Install dependencies +# --ignore-scripts do not run grunt postinstall script as it depends on files other than package.json +RUN npm ci --ignore-scripts + +# Build the app COPY . . -RUN npm ci + +# npm postinstall runs grunt, which depends on files other than package.json +RUN npm run postinstall RUN npm run build -FROM nginx:1.25-alpine3.18 AS cyberchef +######################################### +# Package static build files into nginx # +######################################### +FROM nginx:stable-alpine AS cyberchef -COPY --from=build ./build/prod /usr/share/nginx/html/ +COPY --from=builder /app/build/prod /usr/share/nginx/html/ From 3b75e13287249a347d24fd821fe2dfb5a6b44aae Mon Sep 17 00:00:00 2001 From: PathToLife <12622625+PathToLife@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:46:34 +1300 Subject: [PATCH 2/4] ci release error fix, apply detect chrome driver version npm install env var --- .github/workflows/releases.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 586dba7b..8bfb8e2d 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -25,6 +25,7 @@ jobs: - name: Install run: | + export DETECT_CHROMEDRIVER_VERSION=true npm ci npm run setheapsize From b85036b78ffee2ab8cc036480d469156af1e998f Mon Sep 17 00:00:00 2001 From: PathToLife <12622625+PathToLife@users.noreply.github.com> Date: Mon, 10 Mar 2025 17:28:20 +1300 Subject: [PATCH 3/4] Dockerfile manual architecture selection for multiplatform build. Disable NPM Publish for testing --- .github/workflows/releases.yml | 23 +++++++++++++---------- Dockerfile | 11 ++++++++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 8bfb8e2d..e6db697b 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -62,12 +62,22 @@ jobs: tags: ${{ steps.image-metadata.outputs.tags }} labels: ${{ steps.image-metadata.outputs.labels }} containerfiles: ./Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm/v7 + archs: amd64,arm64v8,arm32v7 oci: true + # enable build layer caching between platforms + layers: true # Webpack seems to use a lot of open files, increase the max open file limit to accomodate. extra-args: | --ulimit nofile=10000 + - name: Publish to GHCR + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY_USER }} + password: ${{ env.REGISTRY_PASSWORD }} - name: Upload Release Assets id: upload-release-assets @@ -82,13 +92,6 @@ jobs: - name: Publish to NPM uses: JS-DevTools/npm-publish@v1 + if: false with: - token: ${{ secrets.NPM_TOKEN }} - - - name: Publish to GHCR - uses: redhat-actions/push-to-registry@v2 - with: - tags: ${{ steps.build-image.outputs.tags }} - registry: ${{ env.REGISTRY }} - username: ${{ env.REGISTRY_USER }} - password: ${{ env.REGISTRY_PASSWORD }} + token: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 09350891..05f85ceb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,19 +12,24 @@ COPY package.json . COPY package-lock.json . # Install dependencies -# --ignore-scripts do not run grunt postinstall script as it depends on files other than package.json +# --ignore-scripts prevents postinstall script (which runs grunt) as it depends on files other than package.json RUN npm ci --ignore-scripts -# Build the app +# Copy files needed for postinstall and build COPY . . # npm postinstall runs grunt, which depends on files other than package.json RUN npm run postinstall + +# Build the app RUN npm run build ######################################### # Package static build files into nginx # ######################################### -FROM nginx:stable-alpine AS cyberchef +# We are using Github Actions: redhat-actions/buildah-build@v2 which needs manual selection of arch in base image +# Remove TARGETARCH if docker buildx is supported in the CI release as --platform=$TARGETPLATFORM will be automatically set +ARG TARGETARCH +FROM ${TARGETARCH}/nginx:stable-alpine AS cyberchef COPY --from=builder /app/build/prod /usr/share/nginx/html/ From a42c7de112091475fab88ec8b64370ef9697c702 Mon Sep 17 00:00:00 2001 From: PathToLife <12622625+PathToLife@users.noreply.github.com> Date: Mon, 10 Mar 2025 18:00:49 +1300 Subject: [PATCH 4/4] test buildah platforms flag environment variables --- .github/workflows/releases.yml | 2 +- Dockerfile | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index e6db697b..20968772 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -62,7 +62,7 @@ jobs: tags: ${{ steps.image-metadata.outputs.tags }} labels: ${{ steps.image-metadata.outputs.labels }} containerfiles: ./Dockerfile - archs: amd64,arm64v8,arm32v7 + platforms: linux/amd64,linux/arm64 oci: true # enable build layer caching between platforms layers: true diff --git a/Dockerfile b/Dockerfile index 05f85ceb..d63a8ca3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,7 @@ RUN npm run build # We are using Github Actions: redhat-actions/buildah-build@v2 which needs manual selection of arch in base image # Remove TARGETARCH if docker buildx is supported in the CI release as --platform=$TARGETPLATFORM will be automatically set ARG TARGETARCH +ARG TARGETPLATFORM FROM ${TARGETARCH}/nginx:stable-alpine AS cyberchef COPY --from=builder /app/build/prod /usr/share/nginx/html/