Skip to content
Hands-on IT IT Drills

Day 14: CI/CD with Gitea Actions

Goal: Change infrastructure only through pull requests: plan in the PR, apply after the merge, scheduled drift check – all on your own VM. · Duration: approx. 120 min · Prerequisite: Day 9, Day 13

Briefing

  • Gitea is a lean Git server with built-in CI, Gitea Actions. The workflow syntax largely matches that of GitHub Actions.
  • tea is the command line for Gitea – like gh for GitHub. Create a repository, open a PR, merge, view runs: one short command each.
  • A runner (act_runner) picks up jobs and executes them. In host mode, the steps run directly on the VM – with the tofu, conftest, and Docker that are already installed.
 Branch ─► pull request ─► plan.yml:   fmt, validate, plan, conftest, plan as comment
          review + merge ─► apply.yml:  apply on main
          daily 06:00   ─► drift.yml:  plan -detailed-exitcode → exit 2 = drift
  • The S3 storage from Day 9 still holds the state. The pipeline gets its credentials as repository secrets – not in the code.

Drill 1: Starting Gitea

source ~/tf-lab/setup/env.sh
docker volume create gitea-data
docker run -d --name gitea --restart unless-stopped -p 127.0.0.1:3000:3000 \
  -v gitea-data:/data \
  -e GITEA__security__INSTALL_LOCK=true \
  -e GITEA__server__ROOT_URL=http://127.0.0.1:3000/ \
  gitea/gitea:28.3.0
sleep 15
curl -s http://127.0.0.1:3000/api/v1/version; echo

Expected (the container ID differs):

gitea-data
5c1d0e7a9b3f...
{"version":"28.3.0"}
  • INSTALL_LOCK=true skips the setup wizard in the browser. Gitea then uses SQLite in the volume – just right for a lab.
  • If curl doesn’t answer yet, wait a few seconds and run it again.

Create an admin – with the gitea command inside the container:

docker exec -u git gitea gitea admin user create --admin --username lab \
  --password lab-gitea-pw-123 --email [email protected] --must-change-password=false

Expected:

New user 'lab' has been successfully created!

You can reach the web UI from your laptop through an SSH tunnel: ssh -L 3000:127.0.0.1:3000 ubuntu@<VM-IP>, then http://127.0.0.1:3000 in the browser, signing in as lab.

Save your progress? Sign up for free

Drill 2: Setting Up tea

curl -sSL -o ~/.local/bin/tea https://dl.gitea.com/tea/0.16.0/tea-0.16.0-linux-amd64
chmod +x ~/.local/bin/tea
tea --version | head -1

Expected:

Version: 0.16.0 golang: 1.26.6  go-sdk: v1.2.0

Log in. tea creates an API token by itself and stores it in ~/.config/tea/config.yml:

tea logins add --name lab --url http://127.0.0.1:3000 --user lab \
  --password lab-gitea-pw-123 | head -1
tea whoami

Expected (shortened):

Login as lab on http://127.0.0.1:3000 successful. Added this login as lab
NOTE: no login matched this repository, falling back to login 'lab' ...
  # lab (admin)
...

tea prints the NOTE message outside a repository: it then uses the only login it knows.

So that git push uses the token too, tea registers itself as a Git credential helper:

tea login helper setup
git config --global --get-regexp 'credential.*helper'

Expected (the first line may also read "lab" has already been added!):

Added "lab"
credential.http://127.0.0.1:3000.helper
credential.http://127.0.0.1:3000.helper !tea login helper

The first, empty line resets other helpers for this address. After that, Git asks tea for the token for http://127.0.0.1:3000 – no password in the remote URL.

Save your progress? Sign up for free

Drill 3: Setting Up the Runner

curl -sSL -o ~/.local/bin/act_runner \
  https://dl.gitea.com/act_runner/0.6.1/act_runner-0.6.1-linux-amd64
chmod +x ~/.local/bin/act_runner
act_runner --version
docker exec -u git gitea gitea actions generate-runner-token

Expected (the token differs):

act_runner version v0.6.1
Hj3kT0aQ9...

The registration token applies to the whole Gitea instance. You provide it once during registration:

