From 2c2cf42cf95bde3a3ac9f2ea0f12aeebcbbcbe97 Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Wed, 6 Mar 2024 20:30:08 +0000 Subject: [PATCH 1/7] build the frontend in Docker --- Dockerfile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Dockerfile b/Dockerfile index a6ad884b8..da1f8d5ee 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} From 8a35eb0b7ec7a7fa84e2c1c26729c4bba406b5f6 Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Wed, 6 Mar 2024 21:14:03 +0000 Subject: [PATCH 2/7] ignore hadolint rule DL3029 --- .hadolint.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.hadolint.yaml b/.hadolint.yaml index cbb62ca47..27fa2ff27 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. From d5470101f40d604ea21b14a21bcf246b42669aec Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Wed, 6 Mar 2024 21:25:02 +0000 Subject: [PATCH 3/7] don't build the frontend by default in Docker --- .env.docker | 7 +++++++ Dockerfile | 23 ++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.env.docker b/.env.docker index 0d5836745..e90ac1c03 100644 --- a/.env.docker +++ b/.env.docker @@ -1122,6 +1122,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/Dockerfile b/Dockerfile index da1f8d5ee..599e450b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -188,6 +188,7 @@ RUN --mount=type=cache,id=pixelfed-pear-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${T FROM --platform=${BUILDARCH} node:lts AS frontend-build ARG BUILDARCH +ARG BUILD_FRONTEND=0 ARG RUNTIME_UID ARG NODE_ENV=production @@ -199,16 +200,28 @@ WORKDIR /var/www/ 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 + < Date: Wed, 6 Mar 2024 21:25:31 +0000 Subject: [PATCH 4/7] remove jippi-fork from GitHub actions --- .github/workflows/docker.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0f62ad3bc..8fdea53a1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -10,7 +10,6 @@ on: branches: - dev - staging - - jippi-fork tags: - "*" From 9d9a4cbe2050bc09b07d9e77a980e0033871189a Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Wed, 6 Mar 2024 21:33:07 +0000 Subject: [PATCH 5/7] fix hadolint? --- Dockerfile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 599e450b6..eecd92422 100644 --- a/Dockerfile +++ b/Dockerfile @@ -196,16 +196,16 @@ ENV NODE_ENV=$NODE_ENV WORKDIR /var/www/ +SHELL [ "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 \ - < Date: Wed, 6 Mar 2024 21:34:15 +0000 Subject: [PATCH 6/7] fix hadolint? --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index eecd92422..849eccea2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -196,7 +196,7 @@ ENV NODE_ENV=$NODE_ENV WORKDIR /var/www/ -SHELL [ "bash", "-c" ] +SHELL [ "/usr/bin/bash", "-c" ] # Install NPM dependencies RUN --mount=type=cache,id=pixelfed-node-${BUILDARCH},sharing=locked,target=/tmp/cache \ From f428025db951849fd36408fbd899772ea697174a Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Wed, 6 Mar 2024 21:40:38 +0000 Subject: [PATCH 7/7] add docker-compose build setting for BUILD_FRONTEND --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 5df433c83..7101192f5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -80,6 +80,7 @@ services: - "type=registry,ref=${DOCKER_APP_IMAGE}-cache:${DOCKER_APP_TAG}" args: APT_PACKAGES_EXTRA: "${DOCKER_APP_APT_PACKAGES_EXTRA:-}" + BUILD_FRONTEND: "${DOCKER_APP_BUILD_FRONTEND:-0}" PHP_BASE_TYPE: "${DOCKER_APP_BASE_TYPE}" PHP_DEBIAN_RELEASE: "${DOCKER_APP_DEBIAN_RELEASE}" PHP_EXTENSIONS_EXTRA: "${DOCKER_APP_PHP_EXTENSIONS_EXTRA:-}" @@ -131,6 +132,7 @@ services: - "type=registry,ref=${DOCKER_APP_IMAGE}-cache:${DOCKER_APP_TAG}" args: APT_PACKAGES_EXTRA: "${DOCKER_APP_APT_PACKAGES_EXTRA:-}" + BUILD_FRONTEND: "${DOCKER_APP_BUILD_FRONTEND:-0}" PHP_BASE_TYPE: "${DOCKER_APP_BASE_TYPE}" PHP_DEBIAN_RELEASE: "${DOCKER_APP_DEBIAN_RELEASE}" PHP_EXTENSIONS_EXTRA: "${DOCKER_APP_PHP_EXTENSIONS_EXTRA:-}"