Add GitHub Actions CI and GoReleaser release
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci / pre-commit (pull_request) Has been cancelled
ci / lint (pull_request) Has been cancelled
ci / test (pull_request) Has been cancelled
ci / build (pull_request) Has been cancelled
ci / image (pull_request) Has been cancelled

This commit is contained in:
2026-11-20 22:11:39 +11:00
parent 29b3b1c6ba
commit 1f0d58e687
11 changed files with 199 additions and 200 deletions
+1
View File
@@ -0,0 +1 @@
* @IUCLabs/maintainers
+65
View File
@@ -0,0 +1,65 @@
name: ci
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
pre-commit:
runs-on: iuclabs-k8s
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- run: uvx pre-commit run --all-files --show-diff-on-failure
lint:
runs-on: iuclabs-k8s
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
- run: go vet ./...
test:
runs-on: iuclabs-k8s
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
# runner image has no C toolchain, so no -race
- run: go test -count=1 ./...
build:
runs-on: iuclabs-k8s
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
- run: go build -trimpath -ldflags="-s -w" ./...
image:
runs-on: iuclabs-k8s
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
- run: go run github.com/google/ko@v0.19.1 build --push=false --bare ./cmd/encapi
env:
GOTOOLCHAIN: auto
KO_DOCKER_REPO: ghcr.io/iuclabs/encapi
KO_DEFAULTBASEIMAGE: gcr.io/distroless/static-debian12:nonroot
+39
View File
@@ -0,0 +1,39 @@
name: release
on:
push:
tags: ["v*"]
permissions:
contents: write
id-token: write
packages: write
env:
VAULT_ADDR: https://vault.service.consul:8200
jobs:
release:
runs-on: iuclabs-release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
- uses: hashicorp/vault-action@892a26828f195e65540a40b4768ae4571f51ebfc # v4.0.0
with:
url: ${{ env.VAULT_ADDR }}
method: jwt
path: jwt/github/iuclabs
role: release
jwtGithubAudience: ${{ env.VAULT_ADDR }}
exportToken: true
- uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0
with:
distribution: goreleaser
version: v2.20.2
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+75
View File
@@ -0,0 +1,75 @@
version: 2
project_name: encapi
builds:
- &build
id: encapi-cli
main: ./cmd/encapi-cli
binary: encapi-cli
env:
- CGO_ENABLED=0
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{ .Tag }}
goos: [linux]
goarch: [amd64]
- <<: *build
id: encapi
main: ./cmd/encapi
binary: encapi
archives:
- formats: [none]
nfpms:
- package_name: encapi-cli
ids: [encapi-cli]
bindir: /usr/local/bin
formats: [rpm]
file_name_template: "{{ .ConventionalFileName }}"
release: "1"
section: default
priority: extra
description: CLI + Puppet ENC entrypoint for encapi (External Node Classifier)
maintainer: Ben Vincent <ben@unkin.net>
homepage: https://git.unkin.net/unkin/encapi
license: MIT
replaces: [encapi-cli]
provides: [encapi-cli]
contents:
- src: packaging/encapi-enc
dst: /usr/local/bin/encapi-enc
file_info:
mode: 0755
- src: packaging/enc.conf
dst: /etc/encapi/enc.conf
type: config|noreplace
file_info:
mode: 0644
scripts:
preinstall: packaging/scripts/preinstall.sh
kos:
- build: encapi
base_image: gcr.io/distroless/static-debian12:nonroot
repositories: [ghcr.io/iuclabs/encapi]
tags: ["{{ .Tag }}", latest]
bare: true
platforms: [linux/amd64]
sbom: none
labels:
org.opencontainers.image.source: https://github.com/IUCLabs/encapi
checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS"
algorithm: sha256
signs:
- artifacts: checksum
cmd: scripts/sign.sh
args: ["${artifact}", "${signature}"]
changelog:
disable: true
-18
View File
@@ -1,18 +0,0 @@
when:
- event: tag
ref: refs/tags/v*
steps:
- name: docker-encapi
image: artifactapi.k8s.syd1.au.unkin.net/docker-internal/plugin-docker-buildx:latest
settings:
registry: artifactapi.k8s.syd1.au.unkin.net
repo: artifactapi.k8s.syd1.au.unkin.net/docker-internal/encapi
build_args:
VERSION: ${CI_COMMIT_TAG}
buildkit_config: |
[registry."artifactapi.k8s.syd1.au.unkin.net"]
ca = ["/etc/docker/certs.d/artifactapi.k8s.syd1.au.unkin.net/ca.crt"]
tags:
- ${CI_COMMIT_TAG}
- latest
-85
View File
@@ -1,85 +0,0 @@
when:
- event: tag
# Builds the encapi-cli RPM and publishes it to the ArtifactAPI rpm-internal
# repo. The server image is built separately by docker.yaml.
steps:
- name: build
image: artifactapi.k8s.syd1.au.unkin.net/docker-internal/gobuilder:0.1.2-alma9
commands:
- make build-cli VERSION=${CI_COMMIT_TAG}
environment:
GOCACHE_S3_BUCKET: gocache
GOCACHE_S3_REGION: us-east-1
GOCACHE_S3_ENDPOINT_URL: https://s3.ceph.unkin.net
GOCACHE_S3_PATH_STYLE: "true"
GOCACHE_KEY_PREFIX: ci-encapi
GOCACHEPROG: go-cache-plugin --cache-dir=/tmp/gocache
AWS_ACCESS_KEY_ID:
from_secret: GOCACHE_AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: GOCACHE_AWS_SECRET_ACCESS_KEY
backend_options:
kubernetes:
serviceAccountName: default
resources:
requests:
memory: 1Gi
cpu: 1
limits:
memory: 3Gi
cpu: 2
- name: package
image: artifactapi.k8s.syd1.au.unkin.net/docker-internal/rpmbuilder:0.1.0-alma9
commands:
- ./scripts/build-rpm.sh ${CI_COMMIT_TAG}
depends_on: [build]
backend_options:
kubernetes:
serviceAccountName: default
resources:
requests:
memory: 512Mi
cpu: 1
limits:
memory: 2Gi
cpu: 2
- name: upload
image: git.unkin.net/unkin/almalinux9-base:20260606
commands:
- |
HOST="https://artifactapi.k8s.syd1.au.unkin.net"
REPO="rpm-internal"
set -o pipefail
VAULT="https://vault.service.consul:8200"
AUTH=$$(mktemp)
VT=$$(jq -n --rawfile jwt /var/run/secrets/kubernetes.io/serviceaccount/token '{role:"woodpecker_artifactapi_writer",jwt:$$jwt}' \
| curl -sf -d @- "$$VAULT/v1/auth/k8s/au/syd1/login" | jq -er .auth.client_token) || exit 1
printf 'X-Vault-Token: %s\n' "$$VT" | curl -sf -H @- "$$VAULT/v1/identity/oidc/token/artifactapi-writer" \
| jq -er '"Authorization: Bearer " + .data.token' > "$$AUTH" || exit 1
for rpm in dist/*.rpm; do
FILE=$$(basename "$$rpm")
code=$$(curl -s -o /dev/null -w '%{http_code}' "$$HOST/api/v2/remotes/$$REPO/files/Packages/$$FILE" || true)
if [ "$$code" = "200" ]; then
echo "$$FILE already exists in $$REPO (HTTP $$code); skipping upload"
continue
fi
echo "Uploading $$FILE to $$REPO (existence probe returned $$code)"
curl -f -X PUT \
"$$HOST/api/v2/remotes/$$REPO/files/$$FILE" \
-H "Content-Type: application/x-rpm" -H @"$$AUTH" \
--data-binary @"$$rpm"
done
depends_on: [package]
backend_options:
kubernetes:
serviceAccountName: default
resources:
requests:
memory: 128Mi
cpu: 100m
limits:
memory: 512Mi
cpu: 500m
+4 -6
View File
@@ -1,4 +1,4 @@
.PHONY: build build-server build-cli test test-short lint fmt e2e docker compose clean tidy rpm rpm-package check-go patch minor major
.PHONY: build build-server build-cli test test-short lint fmt e2e docker compose clean tidy rpm check-go patch minor major
MODULE := git.unkin.net/unkin/encapi
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.0.0-dev")
@@ -42,11 +42,9 @@ docker:
compose:
docker compose up -d
# --- CLI RPM (encapi-cli + the puppet ENC wrapper) ---
rpm: build-cli rpm-package
rpm-package:
./scripts/build-rpm.sh $(VERSION)
# Local snapshot of the release: encapi-cli RPM + encapi image (needs Docker).
rpm:
GOTOOLCHAIN=auto go run github.com/goreleaser/goreleaser/v2@v2.20.2 release --snapshot --clean --skip=sign
clean:
rm -rf bin/ $(DIST)/
+6 -5
View File
@@ -130,8 +130,9 @@ make test-short # skip container-backed DB tests
## Releases
- **`encapi` server image** — tagging `vX.Y.Z` builds and pushes
`artifactapi.k8s.syd1.au.unkin.net/docker-internal/encapi:{tag,latest}` (distroless).
- **`encapi-cli` RPM** — the same tag builds an RPM (nfpm) and publishes it to
the ArtifactAPI `rpm-internal` repo. Installs `encapi-cli`, the `encapi-enc`
Puppet wrapper, and `/etc/encapi/enc.conf`.
Tagging `vX.Y.Z` (`make patch|minor|major`) runs GoReleaser on GitHub Actions:
- **`encapi` server image** — `ghcr.io/iuclabs/encapi:{tag,latest}` (distroless, built with ko).
- **`encapi-cli` RPM** — attached to the GitHub release with a signed
`SHA256SUMS`. Installs `encapi-cli`, the `encapi-enc` Puppet wrapper, and
`/etc/encapi/enc.conf`.
-52
View File
@@ -1,52 +0,0 @@
---
# nfpm config for the encapi-cli RPM.
# Rendered through envsubst (see scripts/build-rpm.sh) then fed to `nfpm pkg`.
name: ${PACKAGE_NAME}
version: ${PACKAGE_VERSION}
release: ${PACKAGE_RELEASE}
arch: ${PACKAGE_ARCH}
platform: ${PACKAGE_PLATFORM}
section: default
priority: extra
description: "${PACKAGE_DESCRIPTION}"
maintainer: ${PACKAGE_MAINTAINER}
homepage: ${PACKAGE_HOMEPAGE}
license: ${PACKAGE_LICENSE}
disable_globbing: false
replaces:
- encapi-cli
provides:
- encapi-cli
contents:
# The CLI itself.
- src: dist/encapi-cli
dst: /usr/local/bin/encapi-cli
file_info:
mode: 0755
owner: root
group: root
# Puppet ENC entrypoint (external_nodes = /usr/local/bin/encapi-enc).
- src: packaging/encapi-enc
dst: /usr/local/bin/encapi-enc
file_info:
mode: 0755
owner: root
group: root
# Sample config; marked noreplace so local edits survive upgrades.
- src: packaging/enc.conf
dst: /etc/encapi/enc.conf
type: config|noreplace
file_info:
mode: 0644
owner: root
group: root
scripts:
preinstall: packaging/scripts/preinstall.sh
-34
View File
@@ -1,34 +0,0 @@
#!/usr/bin/env bash
#
# Package the (already built) encapi-cli binary into an RPM with nfpm.
# Usage: scripts/build-rpm.sh [version] (version defaults to $CI_COMMIT_TAG)
#
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${ROOT_DIR}"
VERSION="${1:-${CI_COMMIT_TAG:-0.0.0-dev}}"
VERSION="${VERSION#v}" # strip a leading v
DIST="dist"
if [ ! -f "${DIST}/encapi-cli" ]; then
echo "ERROR: ${DIST}/encapi-cli not found; run 'make build-cli' first" >&2
exit 1
fi
export PACKAGE_NAME="encapi-cli"
export PACKAGE_VERSION="${VERSION}"
export PACKAGE_RELEASE="1"
export PACKAGE_ARCH="amd64"
export PACKAGE_PLATFORM="linux"
export PACKAGE_DESCRIPTION="CLI + Puppet ENC entrypoint for encapi (External Node Classifier)"
export PACKAGE_MAINTAINER="Ben Vincent <ben@unkin.net>"
export PACKAGE_HOMEPAGE="https://git.unkin.net/unkin/encapi"
export PACKAGE_LICENSE="MIT"
envsubst < packaging/nfpm.yaml > "${DIST}/nfpm.yaml"
nfpm pkg --config "${DIST}/nfpm.yaml" --target "${DIST}" --packager rpm
echo "Built:"
ls -1 "${DIST}"/*.rpm
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Detached binary signature of $1 into $2 via the Vault gpg engine.
set -euo pipefail
b=$(base64 -w0 "$1")
jq -n --arg input "$b" '{input: $input, format: "base64"}' \
| curl -sSf --cacert "${VAULT_CACERT:-/etc/vault-ca/ca.crt}" \
-H "X-Vault-Token: ${VAULT_TOKEN}" -d @- \
"${VAULT_ADDR}/v1/gpg/sign/iuclabs-release" \
| jq -er .data.signature | base64 -d > "$2"