diff --git a/frontend/Dockerfile.development b/frontend/Dockerfile.development deleted file mode 100644 index 6069bda8..00000000 --- a/frontend/Dockerfile.development +++ /dev/null @@ -1,38 +0,0 @@ -# frontend/Dockerfile.development - FIXED VERSION -FROM node:18-alpine - -# Install curl for healthchecks -RUN apk add --no-cache curl - -# Set working directory -WORKDIR /app - -# Create non-root user for security but don't switch yet -RUN addgroup -g 1001 -S nodejs && \ - adduser -S reactjs -u 1001 -G nodejs - -# Copy package files first (better caching) -COPY package*.json ./ - -# Install all dependencies (including dev dependencies) as root -RUN npm ci --verbose && \ - npm cache clean --force - -# Copy source code -COPY . . - -# Change ownership of all files to the non-root user -RUN chown -R reactjs:nodejs /app - -# Now switch to non-root user -USER reactjs - -# Expose port 3000 (Vite default) -EXPOSE 3000 - -# Add healthcheck -HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ - CMD curl -f http://localhost:3000/ || exit 1 - -# Start development server with host binding -CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"] \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile.kubernetes similarity index 66% rename from frontend/Dockerfile rename to frontend/Dockerfile.kubernetes index 29619177..80350c42 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile.kubernetes @@ -1,5 +1,5 @@ -# Production Dockerfile for Frontend with Nginx -# Multi-stage build for optimal size and performance +# Kubernetes-optimized Dockerfile for Frontend +# Multi-stage build for production deployment # Stage 1: Build the application FROM node:18-alpine AS builder @@ -17,6 +17,7 @@ RUN npm ci --verbose && \ COPY . . # Build the application for production +# This will use environment variables available at build time RUN npm run build # Stage 2: Production server with Nginx @@ -34,7 +35,30 @@ COPY nginx.conf /etc/nginx/conf.d/ # Copy built application from builder stage COPY --from=builder /app/dist /usr/share/nginx/html -# Nginx user already exists in the base image, just ensure proper ownership +# Create a script to substitute environment variables at runtime +COPY <<'EOF' /docker-entrypoint.d/30-substitute-env.sh +#!/bin/sh +set -e + +# Default values for environment variables +export VITE_API_URL=${VITE_API_URL:-"http://gateway-service:8000"} +export VITE_APP_TITLE=${VITE_APP_TITLE:-"PanIA Dashboard"} +export VITE_APP_VERSION=${VITE_APP_VERSION:-"1.0.0"} + +# Create a runtime configuration file that can be loaded by the frontend +cat > /usr/share/nginx/html/runtime-config.js << EOL +window.__RUNTIME_CONFIG__ = { + VITE_API_URL: '${VITE_API_URL}', + VITE_APP_TITLE: '${VITE_APP_TITLE}', + VITE_APP_VERSION: '${VITE_APP_VERSION}' +}; +EOL + +echo "Runtime configuration created with API URL: ${VITE_API_URL}" +EOF + +# Make the script executable +RUN chmod +x /docker-entrypoint.d/30-substitute-env.sh # Set proper permissions RUN chown -R nginx:nginx /usr/share/nginx/html && \ @@ -65,7 +89,7 @@ EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ - CMD curl -f http://localhost:3000/ || exit 1 + CMD curl -f http://localhost:3000/health || exit 1 # Start nginx CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/frontend/Dockerfile.production b/frontend/Dockerfile.production deleted file mode 100644 index 98ba917c..00000000 --- a/frontend/Dockerfile.production +++ /dev/null @@ -1,41 +0,0 @@ -# frontend/Dockerfile.production -# Multi-stage build for production - -# Build stage -FROM node:18-alpine as builder - -WORKDIR /app - -# Copy package files -COPY package*.json ./ - -# Install dependencies -RUN npm ci --only=production - -# Copy source code -COPY . . - -# Build the application -RUN npm run build - -# Production stage -FROM nginx:alpine - -# Install curl for healthchecks -RUN apk add --no-cache curl - -# Copy built app from builder stage -COPY --from=builder /app/dist /usr/share/nginx/html - -# Copy nginx configuration -COPY nginx.conf /etc/nginx/nginx.conf - -# Expose port 80 -EXPOSE 80 - -# Add healthcheck -HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ - CMD curl -f http://localhost/ || exit 1 - -# Start nginx -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index e7d78224..86708766 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -22,6 +22,8 @@
+ +