diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7e134bd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +.git +dist +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..21850af --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Build stage +FROM node:18-alpine AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +# Runtime stage +FROM nginx:alpine +RUN apk add --no-cache gettext +COPY --from=builder /app/dist /usr/share/nginx/html +COPY public/config.template.js /usr/share/nginx/html/ +COPY docker-entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..b90ac9c --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +# Generate config.js from template at runtime +envsubst < /usr/share/nginx/html/config.template.js > /usr/share/nginx/html/config.js + +# Start nginx +exec "$@" diff --git a/public/config.template.js b/public/config.template.js new file mode 100644 index 0000000..0d796f2 --- /dev/null +++ b/public/config.template.js @@ -0,0 +1,3 @@ +window.__RUNTIME_CONFIG__ = { + API_HOSTNAME: '${API_HOSTNAME}' +}; diff --git a/public/index.html b/public/index.html index 6be1946..3e41c11 100644 --- a/public/index.html +++ b/public/index.html @@ -8,6 +8,7 @@ <%= htmlWebpackPlugin.options.title %> +