Skip to content

Deploying Woodpecker CI on AlmaLinux 9 with PostgreSQL, agent pool and Forgejo OAuth

Stand up a hardened Woodpecker CI server on AlmaLinux 9 — PostgreSQL backend, three-agent worker pool over gRPC, OAuth via Forgejo, nginx + Let's Encrypt in front.

The team has moved to Forgejo for code hosting and now needs CI that doesn’t shovel every commit to a public SaaS runner. Drone is in maintenance mode, Jenkins is the kind of project nobody volunteers to inherit, and Woodpecker is the active fork with a sane Docker-native pipeline syntax. You spin up the server container on a single VM, register the OAuth app on Forgejo, point the first repo at it — and the first three pipelines succeed. Two months later the agent pool is one container on the same VM as the server, every repo trusts every secret, the SQLite database hangs under concurrent runs, and the runners pull Docker images over the public mirror with no rate-limit protection. A serious CI plane is a different deployment.

What’s happening

A production Woodpecker deployment needs the server and the agents on separate hosts — agents pull source, build images, run user-controlled code; the server holds the OAuth secret and the database, and it must never execute pipeline steps. Persistence is PostgreSQL, never SQLite — concurrent pipelines write build status, log chunks, and queue state every second. The server signs agent registration with a shared secret (WOODPECKER_AGENT_SECRET) that must be rotatable without downtime — agents reconnect; in-flight pipelines are re-queued. OAuth goes to Forgejo (or the IdP you use), and only members of a specific Forgejo org are allowed to log in via WOODPECKER_ADMIN and the org filter. Secrets are scoped: org-level for shared keys (Docker Hub token, registry credentials), repo-level for tenant-specific tokens — never global. The agents need a local Docker daemon to run pipeline steps; they should be on a private VM with no public ingress, only outbound to the registry and the server’s gRPC port. Pipeline timeouts are required — without them a stuck container holds an agent slot forever and the queue drains to zero.

How to verify

Server host should expose only :22, :80, :443, and the gRPC port:

ss -lntp | grep -E ':(22|80|443|8000|9000|5432)\b'
# 0.0.0.0:22   sshd
# 0.0.0.0:443  nginx
# 0.0.0.0:9000 woodpecker-server (gRPC for agents)
# 127.0.0.1:8000 woodpecker-server (HTTP, behind nginx)

PostgreSQL on 5432 must not appear on the server host. Agent registration must be authenticated:

# From an agent host:
curl -sS https://ci.example.com/api/info | jq .version
# "2.7.x"
journalctl -u woodpecker-agent -n 50 | grep -i 'registered\|connected'
# Connected to server

Pipelines must time out on stuck containers:

docker exec -t $(docker ps -q --filter name=woodpecker-agent | head -1) \
  woodpecker-agent --help 2>&1 | grep -E 'WOODPECKER_TIMEOUT|MAX_WORKFLOWS'

If WOODPECKER_MAX_WORKFLOWS is empty, the agent will accept unbounded concurrent workflows — set it to the number of CPU cores. If a build hangs and the agent stays “busy” for hours, the timeout is missing.

The fix

This deployment uses two AlmaLinux 9 hosts: one server and one or more agents. Save the server script as /root/setup-woodpecker-server-alma9.sh on the server host, the agent script as /root/setup-woodpecker-agent-alma9.sh on each agent host. Both run as root and assume base AlmaLinux 9 with SSH key access.

Server installer

#!/usr/bin/env bash
set -euo pipefail

### AlmaLinux 9 Woodpecker CI server clean VM installer
### PostgreSQL 16 + Woodpecker server + nginx + Let's Encrypt
### Forgejo OAuth; server NEVER runs pipeline steps
### Agents register over :9000 gRPC with shared secret
### No local backups; assumes VM-level backup

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${WOODPECKER_DOMAIN:?Set WOODPECKER_DOMAIN=ci.example.com}"
: "${WOODPECKER_EMAIL:?Set WOODPECKER_EMAIL=ops@example.com for Let's Encrypt}"
: "${WOODPECKER_FORGEJO_URL:?Set WOODPECKER_FORGEJO_URL=https://git.example.com}"
: "${WOODPECKER_FORGEJO_CLIENT_ID:?Set WOODPECKER_FORGEJO_CLIENT_ID}"
: "${WOODPECKER_FORGEJO_CLIENT_SECRET:?Set WOODPECKER_FORGEJO_CLIENT_SECRET}"
: "${WOODPECKER_ADMIN:?Set WOODPECKER_ADMIN=opsadmin,jane,john}"
WOODPECKER_VERSION="${WOODPECKER_VERSION:-2.7.3}"
WOODPECKER_PG_PASSWORD="${WOODPECKER_PG_PASSWORD:-$(openssl rand -hex 24)}"
WOODPECKER_AGENT_SECRET="${WOODPECKER_AGENT_SECRET:-$(openssl rand -hex 32)}"

