htmgo/examples/todo-list/Dockerfile

36 lines
893 B
Docker
Raw Permalink Normal View History

2024-09-23 02:33:22 +00:00
# Stage 1: Build the Go binary
2024-09-23 03:08:56 +00:00
FROM golang:1.23 AS builder
2024-09-23 02:33:22 +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 . .
2024-09-23 03:41:36 +00:00
# Build the Go binary for Linux
RUN CGO_ENABLED=0 GOPRIVATE=github.com/maddalax LOG_LEVEL=debug go run github.com/maddalax/htmgo/cli/htmgo@latest build
2024-09-23 03:43:09 +00:00
RUN CGO_ENABLED=1 GOOS=linux go build -o ./dist -a -ldflags '-linkmode external -extldflags "-static"' .
2024-09-23 03:41:36 +00:00
2024-09-23 02:33:22 +00:00
# Stage 2: Create the smallest possible image
2024-09-23 03:43:09 +00:00
FROM gcr.io/distroless/base-debian11
2024-09-23 02:33:22 +00:00
# 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
CMD ["./todolist"]