Compare commits

...

3 Commits

Author SHA1 Message Date
52023081ab fix: Add retry logic to git operations in deploy-application-code.yml
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 30s
Security Vulnerability Scan / Check for Dependency Changes (push) Failing after 37s
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
Security Vulnerability Scan / Composer Security Audit (push) Has been skipped
🚀 Build & Deploy Image / Build Runtime Base Image (push) Failing after 13m31s
🚀 Build & Deploy Image / Build Docker Image (push) Has been cancelled
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been cancelled
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been cancelled
- Add retry logic (5 retries, 10s delay) to git clone and update tasks
- Handle 504 Gateway Timeout errors from Gitea gracefully
- Fail with clear error message if all retries are exhausted
- Prevents workflow failures due to temporary Gitea unavailability
2025-11-08 17:34:59 +01:00
43a06eae4d docs: Add documentation and playbooks for fixing Gitea runner configuration
- Add FIX_RUNNER_CONFIG.md with manual steps to re-register runner
- Add fix-gitea-runner-config.yml to diagnose runner issues
- Add register-gitea-runner.yml to re-register runner via Ansible
- Fixes issue where runner falls back to GitHub on 504 errors
2025-11-08 17:25:22 +01:00
21e7c40c99 feat: Add Ansible playbooks to fix Gitea runner configuration
- Add fix-gitea-runner-config.yml to diagnose runner configuration issues
- Add register-gitea-runner.yml to re-register runner with correct Gitea URL
- Check for GitHub URLs in runner configuration (should only use git.michaelschiemer.de)
- Verify .env file has correct GITEA_INSTANCE_URL
- Fixes 504 timeouts caused by runner trying to connect to GitHub fallback
2025-11-08 17:14:19 +01:00
4 changed files with 458 additions and 0 deletions

View File

@@ -68,6 +68,18 @@
GIT_TERMINAL_PROMPT: "0" GIT_TERMINAL_PROMPT: "0"
vars: vars:
ansible_become: no ansible_become: no
register: git_clone_result
retries: 5
delay: 10
until: git_clone_result is succeeded
ignore_errors: yes
- name: Fail if git clone failed after retries
fail:
msg: "Failed to clone repository after 5 retries. Gitea may be unreachable or overloaded. Last error: {{ git_clone_result.msg | default('Unknown error') }}"
when:
- not git_repo_exists.stat.exists
- git_clone_result is failed
- name: Update repository (if exists) - name: Update repository (if exists)
ansible.builtin.git: ansible.builtin.git:
@@ -81,6 +93,18 @@
GIT_TERMINAL_PROMPT: "0" GIT_TERMINAL_PROMPT: "0"
vars: vars:
ansible_become: no ansible_become: no
register: git_update_result
retries: 5
delay: 10
until: git_update_result is succeeded
ignore_errors: yes
- name: Fail if git update failed after retries
fail:
msg: "Failed to update repository after 5 retries. Gitea may be unreachable or overloaded. Last error: {{ git_update_result.msg | default('Unknown error') }}"
when:
- git_repo_exists.stat.exists
- git_update_result is failed
- name: Set ownership of repository files - name: Set ownership of repository files
file: file:

View File

