Merge pull request 'Add GitHub Actions CI and ko image release' (#13) from benvin/github-actions into main
ci / pre-commit (push) Has been cancelled
ci / lint (push) Has been cancelled
ci / test (push) Has been cancelled
ci / build (push) Has been cancelled
ci / image (push) Has been cancelled

Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
2026-11-20 23:59:20 +11:00
11 changed files with 113 additions and 205 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
VERSION: ci-${{ github.sha }}
+34
View File
@@ -0,0 +1,34 @@
name: release
on:
push:
tags: ["v[0-9]*"]
permissions:
contents: read
packages: write
jobs:
release:
runs-on: iuclabs-release
env:
KO_DOCKER_REPO: ghcr.io/iuclabs/encapi
VERSION: ${{ github.ref_name }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
- run: |
go install github.com/google/ko@v0.19.1
go install github.com/google/go-containerregistry/cmd/crane@v0.22.1
env:
GOTOOLCHAIN: auto
- run: echo "${GITHUB_TOKEN}" | crane auth login ghcr.io -u "${GITHUB_ACTOR}" --password-stdin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: >-
ko build --bare --sbom=none --platform linux/amd64 --tags "${VERSION}"
--image-label org.opencontainers.image.source=https://github.com/IUCLabs/encapi
./cmd/encapi
- run: crane tag "${KO_DOCKER_REPO}:${VERSION}" latest
+6
View File
@@ -0,0 +1,6 @@
defaultBaseImage: gcr.io/distroless/static-debian12:nonroot
builds:
- id: encapi
main: ./cmd/encapi
ldflags:
- -s -w -X main.version={{.Env.VERSION}}
-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
+1 -7
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 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,12 +42,6 @@ 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)
clean:
rm -rf bin/ $(DIST)/
+4 -6
View File
@@ -10,7 +10,7 @@ keeping Puppet's node-classification contract byte-compatible.
|-----------------|-----------------------------------------------------------------------|
| `encapi` | HTTP server: serves ENC documents + a read/write API. Postgres-backed. |
| `encapi-cli` | CLI over the API. `encapi-cli classify <host>` is the Puppet ENC. |
| `encapi-enc` | Thin wrapper (shipped in the RPM) for Puppet's `external_nodes`. |
| `encapi-enc` | Thin wrapper for Puppet's `external_nodes`. |
The Terraform provider lives in a sibling repo:
[`terraform-provider-encapi`](https://git.unkin.net/unkin/terraform-provider-encapi).
@@ -130,8 +130,6 @@ 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`) builds the `encapi` server image
with ko on GitHub Actions and pushes `ghcr.io/iuclabs/encapi:{tag,latest}`
(distroless).
+2 -3
View File
@@ -37,9 +37,8 @@ creates the derived status, role, and node.
## 2. Repoint the exec ENC (`profiles::puppet::cobbler_enc`)
Install the CLI RPM on the puppet masters (it ships `encapi-cli`,
`/usr/local/bin/encapi-enc`, and `/etc/encapi/enc.conf`), set
`ENCAPI_URL` in `/etc/encapi/enc.conf`, and point Puppet at the wrapper:
No `encapi-cli` RPM is published any more; `encapic` is the ENC client used
on every puppet master. The original exec wrapper setup was:
```
node_terminus = exec
-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