Allow docker image to work off of environment variables instead of hardcoded on build

This commit is contained in:
dragongoose
2023-04-26 10:31:07 -04:00
parent 4f03d41b0a
commit c1b214b0c9
4 changed files with 32 additions and 17 deletions

View File

@ -6,13 +6,10 @@
FROM node:16 AS builder
# Set working directory
WORKDIR /app
ARG VITE_BACKEND_DOMAIN
ARG VITE_INSTANCE_DOMAIN
ARG VITE_HTTPS
ENV VITE_BACKEND_DOMAIN $VITE_BACKEND_DOMAIN
ENV VITE_INSTANCE_DOMAIN $VITE_INSTANCE_DOMAIN
ENV VITE_HTTPS $VITE_HTTPS
ENV VITE_BACKEND_DOMAIN VITE_BACKEND_DOMAIN_PLACEHOLDER
ENV VITE_INSTANCE_DOMAIN VITE_INSTANCE_DOMAIN_PLACEHOLDER
ENV VITE_HTTPS VITE_HTTPS_PLACEHOLDER
# Copy all files from current directory to working dir in image
COPY . .
# install node modules and build assets
@ -22,11 +19,13 @@ RUN npm i && npm run build
FROM nginx:alpine
COPY ./nginx.conf /etc/nginx/nginx.conf
# Set working directory to nginx asset directory
WORKDIR /usr/share/nginx/html
# Remove default nginx static assets
RUN rm -rf ./*
RUN mkdir /app
# Copy static assets from builder stage
COPY --from=builder /app/dist .
COPY --from=builder /app/dist /app
# Containers run nginx with global directives and daemon off
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]
# Overriding the default NGINX container behavior
COPY ./substitute_environment_variables.sh ./substitute_environment_variables.sh
RUN chmod +x /substitute_environment_variables.sh
ENTRYPOINT ["/substitute_environment_variables.sh"]

View File

@ -4,9 +4,10 @@ services:
build:
context: "../"
dockerfile: ./docker/Dockerfile
args :
- VITE_BACKEND_DOMAIN=localhost:7000
- VITE_INSTANCE_DOMAIN=localhost:80
- VITE_HTTPS=false
ports:
- "8080:80"
- "8080:80"
environment:
- VITE_BACKEND_DOMAIN=localhost:7000
- VITE_INSTANCE_DOMAIN=localhost:80
- VITE_HTTPS=false