@@ -0,0 +1,200 @@
---
- name: Fix Gitea Runner Configuration
hosts: production
gather_facts: yes
become: no
vars:
gitea_runner_path: "{{ runner_path | default('/home/deploy/deployment/gitea-runner') }}"
gitea_instance_url: "https://git.michaelschiemer.de"
runner_container_name: "gitea-runner"
tasks:
- name: Check if Gitea runner directory exists
stat:
path: "{{ gitea_runner_path }}"
register: runner_dir_exists
- name: Fail if runner directory does not exist
fail:
msg: "Gitea runner directory not found at {{ gitea_runner_path }}"
when: not runner_dir_exists.stat.exists
- name: Check if runner container is running
shell: |
docker ps --format json | jq -r 'select(.Names == "{{ runner_container_name }}") | .State'
register: runner_container_state
changed_when: false
failed_when: false
- name: Display runner container status
debug:
msg: |
Runner Container Status: {{ runner_container_state.stdout | default('NOT RUNNING') }}
- name: Check if .runner file exists
stat:
path: "{{ gitea_runner_path }}/data/.runner"
register: runner_file_exists
- name: Read .runner file content (if exists)
slurp:
src: "{{ gitea_runner_path }}/data/.runner"
register: runner_file_content
when: runner_file_exists.stat.exists
changed_when: false
- name: Display .runner file content
debug:
msg: |
Runner Registration File Content:
{{ runner_file_content.content | b64decode | default('File not found') }}
when: runner_file_exists.stat.exists
- name: Check for GitHub URLs in .runner file
shell: |
grep -i "github.com" "{{ gitea_runner_path }}/data/.runner" 2>/dev/null || echo "NO_GITHUB_URLS"
register: github_urls_check
when: runner_file_exists.stat.exists
changed_when: false
failed_when: false
- name: Display GitHub URLs check result
debug:
msg: |
GitHub URLs in .runner file: {{ github_urls_check.stdout }}
- name: Check runner logs for incorrect URLs
shell: |
docker logs {{ runner_container_name }} --tail=100 2>&1 | grep -E "(github.com|instance|repo)" || echo "NO_MATCHES"
register: runner_logs_check
changed_when: false
failed_when: false
- name: Display runner logs analysis
debug:
msg: |
Runner Logs Analysis (last 100 lines):
{{ runner_logs_check.stdout }}
- name: Check .env file for GITEA_INSTANCE_URL
shell: |
grep "^GITEA_INSTANCE_URL=" "{{ gitea_runner_path }}/.env" 2>/dev/null || echo "NOT_FOUND"
register: env_instance_url
changed_when: false
failed_when: false
- name: Display GITEA_INSTANCE_URL from .env
debug:
msg: |
GITEA_INSTANCE_URL in .env: {{ env_instance_url.stdout }}
- name: Check if .env has correct Gitea URL
set_fact:
env_has_correct_url: "{{ env_instance_url.stdout is defined and gitea_instance_url in env_instance_url.stdout }}"
- name: Check if runner needs re-registration
set_fact:
runner_needs_reregistration: >-
{%- if not runner_file_exists.stat.exists -%}
true
{%- elif 'github.com' in (github_urls_check.stdout | default('')) -%}
true
{%- elif not env_has_correct_url -%}
true
{%- else -%}
false
{%- endif -%}
- name: Display re-registration decision
debug:
msg: |
Runner Re-registration Needed: {{ runner_needs_reregistration | bool }}
Reasons:
- Runner file exists: {{ runner_file_exists.stat.exists }}
- Contains GitHub URLs: {{ 'github.com' in (github_urls_check.stdout | default('')) }}
- .env has correct URL: {{ env_has_correct_url | bool }}
- name: Stop runner container before re-registration
shell: |
cd {{ gitea_runner_path }}
docker compose stop {{ runner_container_name }}
when: runner_needs_reregistration | bool
register: stop_runner
changed_when: stop_runner.rc == 0
- name: Backup existing .runner file
copy:
src: "{{ gitea_runner_path }}/data/.runner"
dest: "{{ gitea_runner_path }}/data/.runner.backup.{{ ansible_date_time.epoch }}"
remote_src: yes
when:
- runner_file_exists.stat.exists
- runner_needs_reregistration | bool
- name: Remove existing .runner file
file:
path: "{{ gitea_runner_path }}/data/.runner"
state: absent
when: runner_needs_reregistration | bool
- name: Update .env file with correct GITEA_INSTANCE_URL
lineinfile:
path: "{{ gitea_runner_path }}/.env"
regexp: '^GITEA_INSTANCE_URL='
line: "GITEA_INSTANCE_URL={{ gitea_instance_url }}"
create: yes
when: runner_needs_reregistration | bool
register: env_updated
- name: Display instructions for manual re-registration
debug:
msg: |
========================================
Runner Re-registration Required
========================================
The runner needs to be re-registered with the correct Gitea instance URL.
Steps to re-register:
1. Get a new registration token from Gitea:
{{ gitea_instance_url }}/admin/actions/runners
Click "Create New Runner" and copy the token
2. Update .env file with the token:
GITEA_RUNNER_REGISTRATION_TOKEN=<your-token>
3. Re-register the runner:
cd {{ gitea_runner_path }}
./register.sh
Or use Ansible to set the token and register:
ansible-playbook -i inventory/production.yml \
playbooks/register-gitea-runner.yml \
-e "runner_registration_token=<your-token>"
========================================
when: runner_needs_reregistration | bool
- name: Display final status
debug:
msg: |
========================================
Gitea Runner Configuration Status
========================================
Runner Directory: {{ gitea_runner_path }}
Container Running: {{ 'YES' if runner_container_state.stdout == 'running' else 'NO' }}
Runner File Exists: {{ 'YES' if runner_file_exists.stat.exists else 'NO' }}
Contains GitHub URLs: {{ 'YES' if 'github.com' in (github_urls_check.stdout | default('')) else 'NO' }}
.env has correct URL: {{ 'YES' if env_has_correct_url else 'NO' }}
Re-registration Needed: {{ 'YES' if runner_needs_reregistration | bool else 'NO' }}
========================================
{% if not runner_needs_reregistration | bool %}
✅ Runner configuration looks correct!
{% else %}
⚠️ Runner needs to be re-registered with correct Gitea URL
{% endif %}

