-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (60 loc) · 3.03 KB
/
Copy pathDockerfile
File metadata and controls
72 lines (60 loc) · 3.03 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.6
# ---- build stage ------------------------------------------------------------
# --platform=$BUILDPLATFORM pins this stage to the build host's native
# architecture so we cross-compile (fast) instead of running the Go
# toolchain under QEMU emulation (slow). TARGETOS/TARGETARCH/TARGETVARIANT
# are populated by buildx from the --platform flag of `docker buildx build`.
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
WORKDIR /src
# Cache-friendly layer for module downloads.
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# CGO disabled → fully static binary, no glibc/musl dependency at
# runtime. GOARM is the ARM ISA level: arm/v6 → GOARM=6, arm/v7 →
# GOARM=7. The ${TARGETVARIANT#v} strip handles both.
ENV CGO_ENABLED=0
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=${TARGETVARIANT#v} \
go build \
-ldflags="-s -w -X main.version=$(git describe --tags --always 2>/dev/null || echo dev)" \
-trimpath \
-o /out/anchord \
./cmd/anchord
# ---- runtime stage ----------------------------------------------------------
# DHCP is pure-Go (github.com/insomniacslk/dhcp), so dhclient is no
# longer a runtime dependency. We still need conntrack-tools (for
# flushing stale entries on backend IP changes) and nftables/iproute2
# for diagnostics, so the runtime is Alpine rather than distroless.
#
# alpine:3.21 was chosen for its multi-arch coverage: it ships for
# linux/{amd64, arm64, arm/v7, arm/v6, 386, ppc64le, s390x, riscv64}
# — the same set anchord publishes via buildx.
FROM alpine:3.21
RUN apk add --no-cache \
conntrack-tools \
iproute2 \
nftables \
ca-certificates \
&& adduser -D -u 65532 -s /sbin/nologin anchord
COPY --from=build /out/anchord /usr/local/bin/anchord
# OCI image annotations — surface metadata on ghcr.io and in
# `docker inspect`. The build workflow's metadata-action overrides
# the version/created/revision triplet at push time; everything else
# stays static here so locally-built images carry the same labels.
LABEL org.opencontainers.image.title="anchord" \
org.opencontainers.image.description="Per-project network anchor for Docker Compose: joins an existing Docker macvlan network, optional DHCP refresh of the assigned IP, nftables DNAT to labelled service-anchors, real client source IPs preserved." \
org.opencontainers.image.source="https://github.com/AlexCherrypi/anchord" \
org.opencontainers.image.url="https://github.com/AlexCherrypi/anchord" \
org.opencontainers.image.documentation="https://github.com/AlexCherrypi/anchord#readme" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.authors="Alexander Kirsch" \
org.opencontainers.image.vendor="AlexCherrypi"
# anchord needs CAP_NET_ADMIN for nftables and (in dhcp-refresh mode)
# netlink address replacement on the iface Docker provided.
# It does NOT need to run as root — set the capabilities at compose
# level via cap_add.
USER root
ENTRYPOINT ["/usr/local/bin/anchord"]