Erste Version für CI/CD Pipeline
Some checks are pending
Deploy Moodle to STACKIT Cloud Foundry / deploy (push) Waiting to run
Some checks are pending
Deploy Moodle to STACKIT Cloud Foundry / deploy (push) Waiting to run
This commit is contained in:
parent
dd557bd360
commit
be719a195d
1 changed files with 124 additions and 0 deletions
124
.github/workflows/deploy-moodle.yml
vendored
Normal file
124
.github/workflows/deploy-moodle.yml
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
name: Deploy Moodle to STACKIT Cloud Foundry
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
manifest_file:
|
||||
description: 'Welches Manifest soll verwendet werden?'
|
||||
required: true
|
||||
default: 'manifest-cdn.yml'
|
||||
type: choice
|
||||
options:
|
||||
- manifest-cdn.yml
|
||||
- manifest-no-cdn.yml
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: 1. Code auschecken
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 2. CLIs installieren
|
||||
run: |
|
||||
# Cloud Foundry CLI
|
||||
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
|
||||
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
|
||||
sudo apt-get update && sudo apt-get install cf8-cli -y
|
||||
|
||||
# STACKIT CLI
|
||||
wget https://github.com/stackitcloud/stackit-cli/releases/latest/download/stackit-linux-amd64.tar.gz
|
||||
tar -xzf stackit-linux-amd64.tar.gz && sudo mv stackit /usr/local/bin/
|
||||
|
||||
- name: 3. Bei Cloud Foundry & STACKIT anmelden
|
||||
env:
|
||||
STACKIT_SERVICE_ACCOUNT_TOKEN: ${{ secrets.STACKIT_SERVICE_ACCOUNT_TOKEN }}
|
||||
STACKIT_SERVICE_ACCOUNT_EMAIL: ${{ secrets.STACKIT_SERVICE_ACCOUNT_EMAIL }}
|
||||
run: |
|
||||
stackit auth login --service-account-email "$STACKIT_SERVICE_ACCOUNT_EMAIL" --service-account-token "$STACKIT_SERVICE_ACCOUNT_TOKEN"
|
||||
cf login -a https://api.cf.eu01.stackit.cloud -u "${{ secrets.CF_USERNAME }}" -p "${{ secrets.CF_PASSWORD }}"
|
||||
cf target -o "${{ secrets.CF_ORG }}" -s "${{ secrets.CF_SPACE }}"
|
||||
|
||||
- name: 4. Moodle-Quellcode und Plugins vorbereiten
|
||||
run: |
|
||||
echo "Lade Moodle-Quellcode herunter..."
|
||||
wget https://packaging.moodle.org/stable500/moodle-5.0.1.tgz
|
||||
tar -xzf moodle-5.0.1.tgz
|
||||
|
||||
echo "Lade Plugins herunter und installiere sie..."
|
||||
wget https://moodle.org/plugins/download.php/30019/cachestore_redis_moodle44_2024051300.zip
|
||||
unzip -q cachestore_redis_moodle44_2024051300.zip
|
||||
mv redis moodle/cache/stores/
|
||||
cd moodle
|
||||
git clone https://github.com/catalyst/moodle-tool_objectfs.git admin/tool/objectfs
|
||||
cd ..
|
||||
|
||||
echo "Erstelle Buildpack-Konfiguration und Workarounds..."
|
||||
echo '{"WEBDIR": ".", "PHP_VERSION": "{PHP_82_LATEST}"}' > moodle/.bp-config/options.json
|
||||
mkdir -p moodle/.bp-config/php/php.ini.d/
|
||||
echo "extension=mysqli" > moodle/.bp-config/php/php.ini.d/mysqli.ini
|
||||
echo "extension=redis" > moodle/.bp-config/php/php.ini.d/redis.ini
|
||||
echo "max_input_vars = 5000" > moodle/.bp-config/php/php.ini.d/moodle.ini
|
||||
mkdir -p moodle/logs
|
||||
ln -s /dev/stdout moodle/logs/rewrite.log
|
||||
ln -s /dev/stdout moodle/logs/proc-man.log
|
||||
mkdir -p moodle/httpd/logs
|
||||
mkdir -p moodle/php/var/run
|
||||
ln -s /tmp/httpd.pid moodle/httpd/logs/httpd.pid
|
||||
ln -s /tmp/php-fpm.pid moodle/php/var/run/php-fpm.pid
|
||||
|
||||
- name: 5. STACKIT & Cloud Foundry Services sicherstellen
|
||||
id: services
|
||||
env:
|
||||
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
|
||||
STACKIT_PROJECT_ID: ${{ secrets.STACKIT_PROJECT_ID }}
|
||||
run: |
|
||||
# Funktion, um zu prüfen, ob ein CF-Service existiert
|
||||
service_exists() { cf service "$1" >/dev/null 2>&1; }
|
||||
|
||||
# CF Services
|
||||
if ! service_exists <DEINE_MARIADB_INSTANZ>; then cf create-service <dein-mariadb-service> <plan> <DEINE_MARIADB_INSTANZ>; else echo "Service '<DEINE_MARIADB_INSTANZ>' existiert bereits."; fi
|
||||
if ! service_exists <DEINE_REDIS_INSTANZ>; then cf create-service appcloud-redis7 redis-4.16.100-replica <DEINE_REDIS_INSTANZ>; else echo "Service '<DEINE_REDIS_INSTANZ>' existiert bereits."; fi
|
||||
if ! service_exists <DEIN_AUTOSCALER_INSTANZ>; then cf create-service autoscaler autoscaler-free-plan <DEIN_AUTOSCALER_INSTANZ>; else echo "Service '<DEIN_AUTOSCALER_INSTANZ>' existiert bereits."; fi
|
||||
|
||||
# STACKIT S3 Bucket & Credentials dynamisch erzeugen
|
||||
echo "Stelle S3 Bucket sicher..."
|
||||
stackit object-storage bucket create --name "$S3_BUCKET_NAME" || echo "Bucket '$S3_BUCKET_NAME' existiert bereits."
|
||||
|
||||
echo "Erstelle S3 Credentials und fange die Ausgabe ab..."
|
||||
CREDENTIALS_JSON=$(stackit object-storage credential create --project-id "$STACKIT_PROJECT_ID")
|
||||
|
||||
# Extrahiere Keys mit JQ und setze sie als Umgebungsvariablen für den nächsten Schritt
|
||||
S3_ACCESS_KEY=$(echo "$CREDENTIALS_JSON" | jq -r '.accessKey')
|
||||
S3_SECRET_KEY=$(echo "$CREDENTIALS_JSON" | jq -r '.secretAccessKey')
|
||||
|
||||
echo "S3_ACCESS_KEY=${S3_ACCESS_KEY}" >> $GITHUB_ENV
|
||||
echo "S3_SECRET_KEY=${S3_SECRET_KEY}" >> $GITHUB_ENV
|
||||
|
||||
- name: 6. User-Provided Service für S3 erstellen
|
||||
env:
|
||||
S3_ACCESS_KEY: ${{ env.S3_ACCESS_KEY }}
|
||||
S3_SECRET_KEY: ${{ env.S3_SECRET_KEY }}
|
||||
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
|
||||
run: |
|
||||
# Erstelle S3 CUPS nur, wenn er nicht existiert
|
||||
if ! cf service <DEINE_S3_CUPS_INSTANZ> >/dev/null 2>&1; then
|
||||
cf create-user-provided-service <DEINE_S3_CUPS_INSTANZ> -p "{
|
||||
\"access_key\": \"$S3_ACCESS_KEY\",
|
||||
\"secret_key\": \"$S3_SECRET_KEY\",
|
||||
\"bucket\": \"$S3_BUCKET_NAME\",
|
||||
\"endpoint\": \"https://object.storage.eu01.onstackit.cloud/\"
|
||||
}"
|
||||
else
|
||||
echo "Service '<DEINE_S3_CUPS_INSTANZ>' existiert bereits."
|
||||
fi
|
||||
|
||||
- name: 7. Moodle-Anwendung deployen
|
||||
run: |
|
||||
MANIFEST_FILE=${{ github.event.inputs.manifest_file || 'manifest-cdn.yml' }}
|
||||
echo "Deploye mit Manifest: $MANIFEST_FILE"
|
||||
cf push -f "$MANIFEST_FILE"
|
||||
Loading…
Reference in a new issue