refactor: replace CDN_URL with CDN_HOST in Dockerfiles and update related scripts for asset loading

This commit is contained in:
Victor Santos
2025-12-12 14:00:59 -03:00
parent 64f566076b
commit cce59e3bf6
4 changed files with 19 additions and 19 deletions

View File

@@ -2,8 +2,8 @@ ARG POSTHOG_HOST=https://app.posthog.com
ARG POSTHOG_API_KEY=posthog-api-key ARG POSTHOG_API_KEY=posthog-api-key
ARG INTERCOM_ID=intercom-id ARG INTERCOM_ID=intercom-id
ARG CAPTCHA_SITE_KEY=captcha-site-key ARG CAPTCHA_SITE_KEY=captcha-site-key
# CDN URL placeholder - replaced at container startup with actual CDN_URL env var # CDN HOST placeholder - replaced at container startup with actual CDN_HOST env var
ARG CDN_URL=__INFISICAL_CDN_URL__ ARG CDN_HOST=__INFISICAL_CDN_HOST__
FROM node:20.19.5-trixie-slim AS base FROM node:20.19.5-trixie-slim AS base
@@ -38,8 +38,8 @@ ARG INFISICAL_PLATFORM_VERSION
ENV VITE_INFISICAL_PLATFORM_VERSION $INFISICAL_PLATFORM_VERSION ENV VITE_INFISICAL_PLATFORM_VERSION $INFISICAL_PLATFORM_VERSION
ARG CAPTCHA_SITE_KEY ARG CAPTCHA_SITE_KEY
ENV VITE_CAPTCHA_SITE_KEY $CAPTCHA_SITE_KEY ENV VITE_CAPTCHA_SITE_KEY $CAPTCHA_SITE_KEY
ARG CDN_URL ARG CDN_HOST
ENV VITE_CDN_URL $CDN_URL ENV VITE_CDN_HOST $CDN_HOST
ENV NODE_OPTIONS="--max-old-space-size=8192" ENV NODE_OPTIONS="--max-old-space-size=8192"
@@ -189,7 +189,7 @@ COPY --from=backend-runner /app /backend
COPY --from=frontend-runner /app ./backend/frontend-build COPY --from=frontend-runner /app ./backend/frontend-build
# Copy CDN URL replacement script for runtime CDN URL replacement # Copy CDN HOST replacement script for runtime CDN HOST replacement
COPY frontend/scripts/replace-standalone-build-variable.sh /backend/scripts/replace-standalone-build-variable.sh COPY frontend/scripts/replace-standalone-build-variable.sh /backend/scripts/replace-standalone-build-variable.sh
RUN chmod +x /backend/scripts/export-assets.sh /backend/scripts/replace-standalone-build-variable.sh RUN chmod +x /backend/scripts/export-assets.sh /backend/scripts/replace-standalone-build-variable.sh
RUN chown -R non-root-user:nodejs /backend/frontend-build RUN chown -R non-root-user:nodejs /backend/frontend-build

View File

@@ -2,8 +2,8 @@ ARG POSTHOG_HOST=https://app.posthog.com
ARG POSTHOG_API_KEY=posthog-api-key ARG POSTHOG_API_KEY=posthog-api-key
ARG INTERCOM_ID=intercom-id ARG INTERCOM_ID=intercom-id
ARG CAPTCHA_SITE_KEY=captcha-site-key ARG CAPTCHA_SITE_KEY=captcha-site-key
# CDN URL placeholder - replaced at container startup with actual CDN_URL env var # CDN HOST placeholder - replaced at container startup with actual CDN_HOST env var
ARG CDN_URL=__INFISICAL_CDN_URL__ ARG CDN_HOST=__INFISICAL_CDN_HOST__
FROM node:20.19.5-trixie-slim AS base FROM node:20.19.5-trixie-slim AS base
@@ -40,8 +40,8 @@ ENV INFISICAL_PLATFORM_VERSION $INFISICAL_PLATFORM_VERSION
ENV VITE_INFISICAL_PLATFORM_VERSION $INFISICAL_PLATFORM_VERSION ENV VITE_INFISICAL_PLATFORM_VERSION $INFISICAL_PLATFORM_VERSION
ARG CAPTCHA_SITE_KEY ARG CAPTCHA_SITE_KEY
ENV VITE_CAPTCHA_SITE_KEY $CAPTCHA_SITE_KEY ENV VITE_CAPTCHA_SITE_KEY $CAPTCHA_SITE_KEY
ARG CDN_URL ARG CDN_HOST
ENV VITE_CDN_URL $CDN_URL ENV VITE_CDN_HOST $CDN_HOST
ENV NODE_OPTIONS="--max-old-space-size=8192" ENV NODE_OPTIONS="--max-old-space-size=8192"
# Build # Build
@@ -178,7 +178,7 @@ ENV CAPTCHA_SITE_KEY=$CAPTCHA_SITE_KEY
COPY --from=backend-runner /app /backend COPY --from=backend-runner /app /backend
COPY --from=frontend-runner /app ./backend/frontend-build COPY --from=frontend-runner /app ./backend/frontend-build
# Copy CDN URL replacement script for runtime CDN URL replacement # Copy CDN HOST replacement script for runtime CDN HOST replacement
COPY frontend/scripts/replace-standalone-build-variable.sh /backend/scripts/replace-standalone-build-variable.sh COPY frontend/scripts/replace-standalone-build-variable.sh /backend/scripts/replace-standalone-build-variable.sh
RUN chmod +x /backend/scripts/export-assets.sh /backend/scripts/replace-standalone-build-variable.sh RUN chmod +x /backend/scripts/export-assets.sh /backend/scripts/replace-standalone-build-variable.sh
RUN chown -R non-root-user:nodejs /backend/frontend-build RUN chown -R non-root-user:nodejs /backend/frontend-build

View File

@@ -29,11 +29,11 @@ export default defineConfig(({ mode }) => {
"0.0.1" "0.0.1"
).replaceAll(".", "-"); ).replaceAll(".", "-");
// CDN URL for static assets in /assets/* only. // CDN HOST for static assets in /assets/* only.
// Docker: Set CDN_URL env var at runtime (placeholder replaced at container startup). // Docker: Set CDN_HOST env var at runtime (placeholder replaced at container startup).
// Direct build: Use --build-arg CDN_URL=https://... or VITE_CDN_URL env var. // Direct build: Use --build-arg CDN_HOST=https://... or VITE_CDN_HOST env var.
// Default: Empty = same-origin asset loading. // Default: Empty = same-origin asset loading.
const cdnUrl = env.VITE_CDN_URL || ""; const cdnHost = env.VITE_CDN_HOST || "";
return { return {
base: "/", base: "/",
@@ -60,10 +60,10 @@ export default defineConfig(({ mode }) => {
} }
}, },
experimental: { experimental: {
// Only apply CDN URL to files in /assets/* directory // Only apply CDN HOST to files in /assets/* directory
renderBuiltUrl(filename) { renderBuiltUrl(filename) {
if (filename.startsWith("assets/") && cdnUrl) { if (filename.startsWith("assets/") && cdnHost) {
return `${cdnUrl}/${filename}`; return `${cdnHost}/${filename}`;
} }
return `/${filename}`; return `/${filename}`;
} }

View File

@@ -5,8 +5,8 @@ update-ca-certificates
if [ -d "/backend/frontend-build/assets" ]; then if [ -d "/backend/frontend-build/assets" ]; then
cd /backend/frontend-build || { echo "ERROR: Failed to cd to frontend-build"; exit 1; } cd /backend/frontend-build || { echo "ERROR: Failed to cd to frontend-build"; exit 1; }
if ! /backend/scripts/replace-standalone-build-variable.sh "__INFISICAL_CDN_URL__" "${CDN_URL:-}"; then if ! /backend/scripts/replace-standalone-build-variable.sh "__INFISICAL_CDN_HOST__" "${CDN_HOST:-}"; then
echo "WARNING: CDN URL replacement failed, assets may not load correctly" echo "WARNING: CDN HOST replacement failed, assets may not load correctly"
fi fi
cd /backend || { echo "ERROR: Failed to cd to backend"; exit 1; } cd /backend || { echo "ERROR: Failed to cd to backend"; exit 1; }