echo
echo "========================================"
echo "Woodpecker server AlmaLinux 9 Setup"
echo "========================================"
echo

echo "==> Updating base OS"
dnf -y update
dnf -y install epel-release
dnf -y install vim curl wget chrony fail2ban dnf-automatic \
  policycoreutils-python-utils lsof tcpdump bind-utils tar gzip \
  iproute net-tools openssl jq firewalld

systemctl enable --now chronyd

echo "==> SELinux enforcing"
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
setenforce 1 || true

echo "==> Kernel/network tuning"
cat > /etc/sysctl.d/99-woodpecker.conf <<'SYSCTL'
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 10240 65535
kernel.dmesg_restrict = 1
fs.file-max = 2097152
SYSCTL
sysctl --system

echo "==> Firewalld"
systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-port=9000/tcp
firewall-cmd --reload

echo "==> Hardening SSH"
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sshd -t && systemctl restart sshd

echo "==> fail2ban + automatic security updates"
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban

cat > /etc/dnf/automatic.conf <<'DNFAUTO'
[commands]
upgrade_type = security
random_sleep = 900
download_updates = yes
apply_updates = yes
[emitters]
emit_via = stdio
DNFAUTO
systemctl enable --now dnf-automatic.timer

echo "==> Installing Docker CE"
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker

echo "==> Preparing /opt/woodpecker"
mkdir -p /opt/woodpecker /var/lib/woodpecker/server
chmod 700 /var/lib/woodpecker

cat > /opt/woodpecker/.env <<ENV
WOODPECKER_VERSION=${WOODPECKER_VERSION}
WOODPECKER_DOMAIN=${WOODPECKER_DOMAIN}
PG_PASSWORD=${WOODPECKER_PG_PASSWORD}
AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
FORGEJO_URL=${WOODPECKER_FORGEJO_URL}
FORGEJO_CLIENT_ID=${WOODPECKER_FORGEJO_CLIENT_ID}
FORGEJO_CLIENT_SECRET=${WOODPECKER_FORGEJO_CLIENT_SECRET}
WOODPECKER_ADMIN=${WOODPECKER_ADMIN}
ENV

chmod 600 /opt/woodpecker/.env

cat > /opt/woodpecker/docker-compose.yml <<'COMPOSE'
services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: woodpecker
      POSTGRES_PASSWORD: ${PG_PASSWORD}
      POSTGRES_DB: woodpecker
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U woodpecker -d woodpecker"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 20s

  server:
    image: woodpeckerci/woodpecker-server:v${WOODPECKER_VERSION}
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      WOODPECKER_OPEN: "false"
      WOODPECKER_HOST: https://${WOODPECKER_DOMAIN}
      WOODPECKER_SERVER_ADDR: ":8000"
      WOODPECKER_GRPC_ADDR: ":9000"
      WOODPECKER_DATABASE_DRIVER: postgres
      WOODPECKER_DATABASE_DATASOURCE: postgres://woodpecker:${PG_PASSWORD}@postgres:5432/woodpecker?sslmode=disable
      WOODPECKER_AGENT_SECRET: ${AGENT_SECRET}
      WOODPECKER_ADMIN: ${WOODPECKER_ADMIN}
      WOODPECKER_FORGEJO: "true"
      WOODPECKER_FORGEJO_URL: ${FORGEJO_URL}
      WOODPECKER_FORGEJO_CLIENT: ${FORGEJO_CLIENT_ID}
      WOODPECKER_FORGEJO_SECRET: ${FORGEJO_CLIENT_SECRET}
      WOODPECKER_FORGEJO_SKIP_VERIFY: "false"
      WOODPECKER_LOG_LEVEL: info
      WOODPECKER_LOG_STORE: database
      WOODPECKER_DEFAULT_CLONE_IMAGE: woodpeckerci/plugin-git:2.5.2
      WOODPECKER_DEFAULT_WORKFLOW_LABELS: "platform=linux/amd64"
      WOODPECKER_ESCALATE: ""
      WOODPECKER_AUTHENTICATE_PUBLIC_REPOS: "true"
      WOODPECKER_DISABLE_USER_REGISTRATION: "true"
      WOODPECKER_SESSION_EXPIRES: "30d"
    volumes:
      - /var/lib/woodpecker/server:/var/lib/woodpecker
    ports:
      - "127.0.0.1:8000:8000"
      - "9000:9000"
    ulimits:
      nofile:
        soft: 64000
        hard: 64000

