-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (55 loc) · 2.25 KB
/
Dockerfile
File metadata and controls
72 lines (55 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# syntax=docker/dockerfile:1
# =============================================================================
# Stage 1: Builder
# =============================================================================
FROM golang:1.26.2-alpine AS builder
# Build arguments for version info
ARG VERSION=dev
ARG COMMIT=unknown
# Install build dependencies
RUN apk add --no-cache \
ca-certificates \
git \
tzdata
WORKDIR /build
# Copy dependency files first for better layer caching
COPY go.mod go.sum ./
RUN go mod download && go mod verify
# Copy source code
COPY . .
# Build the binary with optimizations
# TARGETARCH is automatically set by Docker buildx for multi-platform builds
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH:-amd64} go build \
-tags dashboard \
-ldflags="-s -w -X main.Version=${VERSION} -X main.Commit=${COMMIT}" \
-trimpath \
-o mockd \
./cmd/mockd
# =============================================================================
# Stage 2: Production
# =============================================================================
FROM gcr.io/distroless/static-debian12:nonroot
# Labels for container metadata
LABEL org.opencontainers.image.title="mockd" \
org.opencontainers.image.description="High-performance API mocking engine" \
org.opencontainers.image.vendor="mockd" \
org.opencontainers.image.source="https://github.com/getmockd/mockd" \
io.modelcontextprotocol.server.name="io.mockd/mockd"
# Copy timezone data from builder (for time-based operations)
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
# Copy CA certificates for HTTPS requests
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy the binary from builder
COPY --from=builder /build/mockd /usr/local/bin/mockd
# Expose mock server and admin API ports
EXPOSE 4280 4290
# Health check against the admin API health endpoint
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD ["/usr/local/bin/mockd", "health", "--admin-port", "4290"]
# Run as nonroot user (provided by distroless)
USER nonroot:nonroot
# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/mockd"]
# Default command: start server with default ports
CMD ["start", "--port", "4280", "--admin-port", "4290"]