towerops/.forgejo
2026-02-03 13:55:19 -06:00
..
workflows add forgejo ci 2026-02-03 13:55:19 -06:00
README.md add forgejo ci 2026-02-03 13:55:19 -06:00

Forgejo Actions Configuration

This directory contains Forgejo Actions workflows (GitHub Actions-compatible) for CI/CD.

Migration from GitLab CI

The .forgejo/workflows/build-deploy.yml file replaces .gitlab-ci.yml with equivalent functionality:

Key Differences

GitLab CI Forgejo Actions
stages: jobs: (jobs run in dependency order)
tags: [home] runs-on: home
rules: on: (trigger conditions)
$CI_COMMIT_SHA ${{ github.sha }}
$CI_REGISTRY_IMAGE ${{ secrets.REGISTRY_URL }}/${{ github.repository }}
workflow.auto_cancel concurrency.cancel-in-progress
Docker-in-Docker service docker/build-push-action@v5

Required Secrets

Configure these in your Forgejo repository settings (Settings → Secrets):

  1. REGISTRY_URL - Container registry URL (e.g., registry.gitlab.com)
  2. REGISTRY_USER - Container registry username
  3. REGISTRY_PASSWORD - Container registry password/token

Required Runner Setup

The workflow assumes a self-hosted runner with label home that has:

  1. Docker - For building images
  2. kubectl - Pre-configured with cluster access
    • Context: towerops/towerops:home-cluster-agent must exist
    • Namespace: towerops with deployment named towerops

Workflow Stages

1. Build

  • Triggers on push to main branch
  • Checks out code
  • Logs into container registry
  • Builds Docker image using k8s/Dockerfile
  • Uses layer caching from :latest tag for faster builds
  • Pushes two tags:
    • <registry>/<repo>:<commit-sha> - Specific version
    • <registry>/<repo>:latest - Latest build

2. Deploy

  • Depends on successful build
  • Uses kubectl to update Kubernetes deployment
  • Sets image to the newly built commit SHA
  • Adds DEPLOY_TIMESTAMP environment variable
  • Lets Kubernetes handle rollout asynchronously

Testing the Workflow

To test without deploying:

# Validate workflow syntax
act --list -W .forgejo/workflows/build-deploy.yml

# Run build job locally (if act is installed)
act push -W .forgejo/workflows/build-deploy.yml -j build

Comparison to GitLab CI

Advantages:

  • Uses official Docker actions (more reliable layer caching)
  • Better concurrency control (auto-cancels old runs)
  • Clearer job dependencies with needs:

Equivalent Features:

  • Same Docker build process with BUILDKIT and caching
  • Same kubectl deployment commands
  • Same environment protection (production)
  • Same branch filtering (main only)

Troubleshooting

Build fails with registry authentication:

  • Verify REGISTRY_USER and REGISTRY_PASSWORD secrets are set
  • Check runner has network access to registry

Deploy fails with kubectl errors:

  • Verify runner has kubectl installed: kubectl version --client
  • Check kubeconfig context exists: kubectl config get-contexts
  • Verify cluster access: kubectl get deployments -n towerops

Runner not picking up jobs:

  • Verify runner is registered with label home
  • Check runner logs in Forgejo Actions settings
  • Ensure runner is online and connected