diff --git a/Dockerfile b/Dockerfile index 2d3a676..b2425c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ ARG PARENT=ubuntu/nginx ARG NODE_PARENT=node:18.12.1 -ARG VITE_API_KEY + + FROM ${NODE_PARENT} as build -ENV APP_DIR=/app +ARG VITE_API_KEY ENV VITE_API_KEY=$VITE_API_KEY +ENV APP_DIR=/app WORKDIR ${APP_DIR} @@ -15,6 +17,9 @@ RUN npm install # user node ADD --chown=node:node . ${APP_DIR} +COPY replace_env_vars.sh /usr/local/bin/replace_env_vars.sh +RUN chmod +x /usr/local/bin/replace_env_vars.sh +RUN /usr/local/bin/replace_env_vars.sh RUN npm run build FROM ${PARENT} diff --git a/k8s/codefresh.yaml b/k8s/codefresh.yaml index 7ed4299..9e6fcdd 100644 --- a/k8s/codefresh.yaml +++ b/k8s/codefresh.yaml @@ -20,6 +20,8 @@ steps: tag: "${{CF_SHORT_REVISION}}" dockerfile: Dockerfile registry: ${{REGISTRY}} + build_arguments: + - VITE_API_KEY=${{VITE_API_KEY}} deploy-to-kubernetes: image: codefresh/cf-deploy-kubernetes tag: latest diff --git a/replace_env_vars.sh b/replace_env_vars.sh new file mode 100755 index 0000000..1ba059b --- /dev/null +++ b/replace_env_vars.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# replace_env_vars.sh + +for var in $(printenv | grep VITE_ | awk -F= '{print $1}'); do + sed -i 's|import.meta.env.'$var'|"'$(printenv $var)'"|g' ./demo/*.js +done