69 lines
2.6 KiB
YAML
69 lines
2.6 KiB
YAML
name: Deploy Next.js via Docker
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: docker:latest
|
|
steps:
|
|
- name: Code auschecken
|
|
run: |
|
|
apk add --no-cache curl unzip
|
|
curl -L -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/archive/main.zip" -o repo.zip
|
|
unzip repo.zip
|
|
# Verschiebt alle Dateien aus dem Zip-Unterordner direkt hierher ins Hauptverzeichnis
|
|
mv PsalmTafel/* . 2>/dev/null || mv psalmtafel/* . 2>/dev/null || mv */* . 2>/dev/null
|
|
rm repo.zip
|
|
|
|
- name: Docker Container aktualisieren
|
|
run: |
|
|
# Kein 'cd' mehr! Wir sind schon im richtigen Ordner, wo dein Dockerfile liegt.
|
|
echo "Baue das neue Next.js Docker-Image..."
|
|
docker build -t psalmtafel-app .
|
|
|
|
echo "Stoppe alten Container, falls er läuft..."
|
|
docker stop psalmtafel-container || true
|
|
docker rm psalmtafel-container || true
|
|
|
|
echo "Starte neuen Container..."
|
|
docker run -d \
|
|
--name psalmtafel-container \
|
|
-p 8443:3000 \
|
|
--restart always \
|
|
psalmtafel-app
|
|
- name: Release in Gitea erstellen
|
|
run: |
|
|
# 1. jq installieren und Version aus package.json auslesen
|
|
apk add --no-cache jq
|
|
VERSION=$(jq -r '.version' package.json)
|
|
echo "Aktuelle Version: v$VERSION"
|
|
|
|
# 2. Prüfen, ob das Release/Tag bereits existiert
|
|
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases/tags/v$VERSION")
|
|
|
|
# 3. Wenn Release noch nicht existiert (404), erstelle es
|
|
if [ "$HTTP_STATUS" -eq 404 ]; then
|
|
echo "Erstelle neues Release v$VERSION..."
|
|
curl -X POST \
|
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"v$VERSION\",
|
|
\"target_commitish\": \"main\",
|
|
\"name\": \"Release v$VERSION\",
|
|
\"body\": \"Automatisches Release für Version v$VERSION\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}" \
|
|
"http://172.17.0.1:3000/api/v1/repos/${{ github.repository }}/releases"
|
|
else
|
|
echo "Release v$VERSION existiert bereits. Überspringe Erstellung."
|
|
fi |