Skip to content

Update deploy-bluegreen.sh #78

Update deploy-bluegreen.sh

Update deploy-bluegreen.sh #78

Workflow file for this run

name: Build and Deploy

Check failure on line 1 in .github/workflows/docker-build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/docker-build.yml

Invalid workflow file

(Line: 66, Col: 9): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.CYSO_HOST != ''
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: van-sprundel/partijgedrag
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Web image
uses: docker/build-push-action@v5
with:
context: ./app
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-web:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-web:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push ETL image
uses: docker/build-push-action@v5
with:
context: ./etl
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-etl:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-etl:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build-and-push
runs-on: ubuntu-latest
# Only deploy if secrets are configured
if: ${{ secrets.CYSO_HOST != '' }}
steps:
- uses: actions/checkout@v4
- name: Deploy to CYSO via SSH
uses: appleboy/ssh-action@v1.0.0
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
CORS_ORIGIN: ${{ secrets.CORS_ORIGIN }}
GIT_SHA: ${{ github.sha }}
with:
host: ${{ secrets.CYSO_HOST }}
username: ${{ secrets.CYSO_USER }}
key: ${{ secrets.CYSO_SSH_KEY }}
port: ${{ secrets.CYSO_SSH_PORT || 22 }}
envs: DATABASE_URL,CORS_ORIGIN,GIT_SHA
script: |
cd ${{ secrets.DEPLOY_PATH || '/opt/partijgedrag' }}
# Create .env with immutable Git SHA tags
cat > .env << EOF
DATABASE_URL=${DATABASE_URL}
PORT=3000
CORS_ORIGIN=${CORS_ORIGIN}
GIT_SHA=${GIT_SHA}
WEB_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-web:${GIT_SHA}
ETL_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-etl:${GIT_SHA}
EOF
# Pull latest deployment scripts
git pull origin main || echo "Skipping git pull"
# Login to registry
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin
# Initialize Swarm if needed (idempotent)
docker swarm init 2>/dev/null || echo "Swarm already initialized"
# Make script executable and deploy
chmod +x deploy-production.sh
./deploy-production.sh
- name: Verify deployment
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.CYSO_HOST }}
username: ${{ secrets.CYSO_USER }}
key: ${{ secrets.CYSO_SSH_KEY }}
port: ${{ secrets.CYSO_SSH_PORT || 22 }}
script: |
cd ${{ secrets.DEPLOY_PATH || '/opt/partijgedrag' }}
sleep 10
echo "📊 Service status:"
docker stack services partijgedrag
if curl -f http://localhost:3000/ready; then
echo "✅ Deployment verified!"
else
echo "❌ Health check failed!"
docker service logs partijgedrag_web --tail=50
exit 1
fi