aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-02-06 10:52:23 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-02-06 10:52:23 +0200
commitc54bf575a8b75f4c1145c8284ad4a10909091b6d (patch)
tree8661260e2d3cd39c74944d98350ff41663e74d9b
parentf7271130ceebe1fd2d184298fc2d1e892ab7d64f (diff)
Dockerize for prod
-rw-r--r--.dockerignore5
-rw-r--r--.env.production1
-rw-r--r--Dockerfile15
-rwxr-xr-xprod_bootstrap.sh15
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;"