33 lines
842 B
Docker
33 lines
842 B
Docker
# Stage 1: Build the Go application
|
|
FROM golang:1.25-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
# Copy go.mod and go.sum files to download dependencies
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy the rest of the source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
# CGO_ENABLED=0 is important for a small static binary
|
|
# -o /app/server creates the binary in a known location
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/server ./cmd/server
|
|
|
|
# Stage 2: Create the final, small image
|
|
FROM alpine:latest
|
|
WORKDIR /app
|
|
|
|
# Copy the static assets and templates
|
|
COPY --from=builder /app/public/assets ./public/assets
|
|
COPY --from=builder /app/public/templates ./public/templates
|
|
|
|
# Copy the compiled binary from the builder stage
|
|
COPY --from=builder /app/server .
|
|
|
|
# Expose the port the app runs on
|
|
EXPOSE 8080
|
|
|
|
# Command to run the executable
|
|
CMD ["./server"]
|