mkdir -p ~/act_runner && cd ~/act_runner
RT=$(docker exec -u git gitea gitea actions generate-runner-token)
act_runner register --no-interactive --instance http://127.0.0.1:3000 \
  --token "$RT" --name lab-vm --labels host:host
ls -A

Expected:

level=info msg="Registering runner, arch=amd64, os=linux, version=v0.6.1."
level=warning msg="Runner in user-mode."
level=debug msg="Successfully pinged the Gitea instance server"
level=info msg="Runner registered successfully."
.runner
  • --labels host:host means: jobs with runs-on: host run directly on the VM (host mode). With ubuntu-latest:docker://… they would run in containers instead.
  • .runner contains the registration. Without this file, Gitea doesn’t know the runner.

The runner should run permanently, even without a logged-in user – as a systemd service of the user ubuntu:

sudo loginctl enable-linger ubuntu
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/act_runner.service <<'EOF'
[Unit]
Description=Gitea Actions Runner

[Service]
WorkingDirectory=%h/act_runner
ExecStart=%h/.local/bin/act_runner daemon
Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin
Restart=on-failure

[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now act_runner
systemctl --user is-active act_runner

Expected (the first line shortened):

Created symlink /home/ubuntu/.config/systemd/user/default.target.wants/act_runner…
active
  • enable-linger keeps user services running even when nobody is logged in.
  • Environment=PATH=… is important: the service reads neither .bashrc nor env.sh. Without ~/.local/bin in the path, a job wouldn’t find conftest.

Save your progress? Sign up for free

Drill 4: The Infrastructure Repository

The repository notes-infra describes a new environment ci on port 8096:

tea repos create --name notes-infra | sed -n 2p

Expected:

NOTE: no login matched this repository, falling back to login 'lab' ...
  # lab/notes-infra (empty)

Now the code – OpenTofu configuration, policy from Day 13, and .gitignore:

mkdir -p ~/tf-lab/tag14 && cd ~/tf-lab/tag14
git init -q -b main
sed 's|tag05/terraform.tfstate|tag14/ci.tfstate|' ~/tf-lab/tag05/backend.tf > backend.tf
cp ~/tf-lab/tag05/versions.tf .
mkdir -p policy && cp ~/tf-lab/policy/plan.rego policy/
cat > main.tf <<'EOF'
provider "docker" {}

variable "instanzen" {
  type    = set(string)
  default = ["a"]
}

module "notes" {
  source      = "git::file:///home/ubuntu/tf-lab/module//notes-docker?ref=v1.2.0"
  name        = "ci"
  port        = 8096
  instanzen   = var.instanzen
  db_passwort = "lab-db-pw-123"
}
EOF
printf '.terraform/\n*.plan\nplan.json\nplan.txt\n' > .gitignore
git remote add origin http://127.0.0.1:3000/lab/notes-infra.git
ls -A

Expected:

.git
.gitignore
backend.tf
main.tf
policy
versions.tf

The module comes via file:// – that works because the runner runs on the same VM. In real operations, this would be the HTTPS address of the module repository.

The pipeline needs the S3 credentials. They go into the repository as secrets – tea recognizes the repository from the remote origin:

tea actions secrets create AWS_ACCESS_KEY_ID "$AWS_ACCESS_KEY_ID"
tea actions secrets create AWS_SECRET_ACCESS_KEY "$AWS_SECRET_ACCESS_KEY"
tea actions secrets list -o simple

Expected (timestamps differ):

Secret 'AWS_ACCESS_KEY_ID' created successfully
Secret 'AWS_SECRET_ACCESS_KEY' created successfully
AWS_SECRET_ACCESS_KEY 2026-11-02T16:30:16Z
AWS_ACCESS_KEY_ID 2026-11-02T16:30:16Z

Gitea stores secrets encrypted, never shows them again, and replaces them in job logs with ***.

Save your progress? Sign up for free

Drill 5: Workflows for Plan and Apply

Workflows live in .gitea/workflows/. First the plan for pull requests:

mkdir -p .gitea/workflows
cat > .gitea/workflows/plan.yml <<'EOF'
name: plan
on: pull_request

jobs:
  plan:
    runs-on: host
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    steps:
      - name: Code holen
        run: |
          git init -q .
          git fetch -q "${{ gitea.server_url }}/${{ gitea.repository }}.git" \
            "${{ gitea.ref }}"
          git checkout -q FETCH_HEAD
      - name: Format und Validierung
        run: |
          tofu fmt -check -recursive
          tofu init -input=false -no-color
          tofu validate -no-color
      - name: Plan
        run: |
          tofu plan -input=false -no-color -out=pr.plan | tee plan.txt
          tofu show -json pr.plan > plan.json
      - name: Plan als Kommentar
        env:
          API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}
          PR: ${{ gitea.event.pull_request.number }}
        run: |
          jq -Rs '{body: ("~~~\n" + . + "~~~")}' < plan.txt > kommentar.json
          curl -sf -o /dev/null -H "Authorization: token ${{ gitea.token }}" \
            -H 'Content-Type: application/json' -d @kommentar.json \
            "$API/issues/$PR/comments"
      - name: Policy
        run: conftest test -p policy plan.json --no-color
EOF
  • Code holen (fetch the code) without actions/checkout: that action needs Node.js, which is missing on the VM. For a PR, gitea.ref is refs/pull/<n>/head. The repository is public, so git fetch works without logging in.
  • Plan als Kommentar (plan as a comment): jq -Rs reads the whole plan as one text and builds the JSON for the Gitea API from it. gitea.token is a short-lived token that Gitea hands to every run.
  • Policy comes last: even a rejected plan should be visible as a comment.

Then apply.yml for main:

cat > .gitea/workflows/apply.yml <<'EOF'
name: apply
on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  apply:
    runs-on: host
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    steps:
      - name: Code holen
        run: |
          git init -q .
          git fetch -q "${{ gitea.server_url }}/${{ gitea.repository }}.git" \
            "${{ gitea.sha }}"
          git checkout -q FETCH_HEAD
      - name: Apply
        run: |
          tofu init -input=false -no-color
          tofu apply -input=false -no-color -auto-approve
EOF

apply.yml fetches the commit via gitea.sha – exactly the one that was pushed. workflow_dispatch additionally allows starting it by hand.

Commit and push:

git add -A
git -c user.name=Lab -c [email protected] commit -qm "Umgebung ci"
git push -q -u origin main

Expected: no output. The push to main immediately starts apply.yml. The first run downloads providers and images and takes about a minute:

sleep 60
tea actions runs list -o simple

Expected (start time and duration differ):

1 completed Umgebung ci main push 2026-11-02 16:08 32s

Columns: run ID, status, commit message, branch, trigger, start, duration. If it still says running, wait and ask again. Whether the run succeeded is shown by view:

tea actions runs view 1 | grep -E '^(Conclusion|Workflow):'
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8096/healthz

Expected:

Conclusion: success
Workflow: Umgebung ci
200

The environment ci is running – created by the pipeline, not by you.

Save your progress? Sign up for free

Drill 6: A Change via Pull Request

The environment should get a second instance:

git switch -c zweite-instanz
sed -i 's/\["a"\]/["a", "b"]/' main.tf
git diff --stat
git -c user.name=Lab -c [email protected] commit -qam "Zweite Instanz"
git push -q -u origin zweite-instanz
tea pr create --head zweite-instanz --base main --title "Zweite Instanz" | sed -n 2p

Expected:

Switched to a new branch 'zweite-instanz'
 main.tf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
remote:
remote: Create a new pull request for 'zweite-instanz':
remote:   http://127.0.0.1:3000/lab/notes-infra/pulls/new/zweite-instanz
remote:
  # #1 Zweite Instanz (open)

Gitea sends the remote: lines for every new branch – but here the PR is created by tea pr create.

sleep 30
tea actions runs view 2 | grep -E '^(Conclusion|Event):'

Expected:

Conclusion: failure
Event: pull_request

The plan failed. The run’s log says why:

tea actions runs logs 2 | grep -oE 'Plan: .*|FAIL - .*'

Expected:

