Few small fixes for the Website service (#23)
This PR contains the work done to address small fixes. To provide further details: * HTML template * Removed the duplicate charset <meta> tag from the Page protocol's head property. * Router * Enabled auto-generated HEAD endpoints so every GET route gets a HEAD sibling. Uptime monitors and crawlers probing with HEAD now receive the page's status and headers instead of a 404. * Docker * Pinned the asset optimizer versionsvia build args so minified output is reproducible for a given Dockerfile commit. * Narrowed the build context copied into the release stage, only package manifests and Swift sources are copied. Static assets come from the separate assets stage after the binary is built. * svgo now minifies all SVGs recursively rather than just icon.svg, and the staging step creates Resources/Static explicitly instead of conditionally moving the unminified sources. * Added curl to the runtime image (needed for the container healthcheck) and .claude to .dockerignore. * Docker-compose * Added a `healthcheck` to the website service hitting GET /health (liveness only), so Compose reports process health without coupling container health to database reachability. Reviewed-on: rock-n-code/loud-amsterdam#23 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit is contained in:
+21
-10
@@ -3,9 +3,15 @@
|
||||
# ================================
|
||||
FROM node:22-alpine AS assets
|
||||
|
||||
# Install the minifiers in their own layer, so they are cached across asset changes
|
||||
RUN apk add --no-cache oxipng \
|
||||
&& npm install --global esbuild svgo
|
||||
ARG ESBUILD_VERSION=0.28.1
|
||||
ARG OXIPNG_VERSION=9.1.5
|
||||
ARG SVGO_VERSION=4.0.2
|
||||
|
||||
# Install the minifiers in their own layer, so they are cached across asset changes.
|
||||
# The oxipng pin is fuzzy (=~) so Alpine package revision bumps (-r0, -r1, ...) do
|
||||
# not break the build when the base image advances.
|
||||
RUN apk add --no-cache "oxipng=~${OXIPNG_VERSION}" \
|
||||
&& npm install --global "esbuild@${ESBUILD_VERSION}" "svgo@${SVGO_VERSION}"
|
||||
|
||||
# Copy the static files and minify the JS/CSS/SVG sources and losslessly recompress
|
||||
# the PNG images in place, keeping their names so the URL paths derived from the
|
||||
@@ -15,7 +21,7 @@ COPY ./Services/Website/Resources/Static .
|
||||
RUN esbuild --minify --allow-overwrite --outdir=css css/*.css \
|
||||
&& esbuild --minify --allow-overwrite --outdir=js js/*.js \
|
||||
&& oxipng --opt max --strip safe *.png \
|
||||
&& svgo icon.svg
|
||||
&& svgo --recursive --folder .
|
||||
|
||||
# Export stage: `docker build --target assets-export --output <dir>` writes the
|
||||
# minified static files to <dir> for local inspection.
|
||||
@@ -47,8 +53,13 @@ COPY ./Packages/Web/Package.swift ./Packages/Web/
|
||||
COPY ./Services/Website/Package.swift ./Services/Website/Package.resolved ./Services/Website/
|
||||
RUN swift package --package-path ./Services/Website resolve
|
||||
|
||||
# Copy entire repo into container
|
||||
COPY . .
|
||||
# Copy only the Swift inputs needed for a release build. Static assets are built
|
||||
# in the assets stage and copied into staging after the binary is produced.
|
||||
COPY ./Packages/Localization/Sources ./Packages/Localization/Sources
|
||||
COPY ./Packages/Persistence/Sources ./Packages/Persistence/Sources
|
||||
COPY ./Packages/Web/Sources ./Packages/Web/Sources
|
||||
COPY ./Services/Website/Sources ./Services/Website/Sources
|
||||
COPY ./Services/Website/Tests ./Services/Website/Tests
|
||||
|
||||
# Build the application, with optimizations, with static linking, and using jemalloc
|
||||
RUN swift build --package-path ./Services/Website -c release \
|
||||
@@ -68,10 +79,9 @@ RUN cp "/usr/libexec/swift/linux/swift-backtrace-static" ./
|
||||
# Copy resources bundled by SPM to staging area
|
||||
RUN find -L "$(swift build --package-path /build/Services/Website -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;
|
||||
|
||||
# Copy the static files directory (served by FileMiddleware) if it exists
|
||||
RUN [ -d /build/Services/Website/Resources ] && mv /build/Services/Website/Resources ./Resources || true
|
||||
|
||||
# Overwrite the static files with the minified copies from the assets stage
|
||||
# Create the static files directory (served by FileMiddleware) and fill it with
|
||||
# the minified copies from the assets stage
|
||||
RUN mkdir -p ./Resources/Static
|
||||
COPY --from=assets /static ./Resources/Static
|
||||
|
||||
# Ensure that by default, neither the directory nor any of its contents are writable.
|
||||
@@ -89,6 +99,7 @@ RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
|
||||
&& apt-get -q install -y \
|
||||
libjemalloc2 \
|
||||
ca-certificates \
|
||||
curl \
|
||||
tzdata \
|
||||
# If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
|
||||
# libcurl4 \
|
||||
|
||||
Reference in New Issue
Block a user