From 2c2cf42cf95bde3a3ac9f2ea0f12aeebcbbcbe97 Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Wed, 6 Mar 2024 20:30:08 +0000 Subject: [PATCH] build the frontend in Docker --- Dockerfile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Dockerfile b/Dockerfile index a6ad884b..da1f8d5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -176,6 +176,40 @@ RUN --mount=type=cache,id=pixelfed-pear-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${T PHP_PECL_EXTENSIONS_EXTRA=${PHP_PECL_EXTENSIONS_EXTRA} \ /docker/install/php-extensions.sh +####################################################### +# Node: Build frontend +####################################################### + +# NOTE: Since the nodejs build is CPU architecture agnostic, +# we only want to build once and cache it for other architectures. +# We force the (CPU) [--platform] here to be architecture +# of the "builder"/"server" and not the *target* CPU architecture +# (e.g.) building the ARM version of Pixelfed on AMD64. +FROM --platform=${BUILDARCH} node:lts AS frontend-build + +ARG BUILDARCH +ARG RUNTIME_UID + +ARG NODE_ENV=production +ENV NODE_ENV=$NODE_ENV + +WORKDIR /var/www/ + +# Install NPM dependencies +RUN --mount=type=cache,id=pixelfed-node-${BUILDARCH},sharing=locked,target=/tmp/cache \ + --mount=type=bind,source=package.json,target=/var/www/package.json \ + --mount=type=bind,source=package-lock.json,target=/var/www/package-lock.json \ + npm install \ + --cache /tmp/cache \ + --no-save \ + --dev + +# Copy the frontend source into the image before building +COPY --chown=${RUNTIME_UID}:${RUNTIME_GID} . /var/www + +# Build the frontend with "mix" (See package.json) +RUN npm run production + ####################################################### # PHP: composer and source code ####################################################### @@ -231,6 +265,7 @@ COPY --link --from=dottie-image /dottie /usr/local/bin/dottie COPY --link --from=gomplate-image /usr/local/bin/gomplate /usr/local/bin/gomplate COPY --link --from=composer-image /usr/bin/composer /usr/bin/composer COPY --link --from=composer-and-src --chown=${RUNTIME_UID}:${RUNTIME_GID} /var/www /var/www +COPY --link --from=frontend-build --chown=${RUNTIME_UID}:${RUNTIME_GID} /var/www/public /var/www/public #! Changing user to runtime user USER ${RUNTIME_UID}:${RUNTIME_GID}