Merge pull request 'fix(ci): repair failing Gitea Actions (validate-flux + build-docs)' (#243) from fix/gitea-actions-failures into main
Validate Flux manifests / kustomize-build (push) Successful in 10s
Build Docs Site / Aggregate OpenAPI Specs (push) Successful in 1m15s

This commit was merged in pull request #243.
This commit is contained in:
2026-06-20 22:12:00 +00:00
6 changed files with 7807 additions and 12 deletions
+38 -8
View File
@@ -21,32 +21,38 @@ jobs:
with: with:
path: api-company path: api-company
# NOTE: cross-repo checkouts use SIBLING_REPOS_TOKEN, NOT the auto-injected
# GITEA_TOKEN. Gitea's automatic GITEA_TOKEN is scoped to THIS repo only,
# so checking out other repos fails with
# "Determining the default branch → not found". GITEA_TOKEN is also a
# reserved secret name that cannot be overridden, hence a separate secret.
# SIBLING_REPOS_TOKEN must be a PAT with read access to the API repos.
- name: Checkout zip-enrichment - name: Checkout zip-enrichment
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
repository: leeworks-agents/zip-enrichment repository: leeworks-agents/zip-enrichment
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.SIBLING_REPOS_TOKEN }}
path: zip-enrichment path: zip-enrichment
- name: Checkout holidays - name: Checkout holidays
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
repository: leeworks-agents/holidays repository: leeworks-agents/holidays
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.SIBLING_REPOS_TOKEN }}
path: holidays path: holidays
- name: Checkout air-quality - name: Checkout air-quality
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
repository: leeworks-agents/air-quality repository: leeworks-agents/air-quality
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.SIBLING_REPOS_TOKEN }}
path: air-quality path: air-quality
- name: Checkout vin-decoder - name: Checkout vin-decoder
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
repository: leeworks-agents/vin-decoder repository: leeworks-agents/vin-decoder
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.SIBLING_REPOS_TOKEN }}
path: vin-decoder path: vin-decoder
- name: Copy openapi.yaml specs into docs-site - name: Copy openapi.yaml specs into docs-site
@@ -72,15 +78,39 @@ jobs:
working-directory: api-company/docs-site working-directory: api-company/docs-site
run: npm run build run: npm run build
- name: Log in to container registry - name: Install Docker CLI
# The job container (node:20) ships no `docker` binary. The runner has a
# dind daemon (dind.enabled in the runner HelmRelease), reachable via
# DOCKER_HOST, so we only need the client. Install the static binary.
env:
DOCKER_CLI_VERSION: "27.3.1"
run: | run: |
echo "${{ secrets.GITEA_TOKEN }}" | docker login registry.leeworks.dev \ set -euxo pipefail
-u ${{ gitea.actor }} --password-stdin curl -fSL --retry 5 --retry-delay 3 --retry-all-errors \
-o /tmp/docker.tgz \
"https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz"
tar -xzf /tmp/docker.tgz -C /tmp
install -m 0755 /tmp/docker/docker /usr/local/bin/docker
docker version --format '{{.Client.Version}}'
docker info >/dev/null # confirms the dind daemon is reachable
- name: Log in to container registry
# Use Gitea's built-in container registry (gitea.leeworks.dev), which
# has a valid Let's Encrypt cert. The standalone registry.leeworks.dev
# serves Traefik's default self-signed cert and fails TLS verification.
#
# Auth uses REGISTRY_TOKEN, NOT the auto GITEA_TOKEN: the auto token has
# no package-registry scope, and the registry requires the username to
# match the token owner. REGISTRY_TOKEN must be a PAT (owner: 0xWheatyz)
# with write:package + read:package scope.
run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login gitea.leeworks.dev \
-u 0xWheatyz --password-stdin
- name: Build and push docs-site image - name: Build and push docs-site image
working-directory: api-company/docs-site working-directory: api-company/docs-site
run: | run: |
IMAGE="registry.leeworks.dev/leeworks-agents/docs-site" IMAGE="gitea.leeworks.dev/leeworks-agents/docs-site"
SHA="${{ gitea.sha }}" SHA="${{ gitea.sha }}"
docker build -t "$IMAGE:$SHA" -t "$IMAGE:latest" . docker build -t "$IMAGE:$SHA" -t "$IMAGE:latest" .
docker push "$IMAGE:$SHA" docker push "$IMAGE:$SHA"
+12 -2
View File
@@ -13,9 +13,19 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Install kustomize - name: Install kustomize
# The act runner runs as root (no `sudo`). Download a pinned release
# tarball directly with retries instead of piping the upstream installer
# script through bash — the installer makes extra GitHub API calls that
# are rate-limited/unreliable on this runner, and `curl -s` hid the
# error (a silent exit 6 = could not resolve host).
env:
KUSTOMIZE_VERSION: "5.4.3"
run: | run: |
curl -sL "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash set -euxo pipefail
sudo mv kustomize /usr/local/bin/ url="https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_amd64.tar.gz"
curl -fSL --retry 5 --retry-delay 3 --retry-all-errors -o /tmp/kustomize.tar.gz "$url"
tar -xzf /tmp/kustomize.tar.gz -C /usr/local/bin kustomize
kustomize version
- name: kustomize build flux/ - name: kustomize build flux/
run: kustomize build flux/ > /dev/null run: kustomize build flux/ > /dev/null
+7567
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -8,9 +8,9 @@
"preview": "astro preview" "preview": "astro preview"
}, },
"dependencies": { "dependencies": {
"astro": "^4.8.0",
"@astrojs/mdx": "^3.0.0", "@astrojs/mdx": "^3.0.0",
"@astrojs/sitemap": "^3.1.0", "@astrojs/sitemap": "~3.2.1",
"astro": "^4.8.0",
"redoc": "^2.1.5" "redoc": "^2.1.5"
}, },
"devDependencies": { "devDependencies": {
+120
View File
@@ -0,0 +1,120 @@
# Deploying the APIs (Flux GitOps → Talos)
> Handoff doc. The APIs are **not** deployed by Gitea Actions — they are deployed
> by **Flux** running on the Talos Kubernetes cluster. The Gitea Actions in this
> repo only build the docs-site image, validate Flux manifests, and publish
> OpenAPI specs to RapidAPI.
## How a deploy actually happens
```
API repo (e.g. leeworks-agents/zip-enrichment)
└─ its own CI builds & pushes registry.leeworks.dev/zip-enrichment/server:<tag>
└─ Flux image-automation (flux/image-automation/) rewrites the
{"$imagepolicy": "flux-system:<api>"} marker in flux/<api>/helmrelease.yaml
└─ Flux GitRepository "api-company" (polls main every 5m)
└─ HelmRelease per API (flux/<api>/helmrelease.yaml, bedag/raw chart)
└─ Deployment rolls out in the cluster namespace
```
Each API has its own directory under `flux/`:
| API | Namespace | HelmRelease path | Image |
|---|---|---|---|
| zip-enrichment | `zip-enrichment` | `flux/zip-enrichment/helmrelease.yaml` | `registry.leeworks.dev/zip-enrichment/server` |
| holidays | `holidays` | `flux/holidays/helmrelease.yaml` | `registry.leeworks.dev/holidays/server` |
| air-quality | `air-quality` | `flux/air-quality/helmrelease.yaml` | `registry.leeworks.dev/air-quality/server` |
| vin-decoder | `vin-decoder` | `flux/vin-decoder/helmrelease.yaml` | `registry.leeworks.dev/vin-decoder/server` |
(Confirm each path's exact image with `grep -r imagepolicy flux/`.)
## Prerequisite: the manifests must be live in the cluster's Flux source
`flux/api-company-source/gitrepository.yaml` is **reference only**. The
*authoritative* copy must be committed to **`0xWheatyz/Talos`** at:
```
testing1/first-cluster/cluster/flux/api-company/
```
If that path does not point Flux at this repo's `flux/` directory, Flux never
sees these HelmReleases and nothing deploys. Verify the Talos repo references
this repo's `main` branch and that a Flux `Kustomization` includes the
`api-company` path.
Per-API the cluster also needs (already templated under `flux/<api>/`):
- `namespace.yaml` — the target namespace
- the `gitea-registry` imagePullSecret in that namespace
- `externalsecret.yaml` — pulls API keys (e.g. RapidAPI) via external-secrets
- `servicemonitor.yaml` — Prometheus scraping (optional for deploy)
## One-time local setup (machine with cluster access)
You need tools that are **not** installed on the dev machine yet:
```bash
# Talos kubeconfig — export from the Talos controlplane, e.g.:
# talosctl kubeconfig ~/.kube/talos-leeworks
export KUBECONFIG=~/.kube/talos-leeworks
kubectl cluster-info # must succeed before continuing
# Flux CLI
brew install fluxcd/tap/flux
# Helm (optional, for debugging charts)
brew install helm
flux check # confirm Flux is installed & healthy in-cluster
```
## Deploy / sync all APIs
```bash
export KUBECONFIG=~/.kube/talos-leeworks
# 1. Pull the latest main into the cluster's Git source
flux reconcile source git api-company -n flux-system
# 2. Apply the manifests (name may differ — check: flux get kustomizations -A)
flux reconcile kustomization api-company -n flux-system
# 3. Reconcile each API's HelmRelease
flux reconcile helmrelease zip-enrichment -n zip-enrichment
flux reconcile helmrelease holidays -n holidays
flux reconcile helmrelease air-quality -n air-quality
flux reconcile helmrelease vin-decoder -n vin-decoder
# 4. Verify everything is Ready
flux get helmreleases -A
kubectl get pods -A | grep -E 'zip-enrichment|holidays|air-quality|vin-decoder'
```
## Troubleshooting
```bash
# Why is a release not Ready?
flux get helmrelease <name> -n <ns>
kubectl describe helmrelease <name> -n <ns>
# Is image automation picking up new tags?
flux get image policy -n flux-system
flux get image update -A
# Pod won't start (image pull / secret issues)
kubectl describe pod <pod> -n <ns>
kubectl get events -n <ns> --sort-by=.lastTimestamp | tail -20
```
## Force a fresh deploy of a single API
```bash
flux suspend helmrelease <name> -n <ns>
flux resume helmrelease <name> -n <ns> # triggers a fresh reconcile
# or restart the workload directly:
kubectl rollout restart deployment/<name> -n <ns>
```
## Related docs in this repo
- `docs/operator-runbook.md` — day-2 operations
- `docs/registry.md` — container registry (`registry.leeworks.dev`) setup
- `docs/secrets-checklist.md` — required cluster secrets
- `flux/image-automation/` — automatic image tag bumping
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# Create the Gitea PATs the build-docs workflow needs and store them as action
# secrets on leeworks-agents/api-company:
# - SIBLING_REPOS_TOKEN : read:repository (clone the sibling API repos)
# - REGISTRY_TOKEN : write:package + read:package
# (push the docs-site image to gitea.leeworks.dev)
#
# Why this script exists:
# - The auto-injected GITEA_TOKEN is scoped to THIS repo only (can't read
# sibling repos) and has no package-registry scope (can't push images).
# GITEA_TOKEN is also a reserved secret name that cannot be overridden.
# - `tea` cannot CREATE a PAT (no such command), and Gitea's token-creation
# API requires BASIC AUTH (your password) — a token cannot mint a token.
# - `tea` CAN set the action secrets using its existing login.
#
# So: this prompts for your password ONCE, mints both PATs via the API, and
# pipes each straight into `tea`. Token values are never written to disk.
#
# Usage: bash scripts/setup-sibling-repos-token.sh
set -euo pipefail
GITEA_URL="https://gitea.leeworks.dev"
GITEA_USER="0xWheatyz"
REPO="leeworks-agents/api-company"
# Unique per run (date + seconds + pid) so re-runs never collide with an
# existing PAT name — Gitea returns 400 "token name has been used" otherwise.
STAMP="$(date +%Y%m%d-%H%M%S)-$$"
command -v curl >/dev/null || { echo "curl required"; exit 1; }
command -v tea >/dev/null || { echo "tea required"; exit 1; }
command -v python3 >/dev/null || { echo "python3 required"; exit 1; }
echo "Gitea user: $GITEA_USER ($GITEA_URL)"
read -r -s -p "Gitea password (for $GITEA_USER): " GITEA_PASS
echo
failures=0
# mint_token <token-name> <json-scopes-array> <secret-name>
mint_token() {
local token_name="$1" scopes="$2" secret_name="$3" body code pat
# Capture body + HTTP status separately so 4xx errors show the real message.
body="$(curl -sS -o - -w $'\n%{http_code}' -X POST \
-u "${GITEA_USER}:${GITEA_PASS}" \
-H 'Content-Type: application/json' \
-d "{\"name\":\"${token_name}\",\"scopes\":${scopes}}" \
"${GITEA_URL}/api/v1/users/${GITEA_USER}/tokens")"
code="${body##*$'\n'}"
body="${body%$'\n'*}"
if [ "$code" -lt 200 ] || [ "$code" -ge 300 ]; then
echo "${secret_name}: token API returned HTTP ${code}: ${body}" >&2
echo " (401/403 = wrong password or 2FA; 400 = duplicate name or bad scope)" >&2
failures=$((failures+1)); return 1
fi
pat="$(printf '%s' "$body" | python3 -c 'import sys,json; print(json.load(sys.stdin)["sha1"])' 2>/dev/null || true)"
[ -n "$pat" ] || { echo "${secret_name}: could not parse token from: ${body}" >&2; failures=$((failures+1)); return 1; }
printf '%s' "$pat" | tea actions secrets create "$secret_name" --repo "$REPO" --stdin
echo "${secret_name} set (PAT '${token_name}')"
}
# Don't let one failure abort the rest.
mint_token "sibling-repos-readonly-${STAMP}" '["read:repository"]' "SIBLING_REPOS_TOKEN" || true
mint_token "docs-registry-${STAMP}" '["write:package","read:package"]' "REGISTRY_TOKEN" || true
unset GITEA_PASS
echo "Done (${failures} failure(s)). Verify: tea actions secrets list --repo ${REPO}"
echo "Then re-run build-docs (push to main, or: tea actions workflows dispatch build-docs.yaml)"
[ "$failures" -eq 0 ]