Skip to content

Commit 42d79a9

Browse files
committed
Use Node.js CLI to update env vars during start time
1 parent 89fed0a commit 42d79a9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Dockerfile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### STAGE 1: Build ###
2-
# This image is around 50 megabytes
2+
# This image is around 53 megabytes
3+
# https://hub.docker.com/_/node/tags?page=1&name=alpine
34
FROM node:18-alpine3.18 AS builder
45

56
# Create app directory
@@ -14,19 +15,25 @@ RUN npm ci --verbose
1415
# Build the ui
1516
RUN npm run build
1617

17-
# Create environment variable js file
18-
RUN node generate-env-browser.js
19-
2018
### STAGE 2: Run ###
2119
# This image is around 5 megabytes
22-
FROM nginx:1.25-alpine3.17-slim
20+
# https://hub.docker.com/_/nginx/tags?page=1&name=slim
21+
FROM nginx:1.25-alpine3.18-slim
22+
23+
# Install Node.js LTS version needed for env variable generation
24+
RUN apk add --update nodejs
2325

2426
COPY /nginx /etc/nginx/conf.d
2527

2628
EXPOSE 8080
2729
EXPOSE 443
2830

31+
# Copy web application which was build in stage 1
2932
COPY --from=builder /app/build /usr/share/nginx/html
30-
COPY --from=builder /app/env-config.js /usr/share/nginx/html/
3133

32-
# Nginx server will now start automatically.
34+
# Environment variables adjust the running environment
35+
COPY generate-env-browser.js /usr/share/nginx/html/generate-env-browser.mjs
36+
COPY .env .
37+
38+
# Start Nginx server with override ENV variables script
39+
CMD ["/bin/sh", "-c", "node /usr/share/nginx/html/generate-env-browser.mjs && nginx -g \"daemon off;\""]

0 commit comments

Comments
 (0)