View File

@@ -0,0 +1,142 @@
---
- name: Register Gitea Runner with Correct Instance URL
hosts: production
gather_facts: yes
become: no
vars:
gitea_runner_path: "{{ runner_path | default('/home/deploy/deployment/gitea-runner') }}"
gitea_instance_url: "https://git.michaelschiemer.de"
runner_registration_token: "{{ runner_registration_token | default('') }}"
runner_name: "{{ runner_name | default('dev-runner-01') }}"
runner_labels: "{{ runner_labels | default('ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,php-ci:docker://php-ci:latest') }}"
runner_container_name: "gitea-runner"
tasks:
- name: Fail if registration token is not provided
fail:
msg: "runner_registration_token must be provided via -e 'runner_registration_token=<token>'"
when: runner_registration_token | string | trim == ''
- name: Check if Gitea runner directory exists
stat:
path: "{{ gitea_runner_path }}"
register: runner_dir_exists
- name: Fail if runner directory does not exist
fail:
msg: "Gitea runner directory not found at {{ gitea_runner_path }}"
when: not runner_dir_exists.stat.exists
- name: Stop runner container if running
shell: |
cd {{ gitea_runner_path }}
docker compose stop {{ runner_container_name }}
register: stop_result
changed_when: stop_result.rc == 0
failed_when: false
- name: Backup existing .runner file
copy:
src: "{{ gitea_runner_path }}/data/.runner"
dest: "{{ gitea_runner_path }}/data/.runner.backup.{{ ansible_date_time.epoch }}"
remote_src: yes
when: runner_file_exists.stat.exists
register: runner_file_exists
ignore_errors: yes
- name: Check if .runner file exists
stat:
path: "{{ gitea_runner_path }}/data/.runner"
register: runner_file_exists
- name: Remove existing .runner file
file:
path: "{{ gitea_runner_path }}/data/.runner"
state: absent
when: runner_file_exists.stat.exists
- name: Update .env file with correct configuration
lineinfile:
path: "{{ gitea_runner_path }}/.env"
regexp: '^{{ item.key }}='
line: "{{ item.key }}={{ item.value }}"
create: yes
loop:
- { key: 'GITEA_INSTANCE_URL', value: '{{ gitea_instance_url }}' }
- { key: 'GITEA_RUNNER_REGISTRATION_TOKEN', value: '{{ runner_registration_token }}' }
- { key: 'GITEA_RUNNER_NAME', value: '{{ runner_name }}' }
- { key: 'GITEA_RUNNER_LABELS', value: '{{ runner_labels }}' }
no_log: true
- name: Start runner services
shell: |
cd {{ gitea_runner_path }}
docker compose up -d
register: start_services
changed_when: start_services.rc == 0
- name: Wait for services to be ready
pause:
seconds: 5
- name: Register runner with correct Gitea instance
shell: |
cd {{ gitea_runner_path }}
docker compose exec -T {{ runner_container_name }} act_runner register \
--instance "{{ gitea_instance_url }}" \
--token "{{ runner_registration_token }}" \
--name "{{ runner_name }}" \
--labels "{{ runner_labels }}"
register: register_result
no_log: true
changed_when: register_result.rc == 0
- name: Display registration result
debug:
msg: |
Runner Registration Result:
{{ register_result.stdout | default('No output') }}
when: register_result.rc == 0
- name: Verify .runner file was created
stat:
path: "{{ gitea_runner_path }}/data/.runner"
register: runner_file_created
- name: Check .runner file for correct instance URL
shell: |
grep -i "{{ gitea_instance_url }}" "{{ gitea_runner_path }}/data/.runner" 2>/dev/null || echo "URL_NOT_FOUND"
register: runner_url_check
when: runner_file_created.stat.exists
changed_when: false
- name: Check .runner file for GitHub URLs
shell: |
grep -i "github.com" "{{ gitea_runner_path }}/data/.runner" 2>/dev/null || echo "NO_GITHUB_URLS"
register: runner_github_check
when: runner_file_created.stat.exists
changed_when: false
- name: Display final status
debug:
msg: |
========================================
Gitea Runner Registration Status
========================================
Registration: {{ '✅ SUCCESS' if register_result.rc == 0 else '❌ FAILED' }}
Runner File Created: {{ '✅ YES' if runner_file_created.stat.exists else '❌ NO' }}
Contains Correct URL: {{ '✅ YES' if 'URL_NOT_FOUND' not in runner_url_check.stdout else '❌ NO' }}
Contains GitHub URLs: {{ '❌ YES' if 'NO_GITHUB_URLS' not in runner_github_check.stdout else '✅ NO' }}
========================================
{% if register_result.rc == 0 and runner_file_created.stat.exists %}
✅ Runner registered successfully with {{ gitea_instance_url }}!
Check runner status:
{{ gitea_instance_url }}/admin/actions/runners
{% else %}
❌ Registration failed. Check logs:
docker logs {{ runner_container_name }}
{% endif %}

