TExcelTAD
Home › DevOps Capstone: Ship a Production Service › CI Against a Local Registry

CI Against a Local Registry

On the local track there is no GHCR, no cloud cluster and ideally no waiting for hosted runners while you iterate on the pipeline itself. This lesson closes the loop on your machine: a registry the kind (or k3d) cluster can pull from, the workflow run locally with act, and a policy check that keeps the workflow file itself honest.

A registry the cluster can pull from

Three options, from simplest to most realistic:

Option How Good for
kind load docker-image copies an image from your Docker daemon into every node quick tests; no registry at all
a registry container wired into kind registry:2 on localhost:5001, plus a containerd mirror setting on the nodes the real push/pull flow; kind's docs ship a script for it ("Local Registry" guide)
k3d's built-in registry k3d registry create + --registry-use the same flow in two commands

With k3d:

bash
$ k3d registry create linkly-registry.localhost --port 5001
INFO[0000] Creating node 'k3d-linkly-registry.localhost'
INFO[0000] Successfully created registry 'k3d-linkly-registry.localhost'
$ k3d cluster create linkly --agents 2 --registry-use k3d-linkly-registry.localhost:5001 \
    --k3s-arg "--disable=traefik@server:0"
$ docker tag linkly:1.4.0 localhost:5001/linkly:1.4.0
$ docker push localhost:5001/linkly:1.4.0

