From 2c2cf42cf95bde3a3ac9f2ea0f12aeebcbbcbe97 Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Wed, 6 Mar 2024 20:30:08 +0000 Subject: [PATCH 1/9] 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/9] 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/9] 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/9] 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/9] 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/9] 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/9] 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:-}" From bf309297d5c09c6e1678b8c74332710c52bb2789 Mon Sep 17 00:00:00 2001 From: Norbert Tretkowski Date: Sat, 13 Apr 2024 22:26:53 +0200 Subject: [PATCH 8/9] `version` is obsolete --- docker-compose.migrate.yml | 2 -- docker-compose.yml | 3 --- 2 files changed, 5 deletions(-) diff --git a/docker-compose.migrate.yml b/docker-compose.migrate.yml index b7048b5b5..d0040b051 100644 --- a/docker-compose.migrate.yml +++ b/docker-compose.migrate.yml @@ -1,6 +1,4 @@ --- -version: "3" - services: migrate: image: "servercontainers/rsync" diff --git a/docker-compose.yml b/docker-compose.yml index 767a509b2..3ba3afd34 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,4 @@ --- -# Require 3.8 to ensure people use a recent version of Docker + Compose -version: "3.8" - ############################################################### # Please see docker/README.md for usage information ############################################################### From 3ce5ae21bfc596570fa67922d7a9d990a2051eea Mon Sep 17 00:00:00 2001 From: Norbert Tretkowski Date: Sat, 13 Apr 2024 22:55:21 +0200 Subject: [PATCH 9/9] Fix typo in .env.docker comment --- .env.docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.docker b/.env.docker index e1143f5e7..a15e15431 100644 --- a/.env.docker +++ b/.env.docker @@ -1034,7 +1034,7 @@ DOCKER_APP_HOST_CACHE_PATH="${DOCKER_ALL_HOST_DATA_ROOT_PATH:?error}/pixelfed/ca # Automatically run "One-time setup tasks" commands. # -# If you are migrating to this docker-compose setup or have manually run the "One time seutp" +# If you are migrating to this docker-compose setup or have manually run the "One time setup" # tasks (https://docs.pixelfed.org/running-pixelfed/installation/#setting-up-services) # you can set this to "0" to prevent them from running. #