volumes:
  pgdata:
    driver: local
COMPOSE

echo "==> Starting Woodpecker server"
docker compose --env-file /opt/woodpecker/.env -f /opt/woodpecker/docker-compose.yml up -d

echo "==> Waiting for server on 127.0.0.1:8000"
for i in {1..120}; do
  if ss -lntp | grep -q '127.0.0.1:8000'; then
    break
  fi
  sleep 2
done

if ! ss -lntp | grep -q '127.0.0.1:8000'; then
  echo "Woodpecker server failed to listen"
  docker compose -f /opt/woodpecker/docker-compose.yml logs --tail=200 server || true
  exit 1
fi

echo "==> Installing nginx + certbot"
dnf -y install nginx certbot python3-certbot-nginx
setsebool -P httpd_can_network_connect 1 || true

cat > /etc/nginx/conf.d/woodpecker.conf <<NGINX
upstream woodpecker_backend {
    server 127.0.0.1:8000;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name ${WOODPECKER_DOMAIN};
    return 301 https://\$host\$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ${WOODPECKER_DOMAIN};

    client_max_body_size 100M;
    proxy_read_timeout   600s;
    proxy_send_timeout   600s;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location / {
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_http_version 1.1;
        proxy_pass http://woodpecker_backend;
    }
}
NGINX

# Remove the default server block from /etc/nginx/nginx.conf
sed -i '/^[[:space:]]*server[[:space:]]*{/,/^[[:space:]]*}$/d' /etc/nginx/nginx.conf || true

nginx -t
systemctl enable --now nginx

echo "==> Requesting Let's Encrypt certificate"
certbot --nginx --non-interactive --agree-tos \
  -m "${WOODPECKER_EMAIL}" -d "${WOODPECKER_DOMAIN}" --redirect

systemctl enable --now certbot.timer

echo "==> Waiting for HTTPS listener"
for i in {1..30}; do
  if ss -lntp | grep -q ':443'; then break; fi
  sleep 1
done

echo
echo "========================================"
echo "DONE — server"
echo "========================================"
echo
echo "Agent registration secret (give to each agent):"
echo "${WOODPECKER_AGENT_SECRET}"
echo
echo "Listeners:"
ss -lntp | grep -E ':(22|80|443|8000|9000)\b' || true
echo
echo "Containers:"
docker compose -f /opt/woodpecker/docker-compose.yml ps
echo
echo "Web UI:"
echo "https://${WOODPECKER_DOMAIN}/"
echo
echo "Next: run setup-woodpecker-agent-alma9.sh on each agent host with:"
echo "  WOODPECKER_SERVER=ci.example.com:9000"
echo "  WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}"

Agent installer

Save this as /root/setup-woodpecker-agent-alma9.sh on each agent host. Each agent needs a local Docker daemon to run pipeline steps; agents should sit on a private network and only egress to the server’s :9000 and to your container registry.

#!/usr/bin/env bash
set -euo pipefail

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${WOODPECKER_SERVER:?Set WOODPECKER_SERVER=ci.example.com:9000}"
: "${WOODPECKER_AGENT_SECRET:?Set WOODPECKER_AGENT_SECRET}"
WOODPECKER_VERSION="${WOODPECKER_VERSION:-2.7.3}"
WOODPECKER_MAX_WORKFLOWS="${WOODPECKER_MAX_WORKFLOWS:-$(nproc)}"

echo "==> Updating OS"
dnf -y update
dnf -y install epel-release
dnf -y install vim curl wget chrony fail2ban dnf-automatic firewalld jq

systemctl enable --now chronyd firewalld

firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload

sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sshd -t && systemctl restart sshd

dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker

mkdir -p /opt/woodpecker-agent /var/lib/woodpecker/agent

