30 lines
546 B
Docker
30 lines
546 B
Docker
FROM golang:1.20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy go module files first to leverage Docker cache
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy the source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -o voxpop-backend .
|
|
|
|
# Create a minimal production image
|
|
FROM alpine:latest
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy the binary from the builder stage
|
|
COPY --from=builder /app/voxpop-backend .
|
|
|
|
# Expose port 3000
|
|
EXPOSE 3000
|
|
|
|
# Set environment variables
|
|
ENV GIN_MODE=release
|
|
|
|
# Run the application
|
|
CMD ["./voxpop-backend"] |