htmgo/htmgo-site/Dockerfile

43 lines
1 KiB
Docker
Raw Normal View History

2024-09-21 17:20:35 +00:00
# Stage 1: Build the Go binary
2024-09-23 03:41:36 +00:00
FROM golang:1.23 AS builder
2024-09-21 17:20:35 +00:00
2024-09-21 18:14:51 +00:00
RUN apk update
2024-09-21 17:58:16 +00:00
RUN apk add git
2024-09-21 18:14:51 +00:00
RUN apk add curl
2024-09-21 17:58:16 +00:00
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
2024-09-22 15:46:38 +00:00
# Always download the latest version of the framework
RUN go get github.com/maddalax/htmgo/framework@latest
2024-09-21 17:20:35 +00:00
# Copy the source code into the container
COPY . .
2024-09-23 03:41:36 +00:00
RUN CGO_ENABLED=1 GOOS=linux go build -o ./dist -a -ldflags '-linkmode external -extldflags "-static"' .
2024-09-21 17:20:35 +00:00
# Build the Go binary for Linux
2024-09-23 03:41:36 +00:00
RUN CGO_ENABLED=0 GOPRIVATE=github.com/maddalax LOG_LEVEL=debug go run github.com/maddalax/htmgo/cli/htmgo@latest build
2024-09-21 17:20:35 +00:00
2024-09-21 18:33:35 +00:00
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
2024-09-21 18:22:31 +00:00
# Copy the Go binary from the builder stage
COPY --from=builder /app/dist .
2024-09-21 17:20:35 +00:00
# Expose the necessary port (replace with your server port)
EXPOSE 3000
2024-09-21 18:37:32 +00:00
2024-09-21 17:20:35 +00:00
# Command to run the binary
2024-09-21 18:22:31 +00:00
CMD ["./htmgo-site"]