chore: update ci-cd.yml

This commit is contained in:
2025-07-17 19:39:52 +02:00
parent cec1b42da3
commit 1993602af8

View File

@@ -13,7 +13,7 @@ env:
jobs: jobs:
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-22.04
container: container:
image: php:8.4-cli image: php:8.4-cli
services: services:
@@ -24,18 +24,18 @@ jobs:
env: env:
MYSQL_ROOT_PASSWORD: test MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: test MYSQL_DATABASE: test
steps: steps:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install System Dependencies - name: Install System Dependencies
run: | run: |
apt-get update && apt-get install -y \ apt-get update && apt-get install -y \
git unzip libzip-dev libpng-dev libjpeg-dev \ git unzip libzip-dev libpng-dev libjpeg-dev \
libfreetype6-dev libwebp-dev libavif-dev \ libfreetype6-dev libwebp-dev libavif-dev \
libxpm-dev curl libxpm-dev curl
- name: Install PHP Extensions - name: Install PHP Extensions
run: | run: |
docker-php-ext-configure gd \ docker-php-ext-configure gd \
@@ -43,26 +43,26 @@ jobs:
--with-avif --with-xpm --with-avif --with-xpm
docker-php-ext-install -j$(nproc) \ docker-php-ext-install -j$(nproc) \
gd zip pdo pdo_mysql opcache pcntl posix shmop gd zip pdo pdo_mysql opcache pcntl posix shmop
- name: Install Composer - name: Install Composer
run: | run: |
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- name: Cache Composer Dependencies - name: Cache Composer Dependencies
uses: actions/cache@v3 uses: actions/cache@v3
with: with:
path: ~/.composer/cache path: ~/.composer/cache
key: composer-${{ hashFiles('**/composer.lock') }} key: composer-${{ hashFiles('**/composer.lock') }}
restore-keys: composer- restore-keys: composer-
- name: Install Dependencies - name: Install Dependencies
run: | run: |
composer install --no-progress --prefer-dist --optimize-autoloader composer install --no-progress --prefer-dist --optimize-autoloader
- name: Run PHP CS Fixer (Check) - name: Run PHP CS Fixer (Check)
run: | run: |
composer cs composer cs
- name: Run Tests - name: Run Tests
run: | run: |
./vendor/bin/pest ./vendor/bin/pest
@@ -78,16 +78,16 @@ jobs:
security-scan: security-scan:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: test needs: test
steps: steps:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Run Security Scan - name: Run Security Scan
run: | run: |
# Composer-Audit für bekannte Vulnerabilities # Composer-Audit für bekannte Vulnerabilities
composer audit --format=json || true composer audit --format=json || true
# Grundlegende Sicherheitsscans # Grundlegende Sicherheitsscans
find . -name "*.php" -exec grep -l "eval\|system\|exec\|shell_exec" {} \; || true find . -name "*.php" -exec grep -l "eval\|system\|exec\|shell_exec" {} \; || true
@@ -95,18 +95,18 @@ jobs:
needs: [test, security-scan] needs: [test, security-scan]
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
steps: steps:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Login to Private Registry - name: Login to Private Registry
run: | run: |
echo ${{ secrets.REGISTRY_PASSWORD }} | docker login ${{ env.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin echo ${{ secrets.REGISTRY_PASSWORD }} | docker login ${{ env.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
- name: Determine Image Tag - name: Determine Image Tag
id: tag id: tag
run: | run: |
@@ -117,7 +117,7 @@ jobs:
echo "tag=develop" >> $GITHUB_OUTPUT echo "tag=develop" >> $GITHUB_OUTPUT
echo "env=staging" >> $GITHUB_OUTPUT echo "env=staging" >> $GITHUB_OUTPUT
fi fi
- name: Build and Push PHP Image - name: Build and Push PHP Image
run: | run: |
docker buildx build --push \ docker buildx build --push \
@@ -127,7 +127,7 @@ jobs:
-t ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/php:${{ steps.tag.outputs.tag }} \ -t ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/php:${{ steps.tag.outputs.tag }} \
-t ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/php:${{ github.sha }} \ -t ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/php:${{ github.sha }} \
-f docker/php/Dockerfile . -f docker/php/Dockerfile .
- name: Build and Push Nginx Image - name: Build and Push Nginx Image
run: | run: |
docker buildx build --push \ docker buildx build --push \
@@ -135,7 +135,7 @@ jobs:
-t ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/nginx:${{ steps.tag.outputs.tag }} \ -t ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/nginx:${{ steps.tag.outputs.tag }} \
-t ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/nginx:${{ github.sha }} \ -t ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/nginx:${{ github.sha }} \
-f docker/nginx/Dockerfile . -f docker/nginx/Dockerfile .
- name: Build and Push Worker Image - name: Build and Push Worker Image
run: | run: |
docker buildx build --push \ docker buildx build --push \
@@ -155,42 +155,42 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop' if: github.ref == 'refs/heads/develop'
environment: staging environment: staging
steps: steps:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup SSH - name: Setup SSH
run: | run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.STAGING_HOST }} >> ~/.ssh/known_hosts ssh-keyscan -H ${{ secrets.STAGING_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to Staging - name: Deploy to Staging
run: | run: |
ssh -i ~/.ssh/id_rsa ${{ secrets.STAGING_USER }}@${{ secrets.STAGING_HOST }} << 'EOF' ssh -i ~/.ssh/id_rsa ${{ secrets.STAGING_USER }}@${{ secrets.STAGING_HOST }} << 'EOF'
cd /var/www/michaelschiemer cd /var/www/michaelschiemer
# Registry-Login # Registry-Login
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
# Images pullen # Images pullen
docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/php:develop docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/php:develop
docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/nginx:develop docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/nginx:develop
docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/worker:develop docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/worker:develop
# Environment auf develop setzen # Environment auf develop setzen
sed -i 's/IMAGE_TAG=.*/IMAGE_TAG=develop/' .env sed -i 's/IMAGE_TAG=.*/IMAGE_TAG=develop/' .env
# Services neustarten # Services neustarten
docker compose pull docker compose pull
docker compose up -d docker compose up -d
# Aufräumen # Aufräumen
docker system prune -f docker system prune -f
EOF EOF
- name: Health Check Staging - name: Health Check Staging
run: | run: |
sleep 30 sleep 30
@@ -201,42 +201,42 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
environment: production environment: production
steps: steps:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup SSH - name: Setup SSH
run: | run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.PRODUCTION_HOST }} >> ~/.ssh/known_hosts ssh-keyscan -H ${{ secrets.PRODUCTION_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to Production - name: Deploy to Production
run: | run: |
ssh -i ~/.ssh/id_rsa ${{ secrets.PRODUCTION_USER }}@${{ secrets.PRODUCTION_HOST }} << 'EOF' ssh -i ~/.ssh/id_rsa ${{ secrets.PRODUCTION_USER }}@${{ secrets.PRODUCTION_HOST }} << 'EOF'
cd /var/www/michaelschiemer cd /var/www/michaelschiemer
# Registry-Login # Registry-Login
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
# Images pullen # Images pullen
docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/php:latest docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/php:latest
docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/nginx:latest docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/nginx:latest
docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/worker:latest docker pull ${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}/worker:latest
# Environment auf latest setzen # Environment auf latest setzen
sed -i 's/IMAGE_TAG=.*/IMAGE_TAG=latest/' .env sed -i 's/IMAGE_TAG=.*/IMAGE_TAG=latest/' .env
# Services neustarten # Services neustarten
docker compose pull docker compose pull
docker compose up -d docker compose up -d
# Aufräumen # Aufräumen
docker system prune -f docker system prune -f
EOF EOF
- name: Health Check Production - name: Health Check Production
run: | run: |
sleep 30 sleep 30
@@ -246,7 +246,7 @@ jobs:
needs: [deploy-staging, deploy-production] needs: [deploy-staging, deploy-production]
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: always() if: always()
steps: steps:
- name: Clean up old images - name: Clean up old images
run: | run: |
@@ -258,17 +258,17 @@ jobs:
needs: [deploy-staging, deploy-production] needs: [deploy-staging, deploy-production]
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: always() if: always()
steps: steps:
- name: Notify Deployment Status - name: Notify Deployment Status
run: | run: |
STATUS="${{ job.status }}" STATUS="${{ job.status }}"
BRANCH="${{ github.ref_name }}" BRANCH="${{ github.ref_name }}"
if [ "$STATUS" = "success" ]; then if [ "$STATUS" = "success" ]; then
echo "✅ Deployment erfolgreich für Branch: $BRANCH" echo "✅ Deployment erfolgreich für Branch: $BRANCH"
else else
echo "❌ Deployment fehlgeschlagen für Branch: $BRANCH" echo "❌ Deployment fehlgeschlagen für Branch: $BRANCH"
fi fi
# Hier könnten Sie Slack/Email-Benachrichtigungen hinzufügen # Hier könnten Sie Slack/Email-Benachrichtigungen hinzufügen