mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
fix(app-proxy): share one asset tree across architectures (#2325)
This commit is contained in:
+16
-11
@@ -4,6 +4,8 @@ ARG BUILD_VERSION=""
|
||||
ARG PUBLIC_ASSET_BASE_URL=""
|
||||
ARG FLUXER_APP_PROXY_TIME_FREEZE_ENABLED="true"
|
||||
ARG BUNDLE_LOCAL_ASSETS="true"
|
||||
ARG APP_ASSETS_REF=app-assets
|
||||
ARG APP_ASSETS_PLATFORM=$BUILDPLATFORM
|
||||
|
||||
# ---------- Stage 1: Build the SPA (fluxer_app) ----------
|
||||
FROM node:24-bookworm-slim AS app-build
|
||||
@@ -79,13 +81,19 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
||||
--mount=type=cache,target=/usr/local/cargo/git \
|
||||
cd fluxer_app && pnpm build
|
||||
|
||||
# Extract the full SPA asset tree for local serving by the app proxy.
|
||||
# ---------- Stage 2: The one canonical asset tree every architecture serves ----------
|
||||
# Stage for CI to extract the full dist (docker bake app-dist target)
|
||||
FROM alpine:3.21 AS app-dist
|
||||
COPY --from=app-build /usr/src/app/fluxer_app/dist /dist
|
||||
|
||||
FROM alpine:3.21 AS app-assets
|
||||
ARG BUNDLE_LOCAL_ASSETS=true
|
||||
ARG PUBLIC_ASSET_BASE_URL=""
|
||||
COPY --from=app-build /usr/src/app/fluxer_app/dist /assets
|
||||
COPY fluxer_app_proxy/scripts/precompress_assets.sh /usr/local/bin/precompress_assets.sh
|
||||
RUN if [ "${BUNDLE_LOCAL_ASSETS}" != "true" ]; then \
|
||||
RUN apk add --no-cache brotli
|
||||
RUN --mount=type=bind,from=app-dist,source=/dist,target=/dist \
|
||||
cp -a /dist /assets \
|
||||
&& if [ "${BUNDLE_LOCAL_ASSETS}" != "true" ]; then \
|
||||
case "${PUBLIC_ASSET_BASE_URL}" in \
|
||||
http://* | https://*) ;; \
|
||||
*) \
|
||||
@@ -95,15 +103,12 @@ RUN if [ "${BUNDLE_LOCAL_ASSETS}" != "true" ]; then \
|
||||
;; \
|
||||
esac; \
|
||||
find /assets/assets -type f ! -name 'fonts-*.txt' -delete; \
|
||||
fi
|
||||
RUN apk add --no-cache brotli \
|
||||
fi \
|
||||
&& /usr/local/bin/precompress_assets.sh /assets
|
||||
|
||||
# Stage for CI to extract the full dist (docker bake app-dist target)
|
||||
FROM alpine:3.21 AS app-dist
|
||||
COPY --from=app-build /usr/src/app/fluxer_app/dist /dist
|
||||
FROM --platform=${APP_ASSETS_PLATFORM} ${APP_ASSETS_REF} AS app-static
|
||||
|
||||
# ---------- Stage 2: Build the Rust proxy binary ----------
|
||||
# ---------- Stage 3: Build the Rust proxy binary ----------
|
||||
FROM rust:1-bookworm AS rust-builder
|
||||
|
||||
ARG FLUXER_APP_PROXY_TIME_FREEZE_ENABLED="true"
|
||||
@@ -141,7 +146,7 @@ RUN if [ "${FLUXER_APP_PROXY_TIME_FREEZE_ENABLED}" = "false" ]; then \
|
||||
fi \
|
||||
&& cp target/release/fluxer_app_proxy /usr/local/bin/fluxer-app-proxy
|
||||
|
||||
# ---------- Stage 3: Runtime ----------
|
||||
# ---------- Stage 4: Runtime ----------
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
ARG BUILD_VERSION=""
|
||||
@@ -167,7 +172,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=rust-builder /usr/local/bin/fluxer-app-proxy /usr/local/bin/fluxer-app-proxy
|
||||
COPY --from=app-assets /assets ./static/
|
||||
COPY --from=app-static /assets ./static/
|
||||
|
||||
ENV BUILD_VERSION="${BUILD_VERSION}"
|
||||
ENV FLUXER_APP_PROXY_HOST="0.0.0.0"
|
||||
|
||||
@@ -6,6 +6,10 @@ variable "BUNDLE_LOCAL_ASSETS" { default = "true" }
|
||||
variable "IMAGE_REPO" { default = "" }
|
||||
variable "CACHE_FROM" { default = "" }
|
||||
variable "CACHE_TO" { default = "" }
|
||||
variable "APP_ASSETS_REF" { default = "app-assets" }
|
||||
variable "APP_ASSETS_PLATFORM" { default = "linux/amd64" }
|
||||
variable "SOURCE_SHA" { default = "" }
|
||||
variable "SOURCE_DATE" { default = "" }
|
||||
|
||||
group "default" {
|
||||
targets = ["app-proxy", "app-dist"]
|
||||
@@ -24,6 +28,10 @@ target "app-proxy" {
|
||||
PUBLIC_ASSET_BASE_URL = PUBLIC_ASSET_BASE_URL
|
||||
FLUXER_APP_PROXY_TIME_FREEZE_ENABLED = FLUXER_APP_PROXY_TIME_FREEZE_ENABLED
|
||||
BUNDLE_LOCAL_ASSETS = BUNDLE_LOCAL_ASSETS
|
||||
APP_ASSETS_REF = APP_ASSETS_REF
|
||||
APP_ASSETS_PLATFORM = APP_ASSETS_PLATFORM
|
||||
SOURCE_SHA = SOURCE_SHA
|
||||
SOURCE_DATE = SOURCE_DATE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,3 +41,10 @@ target "app-dist" {
|
||||
tags = []
|
||||
output = ["type=local,dest=app-dist-output"]
|
||||
}
|
||||
|
||||
target "app-assets-image" {
|
||||
inherits = ["app-proxy"]
|
||||
target = "app-assets"
|
||||
tags = IMAGE_REPO != "" ? ["${IMAGE_REPO}:${BUILD_VERSION}-assets"] : []
|
||||
output = ["type=registry"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user