# 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 COPY *.go ./ # 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 RUN npm ci --only=production # 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 the React build from frontend-builder stage COPY --from=frontend-builder /app/frontend/build ./frontend/build # Expose port EXPOSE 8080 # Run the binary CMD ["./main"]