-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathDockerfile
More file actions
52 lines (39 loc) · 1.98 KB
/
Copy pathDockerfile
File metadata and controls
52 lines (39 loc) · 1.98 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
# syntax=docker/dockerfile:1.7
#
# Multi-stage build:
# 1. Build pike from source so the image is reproducible from the checked-out SHA
# (no fetching the "latest" release at build time).
# 2. Ship a minimal Alpine runtime with a non-root user and only the tools
# entrypoint.sh actually needs.
# ---- builder ----------------------------------------------------------------
FROM golang:1.27.1-alpine3.24@sha256:cf6fca6641884b8433441b2b0652976f975e1d0fdd26d177eaaf8596087f3125 AS builder
WORKDIR /src
# Cache modules separately from source so dep-only changes don't bust the layer.
COPY go.mod go.sum ./
RUN go mod download
# Only the Go sources needed by the package build are copied into the image.
# Keeping the copy explicit avoids sending the entire build context into a layer.
COPY *.go ./
# Note: pike.Version is declared as a `const` in src/version.go, so it cannot
# be overridden at link time. Change it to a `var` if you want build-time
# version injection via `-ldflags -X`.
RUN CGO_ENABLED=0 go build \
-trimpath \
-ldflags "-s -w" \
-o /out/pike .
# ---- runtime ----------------------------------------------------------------
FROM alpine:3.24@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b
# entrypoint.sh needs bash; terraform/tofu flows often want git + ca-certificates.
RUN apk add --no-cache bash=5.2.37-r0 ca-certificates=20250619-r0 git=2.49.1-r0 \
&& adduser -D -u 10001 -h /home/pike pike
LABEL org.opencontainers.image.title="pike" \
org.opencontainers.image.description="Determine the minimum IAM permissions required to run OpenTofu/Terraform infrastructure code." \
org.opencontainers.image.source="https://github.com/JamesWoolfenden/pike" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.authors="JamesWoolfenden"
COPY --from=builder /out/pike /usr/bin/pike
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
USER pike
WORKDIR /home/pike
ENTRYPOINT ["/entrypoint.sh"]