Skip to content

Commit

Permalink
chore: update frontend-usagers docker image to not depend on buildargs
Browse files Browse the repository at this point in the history
  • Loading branch information
achauve committed Aug 23, 2024
1 parent fc9f375 commit d27eb65
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ fileignoreconfig:
checksum: ebaeaef58dff99ed0a70ace0cb1cfceb31c0656d921999e19ce183e2adc9431f
- filename: .kontinuous/values.yaml
checksum: 40913e433609d86128443db129e4b97da472b3f0811f4db61024ab2943051ca4
- filename: 100-start-prod.sh
checksum: 61fc46497c2c057c938a6bccda8e6506d5390a66e102616fff9a50d691d301bd
- filename: README.md
checksum: 3627cd363d1cfc640df689ce74d5467e13707a2cc9c44b0bffaba14f217296e2
- filename: _scripts/dev/local-node.dockerfile
Expand Down
26 changes: 26 additions & 0 deletions 100-start-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

set -e

READONLY_DIR=/app
WRITABLE_DIR=/usr/share/nginx/html

cp -r $READONLY_DIR/* $WRITABLE_DIR/

cat <<EOF >>$WRITABLE_DIR/config.json
{
"appVersion": "$ENV_NUXT_PUBLIC_APP_VERSION",
"backendUrl": "$ENV_NUXT_PUBLIC_BACKEND_URL",
"environment": "$ENV_NUXT_PUBLIC_ENVIRONMENT",
"matomo": {
"enabled": "$ENV_NUXT_PUBLIC_MATOMO_ENABLED",
"host": "$ENV_NUXT_PUBLIC_MATOMO_HOST",
"siteId": "$ENV_NUXT_PUBLIC_MATOMO_SITE_ID"
},
"sentry": {
"enabled": "$ENV_NUXT_PUBLIC_SENTRY_ENABLED",
"dsn": "$ENV_NUXT_PUBLIC_SENTRY_DSN",
"release": "$ENV_NUXT_PUBLIC_SENTRY_RELEASE"
}
}
EOF
31 changes: 7 additions & 24 deletions packages/frontend-usagers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,25 @@ COPY packages/shared/package.json packages/shared/
COPY packages/frontend-usagers/package.json packages/frontend-usagers/yarn.lock packages/frontend-usagers/
RUN yarn workspace @vao/frontend-usagers install --frozen-lockfile

# these variables are needed at build time because we produce a *static* app
ARG NUXT_PUBLIC_APP_VERSION=development
ARG NUXT_PUBLIC_BACKEND_URL
ARG NUXT_PUBLIC_ENVIRONMENT
ARG NUXT_PUBLIC_MATOMO_ENABLED
ARG NUXT_PUBLIC_MATOMO_HOST
ARG NUXT_PUBLIC_MATOMO_SITE_ID
ARG NUXT_PUBLIC_SENTRY_DSN
ARG NUXT_PUBLIC_SENTRY_RELEASE
ARG NUXT_PUBLIC_SENTRY_ENABLED
# Sentry variables are needed at build time to upload sourcemaps
ARG SENTRY_ORG
ARG SENTRY_PROJECT
ARG SENTRY_URL
ARG SENTRY_AUTH_TOKEN

ENV NUXT_PUBLIC_APP_VERSION=$NUXT_PUBLIC_APP_VERSION
ENV NUXT_PUBLIC_BACKEND_URL=$NUXT_PUBLIC_BACKEND_URL
ENV NUXT_PUBLIC_ENVIRONMENT=$NUXT_PUBLIC_ENVIRONMENT
ENV NUXT_PUBLIC_MATOMO_ENABLED=$NUXT_PUBLIC_MATOMO_ENABLED
ENV NUXT_PUBLIC_MATOMO_HOST=$NUXT_PUBLIC_MATOMO_HOST
ENV NUXT_PUBLIC_MATOMO_SITE_ID=$NUXT_PUBLIC_MATOMO_SITE_ID
ENV NUXT_PUBLIC_SENTRY_DSN=$NUXT_PUBLIC_SENTRY_DSN
ENV NUXT_PUBLIC_SENTRY_RELEASE=$NUXT_PUBLIC_SENTRY_RELEASE
ENV NUXT_PUBLIC_SENTRY_ENABLED=$NUXT_PUBLIC_SENTRY_ENABLED
ENV SENTRY_RELEASE=$NUXT_PUBLIC_SENTRY_RELEASE
# Cannot be changed at runtime
ENV SENTRY_RELEASE=$SENTRY_RELEASE
ENV SENTRY_ORG=$SENTRY_ORG
ENV SENTRY_PROJECT=$SENTRY_PROJECT
ENV SENTRY_URL=$SENTRY_URL

COPY packages/shared packages/shared
COPY packages/frontend-usagers packages/frontend-usagers

RUN --mount=type=secret,id=sentry_auth_token \
export SENTRY_AUTH_TOKEN=$(cat /run/secrets/sentry_auth_token) \
&& yarn workspace @vao/frontend-usagers generate
RUN yarn workspace @vao/frontend-usagers generate


FROM ghcr.io/socialgouv/docker/nginx4spa:8.2.3

COPY --from=builder --chown=101:101 /app/packages/frontend-usagers/.output/public /usr/share/nginx/html
COPY --chmod=755 100-start-prod.sh /docker-entrypoint.d/100-start-prod.sh
COPY --from=builder --chown=101:101 /app/packages/frontend-usagers/.output/public /app
13 changes: 13 additions & 0 deletions packages/frontend-usagers/src/plugins/00.runtime-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineNuxtPlugin } from "#app";

export default defineNuxtPlugin(async ({ $config }) => {
if (import.meta.client) {
try {
const response = await fetch("/config.json");
const config = await response.json();
$config.public = { ...$config.public, ...config };
} catch (error) {
console.error("Dynamic config unavailable (local)", error);
}
}
});

0 comments on commit d27eb65

Please sign in to comment.