Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Created January 24, 2021 06:48
Show Gist options
  • Save mr-pascal/06748660671d4174f38ced55607d98b8 to your computer and use it in GitHub Desktop.
Save mr-pascal/06748660671d4174f38ced55607d98b8 to your computer and use it in GitHub Desktop.
# Name the node stage "builder"
FROM node:15-alpine AS builder
# Set working directory
WORKDIR /app
# Copy our node module specification
COPY package.json package.json
COPY yarn.lock yarn.lock
# install node modules and build assets
RUN yarn install --production
# Copy all files from current directory to working dir in image
# Except the one defined in '.dockerignore'
COPY . .
# Create production build of React App
RUN yarn build
# Choose NGINX as our base Docker image
FROM nginx:alpine
# Copy our nginx configuration
COPY nginx.conf /etc/nginx/conf.d/configfile.template
# Set working directory to nginx asset directory
WORKDIR /usr/share/nginx/html
# Remove default nginx static assets
RUN rm -rf *
# Copy static assets from builder stage
COPY --from=builder /app/build .
# Define environment variables for Cloud Run
ENV PORT 8080
ENV HOST 0.0.0.0
EXPOSE 8080
# Substitute $PORT variable in config file with the one passed via "docker run"
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment