Files
docker-stacks/.gitea/workflows/deploy.yml
knight 477e22d5a6 Update GitOps workflow to respect stack-type labels
- deploy-prod (master → ubuntu-prod): Only deploys prod and public stacks
- deploy-dev (dev → ubuntu-dev): Only deploys dev-only stacks
- Skips stacks without stack-type labels (with warning)
- Fixed: Only create .env from template if .env doesn't exist

This prevents dev-only experimental stacks from being deployed to
production, even if they're in the master branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 10:07:26 -05:00

149 lines
4.7 KiB
YAML

name: Deploy Stacks
on:
push:
branches: [master, dev]
paths:
- 'stacks/**'
workflow_dispatch:
env:
STACKS_DIR: /var/core
jobs:
deploy-prod:
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-prod
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Find and deploy changed stacks
env:
DOMAIN: ${{ secrets.DOMAIN }}
run: |
# Find changed stacks
STACKS=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | grep '^stacks/' | cut -d'/' -f2 | sort -u || echo "")
if [ -z "$STACKS" ]; then
echo "No stacks changed, checking all stacks..."
STACKS=$(ls stacks/)
fi
echo "Evaluating stacks: $STACKS"
echo ""
for stack in $STACKS; do
COMPOSE_FILE="stacks/$stack/docker-compose.yml"
# Check stack-type label
STACK_TYPE=$(grep -o 'stack-type=[^"]*' "$COMPOSE_FILE" 2>/dev/null | head -1 | cut -d= -f2)
if [ -z "$STACK_TYPE" ]; then
echo "⚠️ SKIP $stack - no stack-type label found"
continue
fi
# On prod, only deploy 'prod' and 'public' stacks
if [ "$STACK_TYPE" != "prod" ] && [ "$STACK_TYPE" != "public" ]; then
echo "⏭️ SKIP $stack - stack-type=$STACK_TYPE (not for prod)"
continue
fi
echo "=========================================="
echo "Deploying $stack (stack-type=$STACK_TYPE)..."
echo "=========================================="
STACK_DIR="${{ env.STACKS_DIR }}/$stack"
sudo mkdir -p "$STACK_DIR"
# Copy files
sudo cp -r stacks/$stack/* "$STACK_DIR/"
# Create .env from template if .env doesn't exist
if [ -f "$STACK_DIR/.env.template" ] && [ ! -f "$STACK_DIR/.env" ]; then
echo "Creating .env from template..."
sudo sh -c "DOMAIN=$DOMAIN envsubst < '$STACK_DIR/.env.template' > '$STACK_DIR/.env'"
fi
# Deploy
cd "$STACK_DIR"
sudo docker compose pull --ignore-pull-failures 2>/dev/null || true
sudo docker compose up -d --remove-orphans
echo "✅ Deployed $stack"
echo ""
done
- name: Show running containers
run: sudo docker ps --format "table {{.Names}}\t{{.Status}}" | head -30
deploy-dev:
if: ${{ github.ref == 'refs/heads/dev' }}
runs-on: ubuntu-dev:host
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Find and deploy changed stacks
env:
DOMAIN: ${{ secrets.DOMAIN }}
run: |
# Find changed stacks
STACKS=$(git diff --name-only HEAD~1 HEAD 2>/dev/null | grep '^stacks/' | cut -d'/' -f2 | sort -u || echo "")
if [ -z "$STACKS" ]; then
echo "No stacks changed, checking all stacks..."
STACKS=$(ls stacks/)
fi
echo "Evaluating stacks: $STACKS"
echo ""
for stack in $STACKS; do
COMPOSE_FILE="stacks/$stack/docker-compose.yml"
# Check stack-type label
STACK_TYPE=$(grep -o 'stack-type=[^"]*' "$COMPOSE_FILE" 2>/dev/null | head -1 | cut -d= -f2)
if [ -z "$STACK_TYPE" ]; then
echo "⚠️ SKIP $stack - no stack-type label found"
continue
fi
# On dev, only deploy 'dev-only' stacks
if [ "$STACK_TYPE" != "dev-only" ]; then
echo "⏭️ SKIP $stack - stack-type=$STACK_TYPE (not for dev)"
continue
fi
echo "=========================================="
echo "Deploying $stack (stack-type=$STACK_TYPE)..."
echo "=========================================="
STACK_DIR="${{ env.STACKS_DIR }}/$stack"
sudo mkdir -p "$STACK_DIR"
# Copy files
sudo cp -r stacks/$stack/* "$STACK_DIR/"
# Create .env from template if .env doesn't exist
if [ -f "$STACK_DIR/.env.template" ] && [ ! -f "$STACK_DIR/.env" ]; then
echo "Creating .env from template..."
sudo sh -c "DOMAIN=$DOMAIN envsubst < '$STACK_DIR/.env.template' > '$STACK_DIR/.env'"
fi
# Deploy
cd "$STACK_DIR"
sudo docker compose pull --ignore-pull-failures 2>/dev/null || true
sudo docker compose up -d --remove-orphans
echo "✅ Deployed $stack"
echo ""
done
- name: Show running containers
run: sudo docker ps --format "table {{.Names}}\t{{.Status}}" | head -30