Created
September 20, 2021 01:37
-
-
Save deskoh/40792f100a369cd06152132f5e637941 to your computer and use it in GitHub Desktop.
SPA Container Entrypoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG BASE_REGISTRY=docker.io | |
ARG BASE_IMAGE=library/nginx | |
ARG BASE_TAG=latest | |
# Stage 1 - Build base image with nginx | |
FROM ${BASE_REGISTRY}/${BASE_IMAGE}:${BASE_TAG} as base | |
# Stage 2 - the build process | |
FROM $BASE_REGISTRY/webserver as builder | |
# Clear NODE_ENV variable to allow devDependencies to be installed | |
ENV NODE_ENV= | |
# Create directory explicitly for correct directory ownership | |
RUN mkdir /home/node/webclient | |
WORKDIR /home/node/webclient | |
ARG NPM_MIRROR=https://registry.npmjs.org | |
RUN npm config set registry $NPM_MIRROR | |
COPY package.json package-lock.json ./ | |
# Create public directory first as BUILDKIT doesn't allow directory to be modified if it is created after running `npm ci` | |
RUN mkdir public | |
RUN HUSKY=0 npm ci | |
COPY . ./ | |
RUN npm run build:docker | |
# Stage 3 - the production environment | |
FROM base as final | |
COPY nginx/default.conf /etc/nginx/conf.d/default.conf | |
COPY nginx/nginx.conf /etc/nginx/nginx.conf | |
COPY entrypoint.sh /usr/local/bin/ | |
USER root | |
RUN chmod +x /usr/local/bin/entrypoint.sh | |
USER nginx | |
COPY --from=builder /home/node/webclient/build /usr/share/nginx/html | |
# Update entrypoint.sh if adding or removing environment variables. | |
# Set default environment variables. | |
ENV BASE_URL= \ | |
APPSERVER_URL=http://localhost:3030 | |
HEALTHCHECK --interval=10s --timeout=5s --start-period=5s --retries=3 CMD curl -I -f --max-time 5 http://localhost:8080/health | |
ENTRYPOINT [ "entrypoint.sh" ] | |
CMD [ "nginx", "-g", "daemon off;" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cd /usr/share/nginx/html | |
# Save date modified | |
DATE=$(date -Rr index.html) | |
sed -i 's|"REACT_APP_BASE_URL"|"'$BASE_URL'"|g' index.html | |
sed -i 's|"REACT_APP_APPSERVER_URL"|"'$APPSERVER_URL'"|g' index.html | |
# Restore date modified for consistent ETags | |
touch -d "$DATE" index.html | |
# Forward args to CMD | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment