Initial commit
This commit is contained in:
commit
46bcafb9cb
3 changed files with 122 additions and 0 deletions
88
.forgejo/workflows/build-and-deploy.yaml
Normal file
88
.forgejo/workflows/build-and-deploy.yaml
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
# Reusable, language-agnostic build->push->deploy workflow. The app's
|
||||||
|
# Dockerfile owns the toolchain; this only needs docker + git + kustomize,
|
||||||
|
# which the `host` runner label provides (see the homelab repo's
|
||||||
|
# nixos/hosts/forgejo/default.nix hostPackages).
|
||||||
|
#
|
||||||
|
# Consumers:
|
||||||
|
# jobs:
|
||||||
|
# deploy:
|
||||||
|
# uses: nholtware/workflows/.forgejo/workflows/build-and-deploy.yaml@main
|
||||||
|
# with: { app-name: my-app }
|
||||||
|
# secrets: inherit
|
||||||
|
#
|
||||||
|
# Required Actions secrets (set once at user/org level):
|
||||||
|
# REGISTRY_USER / REGISTRY_TOKEN -- Forgejo PAT with write:package
|
||||||
|
# GITOPS_TOKEN -- Forgejo PAT with write access to the gitops repo
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
app-name:
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
context:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: "."
|
||||||
|
dockerfile:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: "Dockerfile"
|
||||||
|
gitops-repo:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: "nholtware/gitops"
|
||||||
|
secrets:
|
||||||
|
REGISTRY_USER:
|
||||||
|
required: true
|
||||||
|
REGISTRY_TOKEN:
|
||||||
|
required: true
|
||||||
|
GITOPS_TOKEN:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Terraform-pinned static IP of the forgejo host; containerd on the k3s
|
||||||
|
# nodes trusts exactly this registry string (nixos/modules/k3s-registries.nix).
|
||||||
|
REGISTRY: 192.168.1.230:3000
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-push:
|
||||||
|
runs-on: host
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Log in to Forgejo registry
|
||||||
|
env:
|
||||||
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||||
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
run: echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin
|
||||||
|
|
||||||
|
- name: Build and push image
|
||||||
|
run: |
|
||||||
|
TAG=$(echo "$GITHUB_SHA" | cut -c1-8)
|
||||||
|
IMAGE="$REGISTRY/${{ github.repository_owner }}/${{ inputs.app-name }}"
|
||||||
|
docker build -f "${{ inputs.dockerfile }}" \
|
||||||
|
--build-arg GIT_SHA="$TAG" \
|
||||||
|
-t "$IMAGE:$TAG" -t "$IMAGE:latest" "${{ inputs.context }}"
|
||||||
|
docker push "$IMAGE:$TAG"
|
||||||
|
docker push "$IMAGE:latest"
|
||||||
|
|
||||||
|
bump-gitops:
|
||||||
|
needs: build-push
|
||||||
|
runs-on: host
|
||||||
|
steps:
|
||||||
|
- name: Update image tag in gitops repo
|
||||||
|
env:
|
||||||
|
GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }}
|
||||||
|
run: |
|
||||||
|
TAG=$(echo "$GITHUB_SHA" | cut -c1-8)
|
||||||
|
IMAGE="$REGISTRY/${{ github.repository_owner }}/${{ inputs.app-name }}"
|
||||||
|
rm -rf gitops
|
||||||
|
git clone "http://ci-bot:${GITOPS_TOKEN}@192.168.1.230:3000/${{ inputs.gitops-repo }}.git" gitops
|
||||||
|
cd "gitops/manifests/${{ inputs.app-name }}"
|
||||||
|
kustomize edit set image "${{ inputs.app-name }}=$IMAGE:$TAG"
|
||||||
|
cd ../..
|
||||||
|
git config user.name "ci-bot"
|
||||||
|
git config user.email "ci-bot@forgejo.local"
|
||||||
|
git add -A
|
||||||
|
git commit -m "${{ inputs.app-name }}: deploy $TAG" || echo "no change to commit"
|
||||||
|
git push
|
||||||
21
.forgejo/workflows/node-checks.yaml
Normal file
21
.forgejo/workflows/node-checks.yaml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Reusable Node/TypeScript checks: install, lint (if present), test (if
|
||||||
|
# present). Runs in the docker-label container (node preinstalled).
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
node-version:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: "22"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checks:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ inputs.node-version }}
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run lint --if-present
|
||||||
|
- run: npm test --if-present
|
||||||
13
README.md
Normal file
13
README.md
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
# workflows
|
||||||
|
|
||||||
|
Reusable Forgejo Actions workflows for the homelab pipeline.
|
||||||
|
|
||||||
|
- `build-and-deploy.yaml` — language-agnostic: docker build -> push to the
|
||||||
|
Forgejo registry (`192.168.1.230:3000`) -> bump the image tag in
|
||||||
|
`nholtware/gitops` (ArgoCD takes it from there). Inputs: `app-name`
|
||||||
|
(required), `context`, `dockerfile`, `gitops-repo`.
|
||||||
|
- `node-checks.yaml` — optional TypeScript/Node checks: `npm ci`, lint,
|
||||||
|
test (each `--if-present`).
|
||||||
|
|
||||||
|
Secrets expected (user/org-level Actions secrets): `REGISTRY_USER`,
|
||||||
|
`REGISTRY_TOKEN` (write:package), `GITOPS_TOKEN` (write to gitops repo).
|
||||||
Loading…
Add table
Add a link
Reference in a new issue