34 lines
546 B
Docker
34 lines
546 B
Docker
# Build stage
|
|
FROM golang:1.21-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install dependencies
|
|
RUN apk add --no-cache git
|
|
|
|
# Copy go mod files
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bin/server cmd/server/main.go
|
|
|
|
# Final stage
|
|
FROM alpine:latest
|
|
|
|
RUN apk --no-cache add ca-certificates
|
|
|
|
WORKDIR /root/
|
|
|
|
# Copy the binary from builder
|
|
COPY --from=builder /app/bin/server .
|
|
|
|
# Expose port
|
|
EXPOSE 8080
|
|
|
|
# Run the binary
|
|
CMD ["./server"]
|