# 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
# Copy the built binary from builder stage
COPY --from=builder /build/mkcert /usr/local/bin/mkcert
WORKDIR /root
# Default command is the mkcert binary; running the container with no args prints usage
ENTRYPOINT ["mkcert"]
# Ignore VCS and build/test related files .git node_modules vendor *.test *.log .DS_Store _build build *.exe *.dll *.so *.dylib *.md .Makefile **/tmp/**
Smoke [PASS]: mkcert example.test Smoke [FAIL]: test -f example.test.pem && test -f example.test-key.pem Output:
# 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"]
Concerns: The smoke test relies on mkcert generating files in the current directory; ensure the container user has write access to /workspace and that mkcert does not require additional setup (like -install) for this test to succeed in Alpine. Smoke [PASS]: rm -f test-cert.pem test-key.pem; mkcert -cert-file test-cert.pem -key-file test-key.pem localhost; [ -s test-cert.pem ] && [ -s test-key.pem ]