2024-09-30 21:05:06 +00:00
# Stage 1: Build the Go binary
2024-10-01 18:42:14 +00:00
FROM golang:1.23 AS builder
2024-09-30 21:05:06 +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-10-02 03:31:41 +00:00
RUN CGO_ENABLED = 0 GOPRIVATE = github.com/maddalax LOG_LEVEL = debug go run github.com/maddalax/htmgo/cli/htmgo@8b816e956692683337d9fff6416ccc31f5047b59 build
2024-10-01 18:42:14 +00:00
2024-10-02 03:39:30 +00:00
RUN CGO_ENABLED = 1 GOOS = linux go build -tags prod -o ./dist -a -ldflags '-linkmode external -extldflags "-static"' .
2024-09-30 21:05:06 +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/dist .
# Expose the necessary port (replace with your server port)
EXPOSE 3000
# Command to run the binary
2024-10-01 18:42:14 +00:00
CMD [ "./chat" ]