From b58248098efe759ea4b1fb9c6a7eb7698556d5d5 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Thu, 30 Jan 2025 17:49:03 +0100 Subject: [PATCH] feat(web): validate reearth_config.json on startup Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- web/Dockerfile | 3 +++ web/docker/40-envsubst-on-reearth-config.sh | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/web/Dockerfile b/web/Dockerfile index ca13656c5d..a7b0b0f40e 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -68,6 +68,9 @@ ENV REEARTH_PUBLISHED=null ENV REEARTH_TITLE= ENV REEARTH_UNSAFE_PLUGIN_URLS=[] +RUN --mount=type=cache,target=/var/cache/apk \ + apk add --no-cache jq + COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html COPY --chown=nginx:nginx docker/nginx.conf.template /etc/nginx/templates/nginx.conf.template COPY --chown=nginx:nginx docker/40-envsubst-on-reearth-config.sh /docker-entrypoint.d diff --git a/web/docker/40-envsubst-on-reearth-config.sh b/web/docker/40-envsubst-on-reearth-config.sh index 73ca539de1..41cb51516b 100755 --- a/web/docker/40-envsubst-on-reearth-config.sh +++ b/web/docker/40-envsubst-on-reearth-config.sh @@ -36,3 +36,7 @@ wrap_reearth_variables() { wrap_reearth_variables "$@" envsubst < "$_REEARTH_CONFIG_TEMPLATE_FILE" > "$_REEARTH_CONFIG_OUTPUT_FILE" +if ! jq empty "$_REEARTH_CONFIG_OUTPUT_FILE" > /dev/null 2>&1; then + echo "Invalid JSON configuration file $_REEARTH_CONFIG_OUTPUT_FILE" >&2 + exit 1 +fi