# Build stage: compile mkcert for Linux (amd64) using a Go 1.18 Alpine-based image
FROM golang:1.18-alpine3.17 AS builder
WORKDIR /src
# Cache go module downloads
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source and build
COPY . .
ARG VERSION=devel
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -ldflags "-X main.Version=${VERSION}" -o /build/mkcert
# Runtime stage: minimal Alpine image with the statically linked binary
FROM alpine:3.22.4
RUN apk add --no-cache ca-certificates
# Create a working directory for the smoke tests and set as default
RUN mkdir -p /workspace
WORKDIR /workspace
# Copy the built binary from builder stage
COPY --from=builder /build/mkcert /usr/local/bin/mkcert
# Default command is the mkcert binary; running the container with no args prints usage
ENTRYPOINT ["mkcert"]