From 98e160e17c4d7c3196d07fbe0cfe3f49a6e80db5 Mon Sep 17 00:00:00 2001 From: Tom O'Dwyer Date: Thu, 1 Aug 2024 13:47:18 +0100 Subject: [PATCH] Configure Actions and Docker to build Node assets --- .github/workflows/main.yml | 14 ++++++++++++++ docker/Dockerfile | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d9d002de..1dd7bd19 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,6 +33,20 @@ jobs: with: python-version: "3.11" install-just: true + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version-file: ".node-version" + cache: "npm" + cache-dependency-path: package-lock.json + + - name: Install node_modules + run: npm ci + + - name: Build assets + run: npm run build + - name: Set up development environment run: just devenv diff --git a/docker/Dockerfile b/docker/Dockerfile index 2f23f2b7..f0ab4dd4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,6 @@ # syntax=docker/dockerfile:1.2 +ARG NODE_VERSION=20 + ################################################# # # Create base image with python installed. @@ -26,6 +28,28 @@ RUN --mount=type=cache,target=/var/cache/apt \ /root/docker-apt-install.sh /tmp/dependencies.txt +################################################# +# +# Create node image. +# +FROM node:${NODE_VERSION} AS node-builder + +WORKDIR /usr/src/app + +# copy just what npm ci needs +COPY package-lock.json package.json ./ +RUN --mount=type=cache,target=/usr/src/app/.npm \ + npm set cache /usr/src/app/.npm && \ + npm ci + +# just copy in the files `npm run build` needs +COPY vite.config.js tailwind.config.js postcss.config.js ./ +COPY airlock/templates ./airlock/templates +COPY assets/templates ./assets/templates +COPY assets/src ./assets/src + +RUN --mount=type=cache,target=./npm npm run build + ################################################## # # Build image @@ -83,6 +107,10 @@ WORKDIR /app # are readable by all. COPY --from=builder /opt/venv /opt/venv +# copy node assets over from node-builder image. These will have root:root ownership, but +# are readable by all. +COPY --from=node-builder /usr/src/app/assets/out /opt/assets + # Asset and staticfile management # # We support two dev environment side-by-side. Docker-based, which is the same