Skip to content

Commit

Permalink
fix: use dynamic config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
achauve committed Aug 20, 2024
1 parent 4634274 commit 4ebd87b
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 72 deletions.
4 changes: 3 additions & 1 deletion .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 Expand Up @@ -234,7 +236,7 @@ fileignoreconfig:
- filename: pg/seeds/BO-1-back-user.sql
checksum: 2261cabf80475ffa0c06e59760d4a89ea3331b81062fe5e8640745741a562995
- filename: run_front.sh
checksum: a844e8dc91bac636739c5119838d389e7517c8d6f5ef6669841a80fc6e20da85
checksum: 4f6428118676de7f0eb7d8e89cdb10c83fa27da6ae3b4221e143368ce58d1088
scopeconfig:
- scope: node
version: "1.0"
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

APP_TEMPLATED_DIR=/app
APP_DIR=/usr/share/nginx/html

cp -r $APP_TEMPLATED_DIR/* $APP_DIR/

cat <<EOF >>$APP_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
21 changes: 10 additions & 11 deletions packages/frontend-usagers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ ARG SENTRY_PROJECT
ARG SENTRY_URL
ARG SENTRY_AUTH_TOKEN

# Runtime env variables set by Nginx injection
ENV NUXT_PUBLIC_APP_VERSION=ENV_NUXT_PUBLIC_APP_VERSION
ENV NUXT_PUBLIC_BACKEND_URL=ENV_NUXT_PUBLIC_BACKEND_URL
ENV NUXT_PUBLIC_ENVIRONMENT=ENV_NUXT_PUBLIC_ENVIRONMENT
ENV NUXT_PUBLIC_MATOMO_ENABLED=ENV_NUXT_PUBLIC_MATOMO_ENABLED
ENV NUXT_PUBLIC_MATOMO_HOST=ENV_NUXT_PUBLIC_MATOMO_HOST
ENV NUXT_PUBLIC_MATOMO_SITE_ID=ENV_NUXT_PUBLIC_MATOMO_SITE_ID
ENV NUXT_PUBLIC_SENTRY_DSN=ENV_NUXT_PUBLIC_SENTRY_DSN
ENV NUXT_PUBLIC_SENTRY_ENABLED=ENV_NUXT_PUBLIC_SENTRY_ENABLED
# # Runtime env variables set by Nginx injection
# ENV NUXT_PUBLIC_APP_VERSION=ENV_NUXT_PUBLIC_APP_VERSION
# ENV NUXT_PUBLIC_BACKEND_URL=ENV_NUXT_PUBLIC_BACKEND_URL
# ENV NUXT_PUBLIC_ENVIRONMENT=ENV_NUXT_PUBLIC_ENVIRONMENT
# ENV NUXT_PUBLIC_MATOMO_ENABLED=ENV_NUXT_PUBLIC_MATOMO_ENABLED
# ENV NUXT_PUBLIC_MATOMO_HOST=ENV_NUXT_PUBLIC_MATOMO_HOST
# ENV NUXT_PUBLIC_MATOMO_SITE_ID=ENV_NUXT_PUBLIC_MATOMO_SITE_ID
# ENV NUXT_PUBLIC_SENTRY_DSN=ENV_NUXT_PUBLIC_SENTRY_DSN
# ENV NUXT_PUBLIC_SENTRY_ENABLED=ENV_NUXT_PUBLIC_SENTRY_ENABLED

# Cannot be changed at runtime
ENV NUXT_PUBLIC_SENTRY_RELEASE=$SENTRY_RELEASE
ENV SENTRY_RELEASE=$SENTRY_RELEASE
ENV SENTRY_ORG=$SENTRY_ORG
ENV SENTRY_PROJECT=$SENTRY_PROJECT
Expand All @@ -45,7 +44,7 @@ RUN yarn workspace @vao/frontend-usagers generate
FROM nginxinc/nginx-unprivileged:1.27-alpine

COPY packages/frontend-usagers/nginx.conf /etc/nginx/nginx.conf
COPY packages/frontend-usagers/nginx.conf.template /etc/nginx/templates/default.conf.template
COPY --chmod=755 100-start-prod.sh /docker-entrypoint.d/100-start-prod.sh

USER 0
RUN chown -R nginx:nginx /usr/share/nginx/html && chmod -R 755 /usr/share/nginx/html \
Expand Down
31 changes: 30 additions & 1 deletion packages/frontend-usagers/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,34 @@ http {
keepalive_timeout 3000;
sendfile on;

include /etc/nginx/conf.d/*.conf;
server {
listen 8080;
root /usr/share/nginx/html;
index index.html;
server_name_in_redirect on;
add_header X-Frame-Options "deny";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
charset utf-8;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/css application/json application/javascript application/x-javascript text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
client_max_body_size 32m;
error_page 500 502 503 504 /50x.html;

location / {
# this always fallback on /index.html, never 404
try_files $uri $uri.html $uri/index.html $uri/ /index.html;
}

location /50x.html {
root /var/lib/nginx/html;
}
}
}
42 changes: 0 additions & 42 deletions packages/frontend-usagers/nginx.conf.template

This file was deleted.

4 changes: 0 additions & 4 deletions packages/frontend-usagers/src/app.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<template>
<script>
console.log("hello");
// CONFIGURATIONS_PLACEHOLDER
</script>
<div>
<NuxtLayout>
<NuxtPage />
Expand Down
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);
}
}
});
3 changes: 3 additions & 0 deletions packages/frontend-usagers/src/plugins/vue-matomo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default defineNuxtPlugin((nuxtApp) => {
const {
public: { matomo },
} = useRuntimeConfig();

console.error("==== matomo:", matomo);

if (matomo.enabled) {
nuxtApp.vueApp.use(VueMatomo, {
router: nuxtApp.$router,
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend-usagers/src/utils/fetchBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { useRuntimeConfig } from "#app";
export const $fetchBackend = (url, option = {}) => {
const config = useRuntimeConfig();
// eslint-disable-next-line no-undef

console.error("==== backend fetch config:", config);
console.error("--> url:", url);
console.error("--> backendUrl:", config.public.backendUrl);
// eslint-disable-next-line no-undef
return $fetch(url, {
baseURL: config.public.backendUrl,
...option,
Expand Down
28 changes: 15 additions & 13 deletions run_front.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
docker build . -f packages/frontend-usagers/Dockerfile -t frontend-usagers:latest --progress plain

docker run --rm -it \
-e ENV_NUXT_PUBLIC_APP_VERSION=toto \
-e ENV_NUXT_PUBLIC_BACKEND_URL=http://localhost:3010 \
-e ENV_NUXT_PUBLIC_MATOMO_ENABLED="false" \
-e ENV_NUXT_PUBLIC_MATOMO_HOST=http://matomo.fabrique.social.gouv.fr \
-e ENV_NUXT_PUBLIC_MATOMO_SITE_ID=tete \
-e ENV_NUXT_PUBLIC_SENTRY_DSN=https://38eaf4da504d4809a74ce3134b759c91@sentry.fabrique.social.gouv.fr/103 \
-e ENV_NUXT_PUBLIC_SENTRY_ENABLED="false" \
-e ENV_NUXT_PUBLIC_ENVIRONMENT=local \
-p 8080:8080 \
frontend-usagers:latest
set -e

docker build . -f packages/frontend-usagers/Dockerfile -t frontend-usagers:latest --progress plain

docker run --rm -it \
-e ENV_NUXT_PUBLIC_APP_VERSION=toto \
-e ENV_NUXT_PUBLIC_BACKEND_URL=http://localhost:3010 \
-e ENV_NUXT_PUBLIC_MATOMO_ENABLED="false" \
-e ENV_NUXT_PUBLIC_MATOMO_HOST=https://matomo.fabrique.social.gouv.fr \
-e ENV_NUXT_PUBLIC_MATOMO_SITE_ID=tete \
-e ENV_NUXT_PUBLIC_SENTRY_DSN=https://38eaf4da504d4809a74ce3134b759c91@sentry.fabrique.social.gouv.fr/103 \
-e ENV_NUXT_PUBLIC_SENTRY_ENABLED="false" \
-e ENV_NUXT_PUBLIC_ENVIRONMENT=local \
-p 8080:8080 \
frontend-usagers:latest



Expand Down

0 comments on commit 4ebd87b

Please sign in to comment.