diff options
| -rw-r--r-- | .dockerignore | 5 | ||||
| -rw-r--r-- | .env.production | 1 | ||||
| -rw-r--r-- | Dockerfile | 15 | ||||
| -rwxr-xr-x | prod_bootstrap.sh | 15 |
4 files changed, 36 insertions, 0 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a809d77 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.dockerignore +Dockerfile +.vscode/ +node_modules/ +.git/ diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..eec4326 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +VITE_API_URL=%VITE_API_URL diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5e53b29 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:16-alpine AS build + +WORKDIR /app +COPY package-lock.json package.json ./ +RUN npm ci --only-prod +COPY vite.config.ts tsconfig.json index.html .env.production ./ +COPY src ./src +RUN npm run build + +FROM nginx:alpine AS serve + +RUN apk add --no-cache bash +COPY --from=build /app/dist /usr/share/nginx/html +COPY prod_bootstrap.sh / +CMD ["bash", "/prod_bootstrap.sh", "/usr/share/nginx/html"] diff --git a/prod_bootstrap.sh b/prod_bootstrap.sh new file mode 100755 index 0000000..c1de926 --- /dev/null +++ b/prod_bootstrap.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -euo pipefail +DIR="${1}" +VALID_ENV_KEYS=$(printenv | awk -F '=' '{ print $1 }' | tail | awk 'NF') + +for f in $(find ${DIR} -regex '.*\.js'); do + for envKey in ${VALID_ENV_KEYS}; do + replaced=$(printenv ${envKey}) + sed -i "s|%${envKey}|${replaced}|g" "${f}" + echo "[bootstrap] Replaced ${envKey} from container environment." + done +done + +nginx -g "daemon off;" |