View File

@@ -0,0 +1,92 @@
# Gitea Runner Konfiguration korrigieren
## Problem
Der Gitea Runner verwendet gemischte URLs (GitHub + Gitea) und fällt bei 504-Fehlern auf GitHub zurück, was zu Timeouts führt.
## Lösung: Runner neu registrieren
### Schritt 1: Runner stoppen
```bash
cd deployment/gitea-runner
docker compose stop gitea-runner
```
### Schritt 2: Backup erstellen und .runner Datei entfernen
```bash
# Backup erstellen
cp data/.runner data/.runner.backup.$(date +%s)
# .runner Datei entfernen (wird bei neuer Registration neu erstellt)
rm -f data/.runner
```
### Schritt 3: Runner starten
```bash
docker compose up -d gitea-runner
```
### Schritt 4: Runner neu registrieren
```bash
# .env Datei laden
source .env
# Runner registrieren (nur mit korrekter Gitea-URL)
docker compose exec -T gitea-runner act_runner register \
--instance "${GITEA_INSTANCE_URL}" \
--token "${GITEA_RUNNER_REGISTRATION_TOKEN}" \
--name "${GITEA_RUNNER_NAME}" \
--labels "${GITEA_RUNNER_LABELS}"
```
**Wichtig**: Bei der Aufforderung "Runner is already registered, overwrite local config? [y/N]" mit `y` antworten.
### Schritt 5: Verifikation
1. **Prüfe .runner Datei:**
```bash
cat data/.runner | grep -E "(address|instance)"
```
Sollte nur `https://git.michaelschiemer.de` enthalten, keine GitHub-URLs.
2. **Prüfe Runner-Logs:**
```bash
docker compose logs gitea-runner --tail=50 | grep -E "(github|instance|declare)"
```
Sollte `declare successfully` zeigen und keine GitHub-URLs mehr enthalten.
3. **Prüfe in Gitea UI:**
- Gehe zu: https://git.michaelschiemer.de/admin/actions/runners
- Runner sollte als "Online" angezeigt werden
## Automatisierung
Falls der Runner automatisch neu registriert werden soll:
```bash
cd deployment/gitea-runner
./unregister.sh # Falls vorhanden
./register.sh # Neu registrieren
```
## Troubleshooting
**Runner registriert sich nicht:**
- Prüfe, ob Gitea erreichbar ist: `curl https://git.michaelschiemer.de/api/healthz`
- Prüfe, ob der Registration Token noch gültig ist
- Prüfe Runner-Logs: `docker compose logs gitea-runner`
**Runner verwendet immer noch GitHub:**
- Stelle sicher, dass die `.runner` Datei nur die korrekte Gitea-URL enthält
- Prüfe, ob es mehrere Runner-Instanzen gibt: `docker ps | grep runner`
- Prüfe Workflow-Definitionen auf GitHub-URLs
**504 Gateway Timeout:**
- Prüfe Gitea-Container: `docker logs gitea`
- Prüfe Traefik-Logs: `docker logs traefik`
- Stelle sicher, dass Gitea nicht überlastet ist