Update: Verwende repository.michaelschiemer.de:5000 für Git-Repository URLs

- Ändere Remote-URL zu repository.michaelschiemer.de:5000
- Aktualisiere alle Workflows (production-deploy, test-registry, security-scan, update-production-secrets)
- Test: Production Deployment Workflow
This commit is contained in:
2025-10-31 20:14:41 +01:00
parent 891508f47c
commit f1329433ce
4 changed files with 203 additions and 42 deletions

View File

@@ -29,16 +29,16 @@ jobs:
# Use CI token if available, otherwise try public access # Use CI token if available, otherwise try public access
if [ -n "${{ secrets.CI_TOKEN }}" ]; then if [ -n "${{ secrets.CI_TOKEN }}" ]; then
git clone --depth 1 --branch "$REF_NAME" \ git clone --depth 1 --branch "$REF_NAME" \
"https://${{ secrets.CI_TOKEN }}@git.michaelschiemer.de/${REPO}.git" \ "https://${{ secrets.CI_TOKEN }}@repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo /workspace/repo
else else
# Try public HTTPS (works if repository is public) # Try public HTTPS (works if repository is public)
git clone --depth 1 --branch "$REF_NAME" \ git clone --depth 1 --branch "$REF_NAME" \
"https://git.michaelschiemer.de/${REPO}.git" \ "https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo || \ /workspace/repo || \
# Fallback: Try to use Gitea's internal runner access # Fallback: Try to use Gitea's internal runner access
git clone --depth 1 \ git clone --depth 1 \
"https://git.michaelschiemer.de/${REPO}.git" \ "https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo /workspace/repo
fi fi
@@ -127,16 +127,16 @@ jobs:
# Use CI token if available, otherwise try public access # Use CI token if available, otherwise try public access
if [ -n "${{ secrets.CI_TOKEN }}" ]; then if [ -n "${{ secrets.CI_TOKEN }}" ]; then
git clone --depth 1 --branch "$REF_NAME" \ git clone --depth 1 --branch "$REF_NAME" \
"https://${{ secrets.CI_TOKEN }}@git.michaelschiemer.de/${REPO}.git" \ "https://${{ secrets.CI_TOKEN }}@repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo /workspace/repo
else else
# Try public HTTPS (works if repository is public) # Try public HTTPS (works if repository is public)
git clone --depth 1 --branch "$REF_NAME" \ git clone --depth 1 --branch "$REF_NAME" \
"https://git.michaelschiemer.de/${REPO}.git" \ "https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo || \ /workspace/repo || \
# Fallback: Try to use Gitea's internal runner access # Fallback: Try to use Gitea's internal runner access
git clone --depth 1 \ git clone --depth 1 \
"https://git.michaelschiemer.de/${REPO}.git" \ "https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo /workspace/repo
fi fi
@@ -238,7 +238,7 @@ jobs:
echo "" echo ""
echo "🔍 Teste Registry: $TEST_URL" echo "🔍 Teste Registry: $TEST_URL"
# Wenn URL bereits Port enthält, teste direkt (HTTP) # Wenn URL bereits Port 5000 enthält, teste HTTP (Fallback)
if [[ "$TEST_URL" == *":5000" ]]; then if [[ "$TEST_URL" == *":5000" ]]; then
# Direkter HTTP-Zugriff (Port bereits in URL) # Direkter HTTP-Zugriff (Port bereits in URL)
echo " Versuche HTTP-Zugriff auf http://$TEST_URL/v2/" echo " Versuche HTTP-Zugriff auf http://$TEST_URL/v2/"
@@ -299,7 +299,10 @@ jobs:
if [ $LOGIN_EXIT_CODE -eq 0 ]; then if [ $LOGIN_EXIT_CODE -eq 0 ]; then
echo "✅ Erfolgreich bei Registry angemeldet: $TEST_URL" echo "✅ Erfolgreich bei Registry angemeldet: $TEST_URL"
REGISTRY_URL="$TEST_URL" REGISTRY_URL="$TEST_URL"
ACTUAL_REGISTRY="$TEST_URL"
LOGIN_SUCCESS=true LOGIN_SUCCESS=true
echo "REGISTRY_URL=$TEST_URL" >> $GITHUB_ENV
echo "ACTUAL_REGISTRY=$TEST_URL" >> $GITHUB_ENV
break break
else else
echo "⚠️ Login fehlgeschlagen für $TEST_URL (Exit Code: $LOGIN_EXIT_CODE)" echo "⚠️ Login fehlgeschlagen für $TEST_URL (Exit Code: $LOGIN_EXIT_CODE)"
@@ -309,33 +312,91 @@ jobs:
echo "⚠️ Registry nicht erreichbar: http://$TEST_URL (Status: $HTTP_CODE)" echo "⚠️ Registry nicht erreichbar: http://$TEST_URL (Status: $HTTP_CODE)"
fi fi
else else
# Teste HTTPS zuerst # Domain ohne Port - teste HTTPS zuerst (empfohlen, keine insecure-registry nötig!)
if curl -k -s -f -o /dev/null "https://$TEST_URL/v2/" 2>/dev/null; then echo " Versuche HTTPS-Zugriff auf https://$TEST_URL/v2/"
echo "✅ Registry erreichbar über HTTPS: https://$TEST_URL" # Stelle sicher, dass curl verfügbar ist
if ! command -v curl >/dev/null 2>&1; then
apk add --no-cache curl ca-certificates >/dev/null 2>&1 || true
fi
HTTPS_CODE=$(curl -k -s -o /dev/null -w "%{http_code}" "https://$TEST_URL/v2/" 2>&1 || echo "000")
# Debug: Wenn curl fehlschlägt, zeige mehr Details
if [ "$HTTPS_CODE" = "000" ]; then
echo " ⚠️ curl Fehler beim HTTPS-Test"
CURL_VERBOSE=$(curl -k -v "https://$TEST_URL/v2/" 2>&1 | head -20)
echo " curl Verbose Output:"
echo "$CURL_VERBOSE" | while IFS= read -r line; do
echo " $line"
done || true
fi
echo " HTTPS-Status: $HTTPS_CODE"
# Versuche Login # 404 könnte bedeuten, dass die Route nicht richtig konfiguriert ist
if echo "$REGISTRY_PASSWORD" | docker login "$TEST_URL" -u "$REGISTRY_USER" --password-stdin 2>&1; then # 401 ist gut (Registry erreichbar, Auth erforderlich)
echo "✅ Erfolgreich bei Registry angemeldet: $TEST_URL" # 200 ist auch gut (Auth erfolgreich oder nicht erforderlich)
if [ "$HTTPS_CODE" = "401" ] || [ "$HTTPS_CODE" = "200" ]; then
echo "✅ Registry erreichbar über HTTPS: https://$TEST_URL (Status: $HTTPS_CODE)"
# Versuche Login via HTTPS (keine insecure-registry nötig!)
echo " Versuche Docker Login über HTTPS..."
set +e
LOGIN_OUTPUT=$(echo "$REGISTRY_PASSWORD" | docker login "$TEST_URL" -u "$REGISTRY_USER" --password-stdin 2>&1)
LOGIN_EXIT_CODE=$?
set -e
echo " Login-Exit-Code: $LOGIN_EXIT_CODE"
if [ -n "$LOGIN_OUTPUT" ]; then
echo "$LOGIN_OUTPUT" | while IFS= read -r line; do
echo " $line"
done || true
fi
if [ $LOGIN_EXIT_CODE -eq 0 ]; then
echo "✅ Erfolgreich bei Registry angemeldet über HTTPS: $TEST_URL"
REGISTRY_URL="$TEST_URL" REGISTRY_URL="$TEST_URL"
ACTUAL_REGISTRY="$TEST_URL"
LOGIN_SUCCESS=true LOGIN_SUCCESS=true
echo "REGISTRY_URL=$TEST_URL" >> $GITHUB_ENV
echo "ACTUAL_REGISTRY=$TEST_URL" >> $GITHUB_ENV
break break
else else
echo "⚠️ Login fehlgeschlagen für $TEST_URL, versuche HTTP..." echo "⚠️ HTTPS-Login fehlgeschlagen für $TEST_URL, versuche HTTP als Fallback..."
fi fi
else
echo "⚠️ Registry nicht erreichbar über HTTPS: https://$TEST_URL (Status: $HTTPS_CODE)"
fi fi
# Teste HTTP (falls HTTPS nicht funktioniert) # Fallback: Teste HTTP (falls HTTPS nicht funktioniert)
if curl -s -f -o /dev/null "http://$TEST_URL:5000/v2/" 2>/dev/null; then echo " Versuche HTTP-Zugriff auf http://$TEST_URL:5000/v2/ (Fallback)"
echo "✅ Registry erreichbar über HTTP: http://$TEST_URL:5000" HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://$TEST_URL:5000/v2/" 2>&1 || echo "000")
echo " HTTP-Status: $HTTP_CODE"
# Versuche Login mit HTTP if [ "$HTTP_CODE" = "401" ] || [ "$HTTP_CODE" = "200" ]; then
if echo "$REGISTRY_PASSWORD" | docker login "$TEST_URL:5000" -u "$REGISTRY_USER" --password-stdin 2>&1; then echo "✅ Registry erreichbar über HTTP: http://$TEST_URL:5000 (Status: $HTTP_CODE)"
echo "✅ Erfolgreich bei Registry angemeldet: $TEST_URL:5000"
# Versuche Login mit HTTP (benötigt insecure-registry Konfiguration)
echo " Versuche Docker Login über HTTP (benötigt insecure-registry)..."
set +e
LOGIN_OUTPUT=$(echo "$REGISTRY_PASSWORD" | docker login "$TEST_URL:5000" -u "$REGISTRY_USER" --password-stdin 2>&1)
LOGIN_EXIT_CODE=$?
set -e
echo " Login-Exit-Code: $LOGIN_EXIT_CODE"
if [ -n "$LOGIN_OUTPUT" ]; then
echo "$LOGIN_OUTPUT" | while IFS= read -r line; do
echo " $line"
done || true
fi
if [ $LOGIN_EXIT_CODE -eq 0 ]; then
echo "✅ Erfolgreich bei Registry angemeldet über HTTP: $TEST_URL:5000"
REGISTRY_URL="$TEST_URL:5000" REGISTRY_URL="$TEST_URL:5000"
ACTUAL_REGISTRY="$TEST_URL:5000"
LOGIN_SUCCESS=true LOGIN_SUCCESS=true
echo "REGISTRY_URL=$TEST_URL:5000" >> $GITHUB_ENV
echo "ACTUAL_REGISTRY=$TEST_URL:5000" >> $GITHUB_ENV
break break
else else
echo "⚠️ Login fehlgeschlagen für $TEST_URL:5000, versuche nächste URL..." echo "⚠️ HTTP-Login fehlgeschlagen für $TEST_URL:5000, versuche nächste URL..."
fi fi
fi fi
fi fi
@@ -356,12 +417,19 @@ jobs:
echo "Password vorhanden: $([ -n "$REGISTRY_PASSWORD" ] && echo 'Ja' || echo 'Nein')" echo "Password vorhanden: $([ -n "$REGISTRY_PASSWORD" ] && echo 'Ja' || echo 'Nein')"
echo "" echo ""
echo "Mögliche Ursachen:" echo "Mögliche Ursachen:"
echo "1. Registry nicht vom Runner-Container aus erreichbar (Netzwerk-Isolation)" echo "1. ⚠️ WICHTIG: Docker-daemon (docker-dind) muss neu gestartet werden nach Änderungen an insecure-registry"
echo "2. Falsche Credentials in Gitea Secrets" echo " - Stoppe: docker compose -f deployment/gitea-runner/docker-compose.yml stop docker-dind"
echo "3. Registry-DNS nicht auflösbar vom Container aus" echo " - Starte: docker compose -f deployment/gitea-runner/docker-compose.yml up -d docker-dind"
echo "4. Registry läuft nicht oder ist nicht erreichbar" echo "2. Registry nicht vom Runner-Container aus erreichbar (Netzwerk-Isolation)"
echo "3. Falsche Credentials in Gitea Secrets (REGISTRY_USER, REGISTRY_PASSWORD)"
echo "4. Registry-DNS nicht auflösbar vom Container aus"
echo "5. Registry läuft nicht oder ist nicht erreichbar"
echo "" echo ""
echo "Lösung: Prüfe die Secrets in Gitea und stelle sicher, dass die Registry erreichbar ist" echo "Lösungsschritte:"
echo "1. Stelle sicher, dass docker-compose.yml alle Registry-URLs in --insecure-registry Flags enthält"
echo "2. Starte docker-dind Container NEU (siehe oben)"
echo "3. Prüfe die Secrets in Gitea (REGISTRY_USER, REGISTRY_PASSWORD)"
echo "4. Teste Registry-Erreichbarkeit: curl http://94.16.110.151:5000/v2/"
exit 1 exit 1
fi fi
@@ -369,10 +437,27 @@ jobs:
echo "✅ Registry-Login erfolgreich!" echo "✅ Registry-Login erfolgreich!"
echo "📦 Verwendete Registry URL: $REGISTRY_URL" echo "📦 Verwendete Registry URL: $REGISTRY_URL"
# Stelle sicher, dass ACTUAL_REGISTRY gesetzt ist (für Build-Step)
if [ -z "$ACTUAL_REGISTRY" ]; then
ACTUAL_REGISTRY="$REGISTRY_URL"
echo "ACTUAL_REGISTRY=$REGISTRY_URL" >> $GITHUB_ENV
fi
- name: Build and push Docker image - name: Build and push Docker image
shell: bash shell: bash
env:
ACTUAL_REGISTRY: ${{ env.ACTUAL_REGISTRY }}
run: | run: |
cd /workspace/repo cd /workspace/repo
# Fallback falls ACTUAL_REGISTRY nicht gesetzt wurde
if [ -z "$ACTUAL_REGISTRY" ]; then
echo "⚠️ ACTUAL_REGISTRY nicht gesetzt, verwende Fallback: ${{ env.REGISTRY }}"
ACTUAL_REGISTRY="${{ env.REGISTRY }}"
fi
echo "📦 Verwendete Registry für Build: $ACTUAL_REGISTRY"
COMMIT_SHA="${{ github.sha }}" COMMIT_SHA="${{ github.sha }}"
if [ -z "$COMMIT_SHA" ]; then if [ -z "$COMMIT_SHA" ]; then
COMMIT_SHA=$(git rev-parse HEAD) COMMIT_SHA=$(git rev-parse HEAD)
@@ -424,16 +509,16 @@ jobs:
# Use CI token if available, otherwise try public access # Use CI token if available, otherwise try public access
if [ -n "${{ secrets.CI_TOKEN }}" ]; then if [ -n "${{ secrets.CI_TOKEN }}" ]; then
git clone --depth 1 --branch "$REF_NAME" \ git clone --depth 1 --branch "$REF_NAME" \
"https://${{ secrets.CI_TOKEN }}@git.michaelschiemer.de/${REPO}.git" \ "https://${{ secrets.CI_TOKEN }}@repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo /workspace/repo
else else
# Try public HTTPS (works if repository is public) # Try public HTTPS (works if repository is public)
git clone --depth 1 --branch "$REF_NAME" \ git clone --depth 1 --branch "$REF_NAME" \
"https://git.michaelschiemer.de/${REPO}.git" \ "https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo || \ /workspace/repo || \
# Fallback: Try to use Gitea's internal runner access # Fallback: Try to use Gitea's internal runner access
git clone --depth 1 \ git clone --depth 1 \
"https://git.michaelschiemer.de/${REPO}.git" \ "https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo /workspace/repo
fi fi

