31 lines
615 B
Docker
31 lines
615 B
Docker
|
|
# Build stage
|
||
|
|
FROM golang:1.26.5-alpine AS builder
|
||
|
|
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
# Install git and ca-certificates (needed for go modules and HTTPS)
|
||
|
|
RUN apk add --no-cache git ca-certificates
|
||
|
|
|
||
|
|
# Copy dependency files first for better layer caching
|
||
|
|
COPY go.mod go.sum ./
|
||
|
|
RUN go mod download
|
||
|
|
|
||
|
|
# Copy source code
|
||
|
|
COPY *.go ./
|
||
|
|
|
||
|
|
# Build a static binary
|
||
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o backend .
|
||
|
|
|
||
|
|
# Runtime stage
|
||
|
|
FROM alpine:latest
|
||
|
|
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
# Copy the binary from the builder stage
|
||
|
|
COPY --from=builder /app/backend .
|
||
|
|
|
||
|
|
# Expose the port Gin listens on
|
||
|
|
EXPOSE 8080
|
||
|
|
|
||
|
|
# Run the backend
|
||
|
|
CMD ["./backend"]
|