# Build stage for Go backend FROM golang:1.21-alpine AS go-builder WORKDIR /app # Copy go mod and sum files COPY go.mod go.sum ./ # Download dependencies RUN go mod download # Copy source code and environment files COPY *.go ./ COPY .env* ./ # Build the application RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . # Build stage for React frontend FROM node:18-alpine AS frontend-builder WORKDIR /app/frontend # Copy package files COPY frontend/package*.json ./ # Install dependencies (including dev dependencies for build) RUN npm ci # Copy source code COPY frontend/ ./ # Build the React app RUN npm run build # Final stage FROM alpine:latest # Install ca-certificates for HTTPS requests RUN apk --no-cache add ca-certificates WORKDIR /root/ # Copy the Go binary from go-builder stage COPY --from=go-builder /app/main . # Copy environment files from go-builder stage COPY --from=go-builder /app/.env* ./ # Copy the React build from frontend-builder stage COPY --from=frontend-builder /app/frontend/build ./frontend/build # Create log directory with proper permissions RUN mkdir -p /app/logs && chmod 755 /app/logs # Expose port EXPOSE 8080 # Run the binary CMD ["./main"]