View File

@@ -27,16 +27,16 @@ jobs:
# Use CI token if available, otherwise try public access # Use CI token if available, otherwise try public access
if [ -n "${{ secrets.CI_TOKEN }}" ]; then if [ -n "${{ secrets.CI_TOKEN }}" ]; then
git clone --depth 1 --branch "$REF_NAME" \ git clone --depth 1 --branch "$REF_NAME" \
"https://${{ secrets.CI_TOKEN }}@git.michaelschiemer.de/${REPO}.git" \ "https://${{ secrets.CI_TOKEN }}@repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo /workspace/repo
else else
# Try public HTTPS (works if repository is public) # Try public HTTPS (works if repository is public)
git clone --depth 1 --branch "$REF_NAME" \ git clone --depth 1 --branch "$REF_NAME" \
"https://git.michaelschiemer.de/${REPO}.git" \ "https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo || \ /workspace/repo || \
# Fallback: Try to use Gitea's internal runner access # Fallback: Try to use Gitea's internal runner access
git clone --depth 1 \ git clone --depth 1 \
"https://git.michaelschiemer.de/${REPO}.git" \ "https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo /workspace/repo
fi fi

View File

@@ -0,0 +1,61 @@
name: Test Registry Credentials
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'scripts/test-registry-credentials.sh'
- '.gitea/workflows/test-registry.yml'
env:
REGISTRY_DOMAIN: registry.michaelschiemer.de
REGISTRY_HOST: 94.16.110.151
jobs:
test-credentials:
name: Test Registry Credentials
runs-on: docker-build
steps:
- name: Install git and setup environment
shell: sh
run: |
if ! command -v bash >/dev/null 2>&1 || ! command -v git >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1; then
apk add --no-cache git bash curl ca-certificates
fi
- name: Checkout code
shell: bash
run: |
REF_NAME="${{ github.ref_name }}"
REPO="${{ github.repository }}"
if [ -z "$REF_NAME" ]; then
REF_NAME="main"
fi
if [ -n "${{ secrets.CI_TOKEN }}" ]; then
git clone --depth 1 --branch "$REF_NAME" \
"https://${{ secrets.CI_TOKEN }}@repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo
else
git clone --depth 1 --branch "$REF_NAME" \
"https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo || \
git clone --depth 1 \
"https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo
fi
cd /workspace/repo
- name: Test Registry Credentials
shell: bash
env:
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_DOMAIN: ${{ env.REGISTRY_DOMAIN }}
REGISTRY_HOST: ${{ env.REGISTRY_HOST }}
REGISTRY_PORT: 5000
run: |
cd /workspace/repo
./scripts/test-registry-credentials.sh

