diff --git a/.env.docker b/.env.docker index 8367c003..0e373aed 100644 --- a/.env.docker +++ b/.env.docker @@ -1131,6 +1131,13 @@ DOCKER_APP_HOST_CACHE_PATH="${DOCKER_ALL_HOST_DATA_ROOT_PATH:?error}/pixelfed/ca # @dottie/validate required,oneof=0 1 2 #DOCKER_APP_PHP_OPCACHE_REVALIDATE_FREQ="2" +# When doing [docker compose build], should the frontend be built in the Dockerfile? +# If set to "0" the included pre-compiled frontend will be used. +# +# @default "0" +# @dottie/validate required,oneof=0 1 +#DOCKER_APP_BUILD_FRONTEND="0" + ################################################################################ # docker redis ################################################################################ diff --git a/.hadolint.yaml b/.hadolint.yaml index cbb62ca4..27fa2ff2 100644 --- a/.hadolint.yaml +++ b/.hadolint.yaml @@ -1,5 +1,6 @@ ignored: - DL3002 # warning: Last USER should not be root - DL3008 # warning: Pin versions in apt get install. Instead of `apt-get install ` use `apt-get install =` + - DL3029 # warning: Do not use --platform flag with FROM - SC2046 # warning: Quote this to prevent word splitting. - SC2086 # info: Double quote to prevent globbing and word splitting. diff --git a/Dockerfile b/Dockerfile index a3317c11..a0eda322 100644 --- a/Dockerfile +++ b/Dockerfile @@ -176,6 +176,55 @@ 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 BUILD_FRONTEND=0 +ARG RUNTIME_UID + +ARG NODE_ENV=production +ENV NODE_ENV=$NODE_ENV + +WORKDIR /var/www/ + +SHELL [ "/usr/bin/bash", "-c" ] + +# 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 \ +<