diff options
| author | Jan Tuomi <jan.tuomi@eficode.com> | 2019-12-23 15:31:19 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@eficode.com> | 2019-12-23 15:31:19 +0200 |
| commit | 377ed95f74a0141b12cb2cb04f57081c26524cd1 (patch) | |
| tree | 9f8850d33a80e455e3156ade99c326f3cdf0ab82 | |
| parent | cfbfb43a5e06aac134002900a8630715dec1b9cb (diff) | |
Implement method 1 with envsubstmaster
| -rw-r--r-- | Dockerfile | 4 | ||||
| -rwxr-xr-x | nginx-entrypoint.sh | 23 | ||||
| -rw-r--r-- | rollup.config.js | 2 | ||||
| -rw-r--r-- | src/inject.template.js | 4 |
4 files changed, 12 insertions, 21 deletions
@@ -11,8 +11,8 @@ RUN npm run build FROM nginx:alpine AS server WORKDIR /usr/share/nginx/html -RUN apk add --no-cache bash +RUN apk add --no-cache gettext COPY nginx-entrypoint.sh / COPY --from=builder /app/dist ./ -ENTRYPOINT [ "bash", "/nginx-entrypoint.sh" ] +ENTRYPOINT [ "sh", "/nginx-entrypoint.sh" ] diff --git a/nginx-entrypoint.sh b/nginx-entrypoint.sh index e6ed329..6518f10 100755 --- a/nginx-entrypoint.sh +++ b/nginx-entrypoint.sh @@ -1,22 +1,9 @@ -#!/usr/bin/bash +#!/bin/sh WWW_DIR=/usr/share/nginx/html -ENV_PREFIX=FRONTEND_ -INJECT_FILE_PATH="${WWW_DIR}/inject.js" +INJECT_FILE_SRC="${WWW_DIR}/inject.template.js" +INJECT_FILE_DST="${WWW_DIR}/inject.js" -cat >> "${INJECT_FILE_PATH}" << EOF -window.injectedEnv = { - NODE_ENV: "production", -EOF +envsubst < "${INJECT_FILE_SRC}" > "${INJECT_FILE_DST}" -for envrow in $(printenv); do - IFS='=' read -r key value <<< "${envrow}" - - if [[ $key == "${ENV_PREFIX}"* ]]; then - echo " ${key}: \"${value}\"," >> "${INJECT_FILE_PATH}" - fi -done - -echo "};" >> "${INJECT_FILE_PATH}" - -[ -z "$@" ] && nginx -g 'daemon off;' || "$@" +[ -z "$@" ] && nginx -g 'daemon off;' || $@ diff --git a/rollup.config.js b/rollup.config.js index 56fd795..8460edf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -12,7 +12,7 @@ export default { plugins: [ resolve(), copy({ - targets: [ { src: 'src/index.html', dest: 'dist/' } ], + targets: [ { src: 'src/index.html', dest: 'dist/' }, { src: 'src/inject.template.js', dest: 'dist/' } ], }), ], }; diff --git a/src/inject.template.js b/src/inject.template.js new file mode 100644 index 0000000..cd928bb --- /dev/null +++ b/src/inject.template.js @@ -0,0 +1,4 @@ +window.injectedEnv = { + NODE_ENV: '${NODE_ENV}', + FRONTEND_EXAMPLE_ENV: '${FRONTEND_EXAMPLE_ENV}', +}; |