View File

@@ -14,18 +14,34 @@ env:
jobs: jobs:
deploy-secrets: deploy-secrets:
name: Deploy Secrets to Production name: Deploy Secrets to Production
runs-on: ubuntu-latest runs-on: php-ci # Uses pre-built PHP 8.5 CI image with Ansible
environment: environment:
name: production-secrets name: production-secrets
url: https://michaelschiemer.de url: https://michaelschiemer.de
steps: steps:
- name: Checkout deployment configuration - name: Checkout deployment configuration
uses: actions/checkout@v4 run: |
with: REF_NAME="${{ github.ref_name }}"
sparse-checkout: | REPO="${{ github.repository }}"
deployment/ansible if [ -z "$REF_NAME" ]; then
sparse-checkout-cone-mode: false REF_NAME="main"
fi
if [ -n "${{ secrets.CI_TOKEN }}" ]; then
git clone --depth 1 --branch "$REF_NAME" \
"https://${{ secrets.CI_TOKEN }}@repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo
else
git clone --depth 1 --branch "$REF_NAME" \
"https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo || \
git clone --depth 1 \
"https://repository.michaelschiemer.de:5000/${REPO}.git" \
/workspace/repo
fi
cd /workspace/repo
- name: Setup SSH key - name: Setup SSH key
run: | run: |
@@ -34,10 +50,9 @@ jobs:
chmod 600 ~/.ssh/production chmod 600 ~/.ssh/production
ssh-keyscan -H ${{ env.DEPLOYMENT_HOST }} >> ~/.ssh/known_hosts ssh-keyscan -H ${{ env.DEPLOYMENT_HOST }} >> ~/.ssh/known_hosts
- name: Install Ansible # Ansible is pre-installed in php-ci image
run: | - name: Verify Ansible installation
sudo apt-get update run: ansible --version
sudo apt-get install -y ansible
- name: Create vault password file - name: Create vault password file
run: | run: |