cat > /opt/woodpecker-agent/.env <<ENV
WOODPECKER_VERSION=${WOODPECKER_VERSION}
WOODPECKER_SERVER=${WOODPECKER_SERVER}
WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
WOODPECKER_MAX_WORKFLOWS=${WOODPECKER_MAX_WORKFLOWS}
ENV

chmod 600 /opt/woodpecker-agent/.env

cat > /opt/woodpecker-agent/docker-compose.yml <<'COMPOSE'
services:
  agent:
    image: woodpeckerci/woodpecker-agent:v${WOODPECKER_VERSION}
    restart: unless-stopped
    command: agent
    environment:
      WOODPECKER_SERVER: ${WOODPECKER_SERVER}
      WOODPECKER_AGENT_SECRET: ${WOODPECKER_AGENT_SECRET}
      WOODPECKER_GRPC_SECURE: "true"
      WOODPECKER_GRPC_VERIFY: "true"
      WOODPECKER_MAX_WORKFLOWS: ${WOODPECKER_MAX_WORKFLOWS}
      WOODPECKER_HEALTHCHECK: "true"
      WOODPECKER_BACKEND: docker
      WOODPECKER_BACKEND_DOCKER_VOLUMES: ""
      WOODPECKER_BACKEND_DOCKER_NETWORK: bridge
      WOODPECKER_LOG_LEVEL: info
    volumes:
      - /var/lib/woodpecker/agent:/etc/woodpecker
      - /var/run/docker.sock:/var/run/docker.sock
    ulimits:
      nofile:
        soft: 64000
        hard: 64000
COMPOSE

echo "==> Starting Woodpecker agent"
docker compose --env-file /opt/woodpecker-agent/.env -f /opt/woodpecker-agent/docker-compose.yml up -d

echo "==> Waiting for agent registration"
for i in {1..30}; do
  if docker compose -f /opt/woodpecker-agent/docker-compose.yml logs --tail=20 agent 2>/dev/null | grep -qi 'connected\|registered'; then
    break
  fi
  sleep 2
done

echo
echo "========================================"
echo "DONE — agent"
echo "========================================"
echo
echo "Container status:"
docker compose -f /opt/woodpecker-agent/docker-compose.yml ps
echo
echo "Recent logs:"
docker compose -f /opt/woodpecker-agent/docker-compose.yml logs --tail=30 agent
echo
echo "Max concurrent workflows for this agent: ${WOODPECKER_MAX_WORKFLOWS}"
echo "Confirm in the server UI: Settings -> Agents -> <hostname>"

Make both executable and run them in order — server first, then each agent:

# On the server host:
chmod 700 /root/setup-woodpecker-server-alma9.sh
WOODPECKER_DOMAIN=ci.example.com \
WOODPECKER_EMAIL=ops@example.com \
WOODPECKER_FORGEJO_URL=https://git.example.com \
WOODPECKER_FORGEJO_CLIENT_ID=$(cat /root/.woodpecker-forgejo-id) \
WOODPECKER_FORGEJO_CLIENT_SECRET=$(cat /root/.woodpecker-forgejo-secret) \
WOODPECKER_ADMIN=opsadmin,jane,john \
/root/setup-woodpecker-server-alma9.sh

# On each agent host, with the secret printed by the server script:
chmod 700 /root/setup-woodpecker-agent-alma9.sh
WOODPECKER_SERVER=ci.example.com:9000 \
WOODPECKER_AGENT_SECRET=<paste from server install> \
WOODPECKER_MAX_WORKFLOWS=4 \
/root/setup-woodpecker-agent-alma9.sh

Once both planes are up, visit https://ci.example.com/, authenticate via Forgejo, and confirm the admin users from WOODPECKER_ADMIN see the admin panel. Activate a test repo, push a .woodpecker.yml with a trivial echo step, and watch the pipeline land on an agent. If three agents are registered and a single pipeline keeps landing on the same one, check WOODPECKER_MAX_WORKFLOWS — the scheduler prefers idle slots, so a misconfigured agent that advertises 32 workflows will starve the others. Move /opt/woodpecker/.env to your secrets manager and confirm your VM-level backup covers /var/lib/woodpecker/server on the server host — pipeline history lives in PostgreSQL, but server-side config and uploaded files don’t.

For a CI plane you don’t have to operate yourself, our deployment management team runs Woodpecker (or your CI of choice) on managed cloud compute with patching, agent autoscaling, and pipeline failure escalation in place — start a scoping call.