42 lines
1.4 KiB
Docker
42 lines
1.4 KiB
Docker
# syntax=docker/dockerfile:1.4
|
|
|
|
# Build stage
|
|
FROM node:lts AS build
|
|
|
|
WORKDIR /app
|
|
|
|
# Set environment variables to help with sharp installation
|
|
ENV SHARP_IGNORE_GLOBAL_LIBVIPS=1
|
|
ENV npm_config_sharp_binary_host="https://npmjs.org/mirrors/sharp"
|
|
ENV npm_config_sharp_libvips_binary_host="https://npmjs.org/mirrors/sharp-libvips"
|
|
|
|
# Copy package files
|
|
COPY package.json package-lock.json ./
|
|
|
|
# Install dependencies with legacy peer deps and increased timeout
|
|
# Use --no-optional to skip optional dependencies that might cause issues
|
|
RUN npm config set fetch-timeout 600000 && \
|
|
npm config set fetch-retry-mintimeout 10000 && \
|
|
npm config set fetch-retry-maxtimeout 60000 && \
|
|
npm install --legacy-peer-deps --no-optional --verbose
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the Gatsby app
|
|
RUN npm run build
|
|
|
|
# Production stage with Nginx
|
|
FROM nginx:alpine AS production
|
|
|
|
# Create simple nginx config for Gatsby with client-side routing support
|
|
RUN echo 'server { listen 80; root /usr/share/nginx/html; index index.html; location / { try_files $uri $uri/ /index.html; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires 1y; add_header Cache-Control "public, immutable"; } }' > /etc/nginx/conf.d/default.conf
|
|
|
|
# Copy built Gatsby files (builds to 'public' directory)
|
|
COPY --from=build /app/public /usr/share/nginx/html
|
|
|
|
# Expose port 80
|
|
EXPOSE 80
|
|
|
|
# Start nginx
|
|
CMD ["nginx", "-g", "daemon off;"] |