Files
ttrpg-initiative-tracker/Dockerfile
T
robert c54fd88c32 fix(docker): copy workspace package.json files before npm install
npm workspaces needs shared/package.json and server/package.json present
at install time to link @ttrpg/shared, otherwise the build stage fails
with "Module not found: Error: Can't resolve '@ttrpg/shared'".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-01 19:40:23 -04:00

51 lines
1.8 KiB
Docker

# Dockerfile
# Stage 1: Build the React application
FROM node:18-alpine AS build
LABEL stage="build-local-testing"
WORKDIR /app
# Copy root package.json/lockfile plus workspace manifests so npm can
# resolve the @ttrpg/shared and server workspace links during install.
COPY package*.json ./
COPY shared/package.json ./shared/
COPY server/package.json ./server/
# 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
# Replace default nginx config with one that handles SPA client-side routing
COPY nginx-docker.conf /etc/nginx/conf.d/default.conf
# Expose port 80 (Nginx default)
EXPOSE 80
# Start Nginx when the container launches
CMD ["nginx", "-g", "daemon off;"]