141 lines
4.4 KiB
YAML
141 lines
4.4 KiB
YAML
name: Deploy Development
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- dev
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
deploy:
|
||
runs-on: ubuntu-latest
|
||
container:
|
||
image: catthehacker/ubuntu:act-latest
|
||
|
||
steps:
|
||
# 1️⃣ Checkout code
|
||
- name: Checkout code
|
||
shell: sh
|
||
run: |
|
||
git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git /workspace/repo
|
||
cd /workspace/repo
|
||
git checkout $GITHUB_REF_NAME
|
||
|
||
# 2️⃣ Build image
|
||
- name: Build Docker image
|
||
shell: sh
|
||
run: |
|
||
cd /workspace/repo
|
||
docker build -t tablejerseys-web:dev .
|
||
docker save tablejerseys-web:dev | gzip > tablejerseys-web_dev.tar.gz
|
||
|
||
# 3️⃣ Setup SSH
|
||
- name: Setup SSH
|
||
shell: sh
|
||
env:
|
||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||
run: |
|
||
mkdir -p ~/.ssh
|
||
chmod 700 ~/.ssh
|
||
echo "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
|
||
chmod 600 ~/.ssh/id_ed25519
|
||
ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
|
||
|
||
# 4️⃣ Upload artifacts
|
||
- name: Upload image and compose
|
||
shell: sh
|
||
env:
|
||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||
run: |
|
||
scp -i ~/.ssh/id_ed25519 \
|
||
/workspace/repo/tablejerseys-web_dev.tar.gz \
|
||
/workspace/repo/docker-compose.yml \
|
||
${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/
|
||
|
||
# 5️⃣ Deploy on server
|
||
- name: Deploy on server
|
||
shell: sh
|
||
env:
|
||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||
|
||
run: |
|
||
ssh -i ~/.ssh/id_ed25519 $DEPLOY_USER@$DEPLOY_HOST << 'EOF'
|
||
set -e
|
||
|
||
DEPLOY_DIR="/var/www/apps/tablejerseys-web_dev"
|
||
mkdir -p "$DEPLOY_DIR"
|
||
|
||
echo "📦 Loading image"
|
||
docker load < /tmp/tablejerseys-web_dev.tar.gz
|
||
|
||
echo "🧹 Removing old tablejerseys-web images"
|
||
docker images | grep tablejerseys-web | grep -v "$(docker images tablejerseys-web:dev -q)" | awk '{print $3}' | xargs -r docker rmi -f || true
|
||
|
||
echo "📄 Updating compose file"
|
||
cp /tmp/docker-compose.yml "$DEPLOY_DIR/"
|
||
|
||
cd "$DEPLOY_DIR"
|
||
|
||
echo "🔍 Checking .env file"
|
||
if [ ! -f .env ]; then
|
||
echo "❌ .env file not found at $DEPLOY_DIR/.env"
|
||
echo "Please create it first with required variables:"
|
||
echo " - NUXT_PUBLIC_*, STRIPE_SECRET_KEY"
|
||
exit 1
|
||
fi
|
||
|
||
echo "🔧 Fixing .env permissions"
|
||
sudo chown $USER:$USER .env
|
||
sudo chmod 600 .env
|
||
|
||
echo "🌐 Ensure networks"
|
||
docker network inspect traefik-public >/dev/null 2>&1 || \
|
||
docker network create traefik-public
|
||
docker network inspect crew-app-net >/dev/null 2>&1 || \
|
||
docker network create crew-app-net
|
||
|
||
echo "🚀 Starting containers (env vars from .env file)"
|
||
export COMPOSE_PROJECT_NAME=tablejerseys-web-dev
|
||
docker compose down || true
|
||
docker compose up -d --remove-orphans
|
||
|
||
echo "🧪 Testing container health"
|
||
sleep 15
|
||
if ! docker ps | grep -q tablejerseys-web; then
|
||
echo "❌ Container not running"
|
||
docker compose logs --tail=50
|
||
exit 1
|
||
fi
|
||
|
||
echo "🎉 Dev deployment complete!"
|
||
docker compose ps
|
||
|
||
echo "🧹 Cleanup"
|
||
rm -f /tmp/tablejerseys-web_dev.tar.gz /tmp/docker-compose.yml
|
||
|
||
echo "🗑️ Aggressive Docker cleanup to reclaim space"
|
||
docker image prune -af --filter "until=24h" || true
|
||
docker container prune -f || true
|
||
docker volume prune -f || true
|
||
docker builder prune -af --filter "until=48h" || true
|
||
|
||
echo "💾 Docker space usage:"
|
||
docker system df
|
||
|
||
echo "✅ Dev deployment completed successfully"
|
||
EOF
|
||
|
||
# 6️⃣ Verify deployment
|
||
- name: Verify deployment
|
||
shell: sh
|
||
env:
|
||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||
run: |
|
||
sleep 5
|
||
ssh -i ~/.ssh/id_ed25519 $DEPLOY_USER@$DEPLOY_HOST \
|
||
"docker ps | grep tablejerseys-web || exit 1"
|