From f07bdb7cb1bcffac32b2b733aafeb7ab8cdd8b1b Mon Sep 17 00:00:00 2001 From: thenav56 Date: Thu, 7 Nov 2024 14:32:19 +0545 Subject: [PATCH] Changes from go-web-app fixes https://github.com/IFRCGo/go-web-app/pull/1447/commits/2f58e5374e8d8cd8d28de500eade502e8275eae7 --- Dockerfile | 8 ++++---- env.ts | 4 +++- nginx-serve/{apply-helm-config.sh => apply-config.sh} | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) rename nginx-serve/{apply-helm-config.sh => apply-config.sh} (88%) diff --git a/Dockerfile b/Dockerfile index 911c755e..6745f307 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,10 +46,10 @@ FROM nginx:1 AS nginx-serve LABEL maintainer="IFRC" LABEL org.opencontainers.image.source="github.com/IFRCGo/alert-hub-web-app" -COPY ./nginx-serve/apply-helm-config.sh /docker-entrypoint.d/ +COPY ./nginx-serve/apply-config.sh /docker-entrypoint.d/ COPY ./nginx-serve/nginx.conf.template /etc/nginx/templates/default.conf.template COPY --from=nginx-build /code/build /code/build -ENV SOURCE_DIRECTORY=/code/build/ -ENV DESTINATION_DIRECTORY=/usr/share/nginx/html/ -ENV OVERWRITE_DESTINATION=true +ENV APPLY_CONFIG__SOURCE_DIRECTORY=/code/build/ +ENV APPLY_CONFIG__DESTINATION_DIRECTORY=/usr/share/nginx/html/ +ENV APPLY_CONFIG__OVERWRITE_DESTINATION=true diff --git a/env.ts b/env.ts index 9c566122..99122ab7 100644 --- a/env.ts +++ b/env.ts @@ -4,13 +4,15 @@ import { defineConfig, Schema } from '@julr/vite-plugin-validate-env'; export default defineConfig({ APP_TITLE: Schema.string.optional(), APP_ENVIRONMENT: (key, value) => { + // NOTE: APP_ENVIRONMENT_PLACEHOLDER is meant to be used with image builds + // The value will be later replaced with the actual value const regex = /^production|staging|testing|alpha-\d+|development|APP_ENVIRONMENT_PLACEHOLDER$/; const valid = !!value && (value.match(regex) !== null); if (!valid) { throw new Error(`Value for environment variable "${key}" must match regex "${regex}", instead received "${value}"`); } if (value === 'APP_ENVIRONMENT_PLACEHOLDER') { - console.warn(`Using ${value} for app environment. Make sure to not use this for builds without helm chart`) + console.warn(`Using ${value} for app environment. Make sure to not use this for builds without nginx-serve`) } return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development' | 'APP_ENVIRONMENT_PLACEHOLDER'); }, diff --git a/nginx-serve/apply-helm-config.sh b/nginx-serve/apply-config.sh similarity index 88% rename from nginx-serve/apply-helm-config.sh rename to nginx-serve/apply-config.sh index a19b8f0a..c81214e1 100755 --- a/nginx-serve/apply-helm-config.sh +++ b/nginx-serve/apply-config.sh @@ -1,10 +1,10 @@ #!/bin/bash -xe -SOURCE_DIRECTORY=${SOURCE_DIRECTORY?Required} -DESTINATION_DIRECTORY=${DESTINATION_DIRECTORY?Required} +SOURCE_DIRECTORY=${APPLY_CONFIG__SOURCE_DIRECTORY?Required} +DESTINATION_DIRECTORY=${APPLY_CONFIG__DESTINATION_DIRECTORY?Required} # Parse arguments for --overwrite option -OVERWRITE_DESTINATION=${OVERWRITE_DESTINATION:-false} +OVERWRITE_DESTINATION=${APPLY_CONFIG__OVERWRITE_DESTINATION:-false} for arg in "$@"; do if [[ "$arg" == "--overwrite" ]]; then OVERWRITE_DESTINATION=true