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 INTERCOM_ID=intercom-id
ARG CAPTCHA_SITE_KEY=captcha-site-key
# CDN URL placeholder - replaced at container startup with actual CDN_URL env var
ARG CDN_URL=__INFISICAL_CDN_URL__
# CDN HOST placeholder - replaced at container startup with actual CDN_HOST env var
ARG CDN_HOST=__INFISICAL_CDN_HOST__
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
ARG CAPTCHA_SITE_KEY
ENV VITE_CAPTCHA_SITE_KEY $CAPTCHA_SITE_KEY
ARG CDN_URL
ENV VITE_CDN_URL $CDN_URL
ARG CDN_HOST
ENV VITE_CDN_HOST $CDN_HOST
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 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
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

View File

@@ -2,8 +2,8 @@ ARG POSTHOG_HOST=https://app.posthog.com
ARG POSTHOG_API_KEY=posthog-api-key
ARG INTERCOM_ID=intercom-id
ARG CAPTCHA_SITE_KEY=captcha-site-key
# CDN URL placeholder - replaced at container startup with actual CDN_URL env var
ARG CDN_URL=__INFISICAL_CDN_URL__
# CDN HOST placeholder - replaced at container startup with actual CDN_HOST env var
ARG CDN_HOST=__INFISICAL_CDN_HOST__
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
ARG CAPTCHA_SITE_KEY
ENV VITE_CAPTCHA_SITE_KEY $CAPTCHA_SITE_KEY
ARG CDN_URL
ENV VITE_CDN_URL $CDN_URL
ARG CDN_HOST
ENV VITE_CDN_HOST $CDN_HOST
ENV NODE_OPTIONS="--max-old-space-size=8192"
# Build
@@ -178,7 +178,7 @@ ENV CAPTCHA_SITE_KEY=$CAPTCHA_SITE_KEY
COPY --from=backend-runner /app /backend
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
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

View File

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

View File

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