|
@ -36,6 +36,10 @@ |
|
|
# Environment Variables: |
|
|
# Environment Variables: |
|
|
# NODE_ENV: Build environment (development/production) |
|
|
# NODE_ENV: Build environment (development/production) |
|
|
# BUILD_MODE: Build mode for asset selection (development/test/production) |
|
|
# BUILD_MODE: Build mode for asset selection (development/test/production) |
|
|
|
|
|
# |
|
|
|
|
|
# Build Context: |
|
|
|
|
|
# This Dockerfile is designed to work when the build context is set to |
|
|
|
|
|
# ./crowd-funder-for-time-pwa from the parent directory (where docker-compose.yml is located) |
|
|
|
|
|
|
|
|
# ============================================================================= |
|
|
# ============================================================================= |
|
|
# BASE STAGE - Common dependencies and setup |
|
|
# BASE STAGE - Common dependencies and setup |
|
@ -62,6 +66,7 @@ RUN addgroup -g 1001 -S nodejs && \ |
|
|
WORKDIR /app |
|
|
WORKDIR /app |
|
|
|
|
|
|
|
|
# Copy package files for dependency installation |
|
|
# Copy package files for dependency installation |
|
|
|
|
|
# Note: These files are in the project root (crowd-funder-for-time-pwa directory) |
|
|
COPY package*.json ./ |
|
|
COPY package*.json ./ |
|
|
|
|
|
|
|
|
# Install dependencies with security audit |
|
|
# Install dependencies with security audit |
|
@ -82,6 +87,7 @@ ENV BUILD_MODE=${BUILD_MODE} |
|
|
ENV NODE_ENV=${NODE_ENV} |
|
|
ENV NODE_ENV=${NODE_ENV} |
|
|
|
|
|
|
|
|
# Copy pre-built assets from host |
|
|
# Copy pre-built assets from host |
|
|
|
|
|
# Note: dist/ directory is in the project root (crowd-funder-for-time-pwa directory) |
|
|
COPY dist/ ./dist/ |
|
|
COPY dist/ ./dist/ |
|
|
|
|
|
|
|
|
# Verify build output exists |
|
|
# Verify build output exists |
|
@ -107,23 +113,21 @@ RUN apk update && \ |
|
|
curl \ |
|
|
curl \ |
|
|
&& rm -rf /var/cache/apk/* |
|
|
&& rm -rf /var/cache/apk/* |
|
|
|
|
|
|
|
|
# Create non-root user for nginx |
|
|
# Use existing nginx user from base image (nginx user and group already exist) |
|
|
RUN addgroup -g 1001 -S nginx && \ |
|
|
# No need to create new user as nginx:alpine already has nginx user |
|
|
adduser -S nginx -u 1001 -G nginx |
|
|
|
|
|
|
|
|
|
|
|
# Copy appropriate nginx configuration based on build mode |
|
|
# Copy main nginx configuration |
|
|
COPY docker/nginx.conf /etc/nginx/nginx.conf |
|
|
COPY docker/nginx.conf /etc/nginx/nginx.conf |
|
|
COPY docker/default.conf /etc/nginx/conf.d/default.conf |
|
|
|
|
|
|
|
|
|
|
|
# Copy staging configuration if needed |
|
|
# Copy production nginx configuration |
|
|
COPY docker/staging.conf /etc/nginx/conf.d/staging.conf |
|
|
COPY docker/default.conf /etc/nginx/conf.d/default.conf |
|
|
|
|
|
|
|
|
# Copy built assets from builder stage |
|
|
# Copy built assets from builder stage |
|
|
COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html |
|
|
COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html |
|
|
|
|
|
|
|
|
# Create necessary directories with proper permissions |
|
|
# Create necessary directories with proper permissions |
|
|
RUN mkdir -p /var/cache/nginx /var/log/nginx /var/run && \ |
|
|
RUN mkdir -p /var/cache/nginx /var/log/nginx /tmp && \ |
|
|
chown -R nginx:nginx /var/cache/nginx /var/log/nginx /var/run && \ |
|
|
chown -R nginx:nginx /var/cache/nginx /var/log/nginx /tmp && \ |
|
|
chown -R nginx:nginx /usr/share/nginx/html |
|
|
chown -R nginx:nginx /usr/share/nginx/html |
|
|
|
|
|
|
|
|
# Switch to non-root user |
|
|
# Switch to non-root user |
|
@ -139,8 +143,6 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ |
|
|
# Start nginx with proper signal handling |
|
|
# Start nginx with proper signal handling |
|
|
CMD ["nginx", "-g", "daemon off;"] |
|
|
CMD ["nginx", "-g", "daemon off;"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============================================================================= |
|
|
# ============================================================================= |
|
|
# TEST STAGE - For test environment testing |
|
|
# TEST STAGE - For test environment testing |
|
|
# ============================================================================= |
|
|
# ============================================================================= |
|
|