feat: Complete Docker infrastructure and CI/CD pipeline
Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
- Created production-ready Dockerfiles with multi-stage builds - Implemented complete CI/CD pipeline with GitHub Actions: - Automated testing for backend and frontend - Security scanning with Trivy - Docker image building and pushing to GHCR - Automated deployments to dev and production - Zero-downtime deployment strategy with rollback - Set up docker-compose for both development and production - Configured Nginx reverse proxy with SSL support - Domain configuration: - Development: maternal.noru1.ro:3005, maternal-api.noru1.ro:3015 - Production: parentflowapp.com, api.parentflowapp.com - Created comprehensive health check endpoints for monitoring - Updated port configuration for development environment - Added environment-specific configuration files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
81
maternal-web/Dockerfile.production
Normal file
81
maternal-web/Dockerfile.production
Normal file
@@ -0,0 +1,81 @@
|
||||
# Production Dockerfile for Maternal Web (Next.js 15)
|
||||
# Multi-stage build for security and optimization
|
||||
|
||||
# Stage 1: Dependencies
|
||||
FROM node:20-alpine AS deps
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
RUN npm ci --only=production
|
||||
|
||||
# Stage 2: Builder
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
|
||||
# Copy dependencies from deps stage
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY package*.json ./
|
||||
COPY tsconfig*.json ./
|
||||
COPY next.config.js ./
|
||||
|
||||
# Copy source code
|
||||
COPY app/ ./app/
|
||||
COPY components/ ./components/
|
||||
COPY contexts/ ./contexts/
|
||||
COPY hooks/ ./hooks/
|
||||
COPY lib/ ./lib/
|
||||
COPY locales/ ./locales/
|
||||
COPY public/ ./public/
|
||||
COPY styles/ ./styles/
|
||||
COPY types/ ./types/
|
||||
|
||||
# Set build-time environment variables
|
||||
ARG NEXT_PUBLIC_API_URL
|
||||
ARG NEXT_PUBLIC_GRAPHQL_URL
|
||||
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
|
||||
ENV NEXT_PUBLIC_GRAPHQL_URL=${NEXT_PUBLIC_GRAPHQL_URL}
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# Stage 3: Production Runner
|
||||
FROM node:20-alpine AS runner
|
||||
WORKDIR /app
|
||||
|
||||
# Install dumb-init for proper signal handling
|
||||
RUN apk add --no-cache dumb-init
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S nextjs -u 1001
|
||||
|
||||
# Set production environment
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
# Copy necessary files from builder
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
# Copy locales for i18n
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/locales ./locales
|
||||
|
||||
# Switch to non-root user
|
||||
USER nextjs
|
||||
|
||||
# Expose port (default 3000, configurable via PORT env var)
|
||||
EXPOSE 3000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD node -e "require('http').get('http://localhost:' + (process.env.PORT || 3000) + '/api/health', (r) => {r.statusCode === 200 ? process.exit(0) : process.exit(1)})"
|
||||
|
||||
# Use dumb-init to handle signals properly
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
# Start Next.js using the standalone server
|
||||
CMD ["node", "server.js"]
|
||||
@@ -1,13 +1,90 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
/**
|
||||
* Health check endpoint for network status detection
|
||||
* Returns 200 OK when the app is reachable
|
||||
* Health check endpoint for network status detection and monitoring
|
||||
* Returns 200 OK when the app is healthy
|
||||
* Supports detailed health checks with ?detailed=true
|
||||
*/
|
||||
export async function GET() {
|
||||
return NextResponse.json({ status: 'ok', timestamp: new Date().toISOString() });
|
||||
export async function GET(request: NextRequest) {
|
||||
const startTime = Date.now();
|
||||
|
||||
// Basic health check response
|
||||
const basicHealth = {
|
||||
status: 'healthy',
|
||||
timestamp: new Date().toISOString(),
|
||||
version: process.env.APP_VERSION || process.env.NEXT_PUBLIC_APP_VERSION || 'unknown',
|
||||
environment: process.env.NODE_ENV || 'unknown',
|
||||
};
|
||||
|
||||
// Check for detailed health check
|
||||
const isDetailed = request.nextUrl.searchParams.get('detailed') === 'true';
|
||||
|
||||
if (!isDetailed) {
|
||||
return NextResponse.json(basicHealth, { status: 200 });
|
||||
}
|
||||
|
||||
// Detailed health check
|
||||
const checks: Record<string, any> = {};
|
||||
|
||||
// Check memory usage
|
||||
const memUsage = process.memoryUsage();
|
||||
const memoryHealthy = memUsage.heapUsed < 150 * 1024 * 1024; // 150MB threshold
|
||||
checks.memory = {
|
||||
status: memoryHealthy ? 'healthy' : 'warning',
|
||||
heapUsed: Math.round(memUsage.heapUsed / 1024 / 1024) + 'MB',
|
||||
heapTotal: Math.round(memUsage.heapTotal / 1024 / 1024) + 'MB',
|
||||
rss: Math.round(memUsage.rss / 1024 / 1024) + 'MB',
|
||||
};
|
||||
|
||||
// Check API connectivity
|
||||
try {
|
||||
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'https://api.parentflowapp.com';
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
const apiStart = Date.now();
|
||||
const apiResponse = await fetch(`${apiUrl}/health`, {
|
||||
signal: controller.signal,
|
||||
cache: 'no-cache',
|
||||
});
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
checks.api = {
|
||||
status: apiResponse.ok ? 'healthy' : 'unhealthy',
|
||||
statusCode: apiResponse.status,
|
||||
responseTime: `${Date.now() - apiStart}ms`,
|
||||
url: apiUrl,
|
||||
};
|
||||
} catch (error) {
|
||||
checks.api = {
|
||||
status: 'unhealthy',
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
};
|
||||
}
|
||||
|
||||
// Check build info
|
||||
checks.build = {
|
||||
version: process.env.APP_VERSION || process.env.NEXT_PUBLIC_APP_VERSION || 'unknown',
|
||||
nodeVersion: process.version,
|
||||
uptime: Math.round(process.uptime()) + 's',
|
||||
};
|
||||
|
||||
// Overall health status
|
||||
const overallHealthy = memoryHealthy && checks.api?.status === 'healthy';
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
...basicHealth,
|
||||
status: overallHealthy ? 'healthy' : 'degraded',
|
||||
checks,
|
||||
responseTime: `${Date.now() - startTime}ms`,
|
||||
},
|
||||
{ status: overallHealthy ? 200 : 503 }
|
||||
);
|
||||
}
|
||||
|
||||
// Kubernetes liveness probe
|
||||
export async function HEAD() {
|
||||
return new NextResponse(null, { status: 200 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user