todoms_golang/Dockerfile.prod
2025-04-12 15:25:34 +07:00

46 lines
787 B
Docker

# Build stage
FROM golang:1.23.3-alpine AS builder
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git make
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build the application
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o main ./cmd/api
# Production stage
FROM alpine:latest
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/main .
# Copy SSL certificates
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Create necessary directories
RUN mkdir -p /app/logs
# Copy environment file
COPY .env.prod .env
# Expose port
EXPOSE 8080
# Set environment variables
ENV PORT=8080
ENV TZ=Asia/Ho_Chi_Minh
# Run the application
CMD ["./main"]