Plan: 2 to add, 0 to change, 1 to destroy.
FAIL - plan.json - main - module.notes.docker_container.proxy löscht – Freigabe nötig

The comment in the PR shows the full plan. Open http://127.0.0.1:3000/lab/notes-infra/pulls/1 in the browser: below the PR is the comment from gitea-actions with the plan, and below that the red status of the run.

That’s exactly what the rule is for: the proxy is replaced, so it’s briefly deleted. Here that’s fine – one second without a proxy in a CI environment. The approval is the deliberate merge despite the red policy:

tea pr merge 1
sleep 40
tea actions runs view 3 | grep -E '^(Conclusion|Event):'
docker ps --format '{{.Names}}' | grep '^ci-api-' | sort

Expected:

Conclusion: success
Event: push
ci-api-a
ci-api-b

In a real team, you protect main (branch protection): merge only with a green plan or with approval from a second person. You set that up in Gitea under Settings → Branches.

Save your progress? Sign up for free

Drill 7: Detecting Drift

Drift means: the real world deviates from the code because someone intervened by hand. A plan with -detailed-exitcode reports this via the exit code: 0 = nothing to do, 1 = error, 2 = changes.

git switch -q main
git pull -q
cat > .gitea/workflows/drift.yml <<'EOF'
name: drift
on:
  schedule:
    - cron: "0 6 * * *"
  workflow_dispatch:

jobs:
  drift:
    runs-on: host
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    steps:
      - name: Code holen
        run: |
          git init -q .
          git fetch -q "${{ gitea.server_url }}/${{ gitea.repository }}.git" main
          git checkout -q FETCH_HEAD
      - name: Drift prüfen
        run: |
          tofu init -input=false -no-color
          tofu plan -input=false -no-color -detailed-exitcode
EOF
git add -A
git -c user.name=Lab -c [email protected] commit -qm "Drift-Prüfung"
git push -q
sleep 40
tea actions runs list -o simple --limit 1

Expected:

4 completed Drift-Prüfung main push 2026-11-02 16:09 12s

The push started apply.yml again – without any change to the infrastructure. drift.yml would only run tomorrow at 6 a.m. (UTC). Now an intervention that bypasses the pipeline – and the drift check started by hand:

docker rm -f ci-api-b
tea actions workflows dispatch drift.yml --ref main --follow \
  | grep -oE 'Plan: .*|Job succeeded|Failure - .*'

Expected:

ci-api-b
Plan: 1 to add, 0 to change, 0 to destroy.
Failure - Main Drift prüfen

--follow shows the log while the job is running. A red drift run is the signal: someone worked around the pipeline. In real teams, the job then sends a message to the team chat.

The repair is an apply from the pipeline, also started by hand:

tea actions workflows dispatch apply.yml --ref main --follow \
  | grep -oE 'Apply complete.*|Job succeeded'
docker ps --format '{{.Names}}' | grep -c '^ci-api-'

Expected:

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Job succeeded
2

Save your progress? Sign up for free

Checkpoint

systemctl --user is-active act_runner

Expected:

active
tea actions runs list -o simple | wc -l

Expected: three pushes, one PR, two manual starts.

6
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8096/healthz

Expected:

200

Challenge

Start the drift check once more. Now it must be green.

Hint: The same command as in Drill 7. This time, look for No changes.

Solution

cd ~/tf-lab/tag14
tea actions workflows dispatch drift.yml --ref main --follow \
  | grep -oE 'No changes\..*|Job succeeded'

Expected:

No changes. Your infrastructure matches the configuration.
Job succeeded

Save your progress? Sign up for free

Enterprise Note

  • Apply the reviewed plan: Here, apply.yml plans again. It’s stricter to save the plan file from the PR as an artifact and apply exactly that. If main has changed in the meantime, OpenTofu rejects the old plan (“Saved plan is stale”).
  • Separate permissions: The runner for prod has its own credentials and only accepts jobs from protected branches. A PR from a fork must never get access to the prod secrets.
  • Tools with a PR workflow: Atlantis, Digger, or Spacelift provide the workflow shown here ready-made – with locks per directory and apply via comment. Once you’ve built the workflow yourself, you understand what they do.