Inside the cluster the image is then k3d-linkly-registry.localhost:5001/linkly:1.4.0, which is what the chart's image.repository gets in the local environment's values. The Helm chart can go to the same registry as an OCI artifact (helm push linkly-1.0.0.tgz oci://localhost:5001/charts --plain-http), exactly as the OCI registries lesson did.

Running the workflow with act

act runs GitHub Actions workflows in Docker containers on your machine. It reads the same .github/workflows/ci.yml:

bash
$ act pull_request -j check --list
Stage  Job ID  Job name  Workflow name  Workflow file  Events
0      check   check     ci             ci.yml         pull_request,push

$ act pull_request -j check
[ci/check] 🚀  Start image=catthehacker/ubuntu:act-latest
[ci/check]   🐳  docker run image=postgres:16 ...
[ci/check] ⭐ Run Main actions/checkout@v7
[ci/check] ⭐ Run Main make lint test integration vuln build scan
| ok  	github.com/acme/linkly	1.217s
| No vulnerabilities found.
| built dist/linkly v1.4.0-1-g3c9e2d1-dirty
[ci/check]   ✅  Success - Main make lint test integration vuln build scan
[ci/check] 🏁  Job succeeded

What to expect from it:

  • act asks for a default runner image on first use; the medium catthehacker/ubuntu images are closest to GitHub's runners without being tens of gigabytes. Map a label explicitly with -P ubuntu-24.04=catthehacker/ubuntu:act-latest.
  • Secrets come from a file (--secret-file .secrets, git-ignored) or -s NAME. GITHUB_TOKEN is not provided automatically.
  • Jobs that push to GHCR or open pull requests in other repositories either need real credentials or should be skipped locally (-j check). Recent act releases start services: containers; if yours doesn't, start PostgreSQL and Redis yourself as in Running linkly Locally.
  • act is a rehearsal, not a guarantee: hosted runners have different preinstalled tools, caches and permissions. make ci (previous lesson) is the faster inner loop; act checks the YAML around it.

Checking the workflow itself

Workflow files are code with security consequences (Securing Workflows). A few rules are easy to check mechanically on every pull request, before a human reviews the file:

  1. Third-party actions are pinned to a full commit SHA; tags can be moved. Your organisation's own actions (acme/…) may use a tag.
  2. The workflow declares top-level permissions:; otherwise the token gets the repository default, which may be write-all.
  3. Every job has timeout-minutes (the default is six hours of billed runner time when something hangs).
  4. No pull_request_target trigger, which runs with secrets in the context of code from forks.

The session writes a short checker with yq and runs it against a compliant workflow and a careless one:

bash · try it yourself
mkdir -p .github/workflows bad/.github/workflows
cat > check-workflows.sh <<'X'
#!/usr/bin/env bash
# check-workflows.sh DIR: enforce the CI policy on every workflow in DIR/.github/workflows
set -uo pipefail
fail=0
for wf in "$1"/.github/workflows/*.yml; do
  name=$(basename "$wf")
  while read -r ref; do
    sha=${ref##*@}
    case "$ref" in ./*|acme/*) continue ;; esac            # local and in-house actions may use tags
    if [[ $sha =~ ^[0-9a-f]{7,39}$ ]]; then echo "$name: abbreviated SHA: $ref"; fail=1
    elif ! [[ $sha =~ ^[0-9a-f]{40}$ ]]; then echo "$name: not pinned to a commit SHA: $ref"; fail=1; fi
  done < <(yq '.jobs[].steps[]?.uses | select(. != null)' "$wf")
  [ "$(yq 'has("permissions")' "$wf")" = true ] || { echo "$name: no top-level permissions"; fail=1; }
  for job in $(yq '.jobs | to_entries | .[] | select(.value."timeout-minutes" == null) | .key' "$wf"); do
    echo "$name: job '$job' has no timeout-minutes"; fail=1
  done
  [ "$(yq '.on | has("pull_request_target")' "$wf")" = false ] || { echo "$name: uses pull_request_target"; fail=1; }
done
[ $fail -eq 0 ] && echo "$1: all workflows follow the policy"
exit $fail
X
chmod +x check-workflows.sh
cat > .github/workflows/ci.yml <<'X'
name: ci
on: {pull_request: {}, push: {branches: [main]}}
permissions: {contents: read}
jobs:
  check:
    runs-on: ubuntu-24.04
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@0123456789abcdef0123456789abcdef01234567 # v7.x.y (use the real SHA)
      - uses: acme/pipelines/actions/setup-tools@v3
      - run: make ci
X
cat > bad/.github/workflows/ci.yml <<'X'
name: ci
on: {pull_request_target: {}, push: {branches: [main]}}
jobs:
  check:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v7
      - uses: some-user/setup-everything@main
      - uses: aquasecurity/trivy-action@0e5f8a2c
      - run: make ci
X
./check-workflows.sh . ; echo "exit code: $?"
./check-workflows.sh bad ; echo "exit code: $?"
.: all workflows follow the policy
exit code: 0
ci.yml: not pinned to a commit SHA: actions/checkout@v7
ci.yml: not pinned to a commit SHA: some-user/setup-everything@main
ci.yml: abbreviated SHA: aquasecurity/trivy-action@0e5f8a2c
ci.yml: no top-level permissions
ci.yml: job 'check' has no timeout-minutes
ci.yml: uses pull_request_target
exit code: 1

The careless workflow fails on all four rules: two actions on movable refs (@v7, @main), one on an abbreviated SHA (abbreviations can collide), no permissions, no timeout, and a pull_request_target trigger. In CI, this script runs as the first step of the check job, or you adopt a maintained linter such as actionlint (syntax and expression checks) together with zizmor (security audit of workflows), which cover these rules and many more.

Note: The SHA in the compliant workflow is a placeholder that only shows the format; take real SHAs from the action's release page, or let Renovate/Dependabot pin and update them for you (both keep the # vX.Y.Z comment in sync).

Test yourself

Why should third-party actions be pinned to a full commit SHA rather than a tag like @v7?

  1. SHAs run faster
  2. A tag can be moved to different code by whoever controls the repository; a full SHA can't
  3. GitHub requires it
  4. Tags don't work with act

What is act good for?

  1. Replacing GitHub-hosted runners in production
  2. Running the workflow's jobs locally in containers to iterate on the YAML
  3. Deploying to the cluster
  4. Signing images

On k3d with --registry-use k3d-linkly-registry.localhost:5001, what image reference does the chart use inside the cluster?

  1. localhost:5001/linkly:1.4.0
  2. k3d-linkly-registry.localhost:5001/linkly:1.4.0
  3. docker.io/linkly:1.4.0
  4. linkly:1.4.0