+++ /dev/null
-# Maintainer: srv <mustafa@muszr.me>
-# geoauth: Traefik forward-auth by country from the RIR allocation files (see main.go). Static Go binary, no dependencies.
-pkgname=geoauth
-pkgver=0.1.0
-pkgrel=0
-pkgdesc="Forward-auth that admits clients by country"
-url="https://listdrop.muszr.me"
-arch="x86_64"
-license="MIT"
-makedepends="go"
-options="net"
-source="main.go main_test.go go.mod"
-builddir="$srcdir"
-
-build() {
- CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o geoauth .
-}
-
-check() {
- CGO_ENABLED=0 go test ./...
-}
-
-package() {
- install -Dm755 geoauth "$pkgdir"/usr/bin/geoauth
-}
-sha512sums=""
--- /dev/null
+# syntax=docker/dockerfile:1
+#
+# geoauth: the country forward-auth for the public ingress. Built by the Tekton pipeline `geoauth` (k8s/clusters/dev/ci/pipeline-geoauth.yaml)
+# when a tag geoauth-vX.Y.Z is pushed to srv; the image is registry.home.muszr.me/geoauth:vX.Y.Z.
+#
+# checks go vet and go test (fails the build)
+# geoauth the runtime image: a static binary and the CA bundle in scratch, no shell, no package manager, uid/gid 65532
+#
+# docker build --target geoauth -t geoauth images/geoauth (any target works locally too)
+
+ARG ALPINE=alpine:edge
+
+FROM ${ALPINE} AS build
+RUN apk add --no-cache go >/dev/null
+WORKDIR /src
+COPY go.mod main.go main_test.go ./
+ENV CGO_ENABLED=0 GOFLAGS=-trimpath
+
+FROM build AS checks
+RUN go vet ./... && go test ./...
+
+FROM build AS compile
+RUN go build -ldflags "-s -w" -o /out/geoauth .
+
+FROM ${ALPINE} AS rootfs
+RUN apk add --root /rootfs --initdb --no-cache --no-scripts --keys-dir /etc/apk/keys --repositories-file /etc/apk/repositories ca-certificates-bundle >/dev/null \
+ && rm -rf /rootfs/lib/apk /rootfs/var/cache /rootfs/etc/apk /rootfs/sbin/apk \
+ && echo "geoauth:x:65532:65532::/:/sbin/nologin" > /rootfs/etc/passwd \
+ && echo "geoauth:x:65532:" > /rootfs/etc/group
+
+FROM scratch AS geoauth
+COPY --from=rootfs /rootfs/ /
+COPY --from=compile /out/geoauth /usr/bin/geoauth
+USER 65532:65532
+ENTRYPOINT ["/usr/bin/geoauth"]
+++ /dev/null
-# geoauth: static Go binary; CA bundle for the HTTPS fetches. No shell, no package manager.
-contents:
- repositories:
- - https://dl-cdn.alpinelinux.org/alpine/edge/main
- - https://dl-cdn.alpinelinux.org/alpine/edge/community
- keyring:
- - https://alpinelinux.org/keys/alpine-devel@lists.alpinelinux.org-6165ee59.rsa.pub
- - https://alpinelinux.org/keys/alpine-devel@lists.alpinelinux.org-61666e3f.rsa.pub
- packages:
- - ca-certificates-bundle
- - musl # abuild's Go build is dynamically linked (no libc otherwise in a distroless image)
- - geoauth # ours (images/geoauth/APKBUILD)
-accounts:
- groups:
- - {groupname: geoauth, gid: 65532}
- users:
- - {username: geoauth, uid: 65532, gid: 65532}
- run-as: 65532
-entrypoint:
- command: /usr/bin/geoauth
-archs: [x86_64]