45 lines
1.5 KiB
Docker
45 lines
1.5 KiB
Docker
# Dockerfile
|
|
|
|
# Stage 1: Build the React application
|
|
FROM node:18-alpine AS build
|
|
|
|
LABEL stage="build-local-testing"
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package.json and package-lock.json (or yarn.lock)
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies using the lock file for consistency
|
|
RUN npm install
|
|
|
|
# Copy the rest of the application source code
|
|
COPY . .
|
|
|
|
# --- For Local Testing with .env.local ---
|
|
# Copy your .env.local file as .env in the build context.
|
|
# Create React App's build script will automatically load variables from this .env file.
|
|
# IMPORTANT: Ensure .env.local contains your actual Firebase API keys and other secrets.
|
|
# This .env.local file MUST be in your .gitignore and NOT committed to your repository.
|
|
# This Docker image, built this way, CONTAINS YOUR SECRETS and should NOT be pushed to a public registry.
|
|
COPY .env.local .env
|
|
# --- End Local Testing Section ---
|
|
|
|
# Build the application. react-scripts build will use environment variables
|
|
# prefixed with REACT_APP_ (either from the .env file copied above or from the build environment).
|
|
# Set NODE_OPTIONS to use the legacy OpenSSL provider for the build step.
|
|
RUN NODE_OPTIONS=--openssl-legacy-provider npm run build
|
|
|
|
# Stage 2: Serve the static files using Nginx
|
|
FROM nginx:1.25-alpine
|
|
|
|
LABEL stage="nginx-server"
|
|
|
|
# Copy the build output from the 'build' stage to Nginx's html directory
|
|
COPY --from=build /app/build /usr/share/nginx/html
|
|
|
|
# Expose port 80 (Nginx default)
|
|
EXPOSE 80
|
|
|
|
# Start Nginx when the container launches
|
|
CMD ["nginx", "-g", "daemon off;"] |