2024-09-21 17:20:35 +00:00
|
|
|
# Stage 1: Build the Go binary
|
2024-09-21 17:24:55 +00:00
|
|
|
FROM golang:1.23-alpine AS builder
|
2024-09-21 17:20:35 +00:00
|
|
|
|
|
|
|
|
# Set the working directory inside the container
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Copy go.mod and go.sum files
|
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
|
|
|
|
|
|
# Download and cache the Go modules
|
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
|
|
# Copy the source code into the container
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
# Build the Go binary for Linux
|
2024-09-21 17:53:37 +00:00
|
|
|
RUN LOG_LEVEL=debug CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go run github.com/maddalax/htmgo/cli/htmgo@latest build
|
2024-09-21 17:20:35 +00:00
|
|
|
|
|
|
|
|
# Stage 2: Create the smallest possible image
|
|
|
|
|
FROM gcr.io/distroless/base-debian11
|
|
|
|
|
|
|
|
|
|
# Set the working directory inside the container
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Copy the Go binary from the builder stage
|
|
|
|
|
COPY --from=builder /app/server .
|
|
|
|
|
|
|
|
|
|
# Expose the necessary port (replace with your server port)
|
|
|
|
|
EXPOSE 3000
|
|
|
|
|
|
|
|
|
|
# Command to run the binary
|
|
|
|
|
CMD ["./server"]
|