From c54bf575a8b75f4c1145c8284ad4a10909091b6d Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 6 Feb 2022 10:52:23 +0200 Subject: Dockerize for prod --- .dockerignore | 5 +++++ .env.production | 1 + Dockerfile | 15 +++++++++++++++ prod_bootstrap.sh | 15 +++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.production create mode 100644 Dockerfile create mode 100755 prod_bootstrap.sh 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;" -- cgit v1.3