You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB
Docker

# Prepare two environments
# 0. where the application is built
# 1. where the applicatoin is run
# https://cloud.google.com/community/tutorials/deploy-react-nginx-cloud-run
# https://www.youtube.com/watch?v=Sm8GbC02MlE
# FROM node:alpine3.12 as npmi-stage
FROM node:current-alpine as build-stage
# any dir you want actually
WORKDIR /app
# Declare build arguments
ARG VITE_APPLICATION_NAME
ARG VITE_APPLICATION_HANDLE
ARG VITE_DEFAULT_LANG
ARG VITE_APP_VERSION
# Copy package.json and package-lock.json
COPY package.json ./
# Set environment variables
ENV VITE_APPLICATION_HANDLE=${VITE_APPLICATION_HANDLE}
ENV VITE_APPLICATION_NAME=${VITE_APPLICATION_NAME}
ENV VITE_DEFAULT_LANG=${VITE_DEFAULT_LANG}
ENV VITE_APP_VERSION=${VITE_APP_VERSION}
# Install dependencies
RUN npm install
# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .
# Build the application
RUN npm run build
# Stage 2: Setup the server environment
FROM nginx:alpine as deploy-stage
# Copy custom nginx config
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
# 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=build-stage /app/dist .
# Containers run nginx with global directives and daemon off
ENTRYPOINT ["nginx", "-g", "daemon off;"]