fix: simplify CI pipeline YAML to avoid parsing errors
Removed env: block and complex inline heredocs. Compose file written to temp file instead of inline Python string.
This commit is contained in:
+54
-57
@@ -4,10 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
env:
|
|
||||||
REGISTRY: git.home.rm-warpstation.de
|
|
||||||
IMAGE: mwf975_git/tippspiel
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: self-hosted
|
runs-on: self-hosted
|
||||||
@@ -37,7 +33,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Build Docker Image via Portainer
|
- name: Build Docker Image via Portainer
|
||||||
run: |
|
run: |
|
||||||
IMAGE_TAG="${{ env.REGISTRY }}/${{ env.IMAGE }}:latest"
|
REGISTRY="git.home.rm-warpstation.de"
|
||||||
|
IMAGE_TAG="${REGISTRY}/mwf975_git/tippspiel:latest"
|
||||||
echo "Building image: $IMAGE_TAG"
|
echo "Building image: $IMAGE_TAG"
|
||||||
curl -s -k -X POST \
|
curl -s -k -X POST \
|
||||||
"https://192.168.1.60:9444/api/endpoints/2/docker/build?t=${IMAGE_TAG}&dockerfile=./Dockerfile&nocache=1" \
|
"https://192.168.1.60:9444/api/endpoints/2/docker/build?t=${IMAGE_TAG}&dockerfile=./Dockerfile&nocache=1" \
|
||||||
@@ -45,68 +42,58 @@ jobs:
|
|||||||
-H "Content-Type: application/x-tar" \
|
-H "Content-Type: application/x-tar" \
|
||||||
--data-binary @/tmp/tippspiel-ci.tar \
|
--data-binary @/tmp/tippspiel-ci.tar \
|
||||||
--max-time 600 \
|
--max-time 600 \
|
||||||
| grep -E '(Successfully|error|Error)' || true
|
| tail -5
|
||||||
echo "Build completed."
|
echo "Build completed."
|
||||||
|
|
||||||
- name: Push to Gitea Registry
|
- name: Push to Gitea Registry
|
||||||
run: |
|
run: |
|
||||||
IMAGE_TAG="${{ env.REGISTRY }}/${{ env.IMAGE }}:latest"
|
REGISTRY="git.home.rm-warpstation.de"
|
||||||
|
IMAGE_TAG="${REGISTRY}/mwf975_git/tippspiel:latest"
|
||||||
|
DEPLOY_TOKEN="${{ secrets.DEPLOY_TOKEN }}"
|
||||||
|
|
||||||
# Login to Gitea registry via Portainer Docker API
|
AUTH_HEADER=$(python3 -c "
|
||||||
LOGIN_PAYLOAD=$(python3 -c "import json; print(json.dumps({'username': 'mwf975_git', 'password': '${{ secrets.DEPLOY_TOKEN }}', 'serveraddress': 'https://${{ env.REGISTRY }}'}))")
|
import base64, json
|
||||||
curl -s -k -X POST \
|
auth = json.dumps({'username': 'mwf975_git', 'password': '${DEPLOY_TOKEN}', 'serveraddress': 'https://${REGISTRY}'})
|
||||||
"https://192.168.1.60:9444/api/endpoints/2/docker/auth" \
|
print(base64.urlsafe_b64encode(auth.encode()).decode())
|
||||||
-H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" \
|
")
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "$LOGIN_PAYLOAD" || true
|
|
||||||
|
|
||||||
# Push image to registry
|
|
||||||
echo "Pushing $IMAGE_TAG..."
|
echo "Pushing $IMAGE_TAG..."
|
||||||
AUTH_HEADER=$(python3 -c "import base64,json; print(base64.urlsafe_b64encode(json.dumps({'username':'mwf975_git','password':'${{ secrets.DEPLOY_TOKEN }}'}).encode()).decode())")
|
|
||||||
curl -s -k -X POST \
|
curl -s -k -X POST \
|
||||||
"https://192.168.1.60:9444/api/endpoints/2/docker/images/${IMAGE_TAG}/push" \
|
"https://192.168.1.60:9444/api/endpoints/2/docker/images/${IMAGE_TAG}/push" \
|
||||||
-H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" \
|
-H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" \
|
||||||
-H "X-Registry-Auth: $AUTH_HEADER" \
|
-H "X-Registry-Auth: $AUTH_HEADER" \
|
||||||
--max-time 300 || true
|
--max-time 300
|
||||||
|
echo ""
|
||||||
echo "Push completed."
|
echo "Push completed."
|
||||||
|
|
||||||
- name: Redeploy Stack via Portainer
|
- name: Redeploy Stack via Portainer
|
||||||
run: |
|
run: |
|
||||||
echo "Fetching current stack config from Portainer..."
|
REGISTRY="git.home.rm-warpstation.de"
|
||||||
|
|
||||||
# Aktuelle Env-Vars aus Portainer lesen
|
# Compose-File als separate Datei schreiben
|
||||||
ENV_VARS=$(curl -s -k \
|
cat > /tmp/compose-deploy.yml << 'COMPOSE_EOF'
|
||||||
"https://192.168.1.60:9444/api/stacks/115" \
|
services:
|
||||||
-H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" \
|
|
||||||
| python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin).get('Env', [])))")
|
|
||||||
|
|
||||||
# Stack mit Image-Pull neu deployen
|
|
||||||
PAYLOAD=$(python3 -c "
|
|
||||||
import json
|
|
||||||
env_vars = $ENV_VARS
|
|
||||||
print(json.dumps({
|
|
||||||
'stackFileContent': '''services:
|
|
||||||
tippspiel:
|
tippspiel:
|
||||||
image: ${{ env.REGISTRY }}/${{ env.IMAGE }}:latest
|
image: git.home.rm-warpstation.de/mwf975_git/tippspiel:latest
|
||||||
container_name: wm2026-tippspiel
|
container_name: wm2026-tippspiel
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- \"3301:3001\"
|
- "3301:3001"
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=\${NODE_ENV}
|
- NODE_ENV=${NODE_ENV}
|
||||||
- PORT=\${PORT}
|
- PORT=${PORT}
|
||||||
- DATABASE_URL=\${DATABASE_URL}
|
- DATABASE_URL=${DATABASE_URL}
|
||||||
- SUPABASE_URL=\${SUPABASE_URL}
|
- SUPABASE_URL=${SUPABASE_URL}
|
||||||
- SUPABASE_SERVICE_ROLE_KEY=\${SUPABASE_SERVICE_ROLE_KEY}
|
- SUPABASE_SERVICE_ROLE_KEY=${SUPABASE_SERVICE_ROLE_KEY}
|
||||||
- ANTHROPIC_API_KEY=\${ANTHROPIC_API_KEY}
|
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
|
||||||
- FOOTBALL_API_KEY=\${FOOTBALL_API_KEY}
|
- FOOTBALL_API_KEY=${FOOTBALL_API_KEY}
|
||||||
- FOOTBALL_API_BASE_URL=\${FOOTBALL_API_BASE_URL}
|
- FOOTBALL_API_BASE_URL=${FOOTBALL_API_BASE_URL}
|
||||||
- ELEVENLABS_API_KEY=\${ELEVENLABS_API_KEY}
|
- ELEVENLABS_API_KEY=${ELEVENLABS_API_KEY}
|
||||||
- CORS_ORIGIN=\${CORS_ORIGIN}
|
- CORS_ORIGIN=${CORS_ORIGIN}
|
||||||
- STAFFBASE_PUBLIC_KEY=\${STAFFBASE_PUBLIC_KEY:-}
|
- STAFFBASE_PUBLIC_KEY=${STAFFBASE_PUBLIC_KEY:-}
|
||||||
- STAFFBASE_PLUGIN_ID=\${STAFFBASE_PLUGIN_ID:-}
|
- STAFFBASE_PLUGIN_ID=${STAFFBASE_PLUGIN_ID:-}
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [\"CMD\", \"wget\", \"-qO-\", \"http://localhost:3001/health\"]
|
test: ["CMD", "wget", "-qO-", "http://localhost:3001/health"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
@@ -116,34 +103,44 @@ jobs:
|
|||||||
|
|
||||||
networks:
|
networks:
|
||||||
main-network:
|
main-network:
|
||||||
external: true''',
|
external: true
|
||||||
|
COMPOSE_EOF
|
||||||
|
|
||||||
|
# Env-Vars aus Portainer lesen
|
||||||
|
ENV_VARS=$(curl -s -k \
|
||||||
|
"https://192.168.1.60:9444/api/stacks/115" \
|
||||||
|
-H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" \
|
||||||
|
| python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin).get('Env', [])))")
|
||||||
|
|
||||||
|
# Stack-File lesen und Payload bauen
|
||||||
|
STACK_CONTENT=$(cat /tmp/compose-deploy.yml)
|
||||||
|
PAYLOAD=$(python3 -c "
|
||||||
|
import json, sys
|
||||||
|
compose = open('/tmp/compose-deploy.yml').read()
|
||||||
|
env_vars = json.loads(sys.argv[1])
|
||||||
|
print(json.dumps({
|
||||||
|
'stackFileContent': compose,
|
||||||
'env': env_vars,
|
'env': env_vars,
|
||||||
'prune': True,
|
'prune': True,
|
||||||
'pullImage': True
|
'pullImage': True
|
||||||
}))
|
}))
|
||||||
")
|
" "$ENV_VARS")
|
||||||
|
|
||||||
echo "Redeploying stack wm2026-tippspiel..."
|
echo "Redeploying stack..."
|
||||||
curl -s -k -X PUT \
|
curl -s -k -X PUT \
|
||||||
"https://192.168.1.60:9444/api/stacks/115?endpointId=2" \
|
"https://192.168.1.60:9444/api/stacks/115?endpointId=2" \
|
||||||
-H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" \
|
-H "X-API-Key: ${{ secrets.PORTAINER_TOKEN }}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "$PAYLOAD" \
|
-d "$PAYLOAD" \
|
||||||
| python3 -c "import sys,json; d=json.load(sys.stdin); print('Stack redeployed:', d.get('Name'), '| Status:', d.get('Status'))" \
|
| python3 -c "import sys,json; d=json.load(sys.stdin); print('Stack:', d.get('Name'), '| Status:', d.get('Status'))" \
|
||||||
|| echo "Stack redeploy triggered."
|
|| echo "Stack redeploy triggered."
|
||||||
echo "Deployment complete!"
|
|
||||||
|
|
||||||
- name: Verify deployment
|
- name: Verify deployment
|
||||||
run: |
|
run: |
|
||||||
sleep 20
|
sleep 20
|
||||||
STATUS=$(curl -s http://192.168.1.60:3301/health | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('status'))" 2>/dev/null || echo "unreachable")
|
STATUS=$(curl -s http://192.168.1.60:3301/health | python3 -c "import sys,json; print(d:=json.load(sys.stdin), d.get('status'))" 2>/dev/null || echo "unreachable")
|
||||||
echo "Health check: $STATUS"
|
echo "Health check: $STATUS"
|
||||||
if [ "$STATUS" = "ok" ]; then
|
|
||||||
echo "✅ Deployment successful! App running at http://192.168.1.60:3301"
|
|
||||||
else
|
|
||||||
echo "⚠️ Health check inconclusive (container may be restarting)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: rm -rf workspace /tmp/tippspiel-ci.tar
|
run: rm -rf workspace /tmp/tippspiel-ci.tar /tmp/compose-deploy.yml
|
||||||
|
|||||||
Reference in New Issue
Block a user