Files
screenshot-tools/.gitea/workflows/deploy.yml
Frank John Begornia a60488b222
Some checks failed
Deploy Production (ss-tool.crewsportswear.app) / deploy (push) Failing after 3m16s
Add deployment workflows for development and production environments
2025-12-23 01:58:25 +08:00

112 lines
3.3 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Deploy Production (ss-tool.crewsportswear.app)
on:
push:
branches:
- main
- master
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 screenshot-tools:latest .
docker save screenshot-tools:latest | gzip > screenshot-tools.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/screenshot-tools.tar.gz \
/workspace/repo/docker-compose.traefik.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/screenshot-tools"
sudo mkdir -p "$DEPLOY_DIR"
sudo chown $USER:$USER "$DEPLOY_DIR"
echo "📦 Loading Docker image"
docker load < /tmp/screenshot-tools.tar.gz
echo "📋 Moving files to deployment directory"
mv /tmp/docker-compose.traefik.yml "$DEPLOY_DIR/"
cd "$DEPLOY_DIR"
echo "🔧 Creating .env file if not exists"
if [ ! -f .env ]; then
cat > .env << 'ENVFILE'
PORT=5955
HOST=0.0.0.0
USE_SSL=false
OUTPUT_DIR=/var/www/html/images/
BASE_URL=https://ss-tool.crewsportswear.app/
VIEWPORT_WIDTH=1366
VIEWPORT_HEIGHT=1100
WAIT_TIME=10000
ENVFILE
fi
echo "🐳 Stopping existing containers"
docker compose -f docker-compose.traefik.yml down || true
echo "🚀 Starting new containers"
docker compose -f docker-compose.traefik.yml up -d
echo "🧹 Cleanup"
rm -f /tmp/screenshot-tools.tar.gz
echo "✅ Deployment completed successfully!"
docker compose -f docker-compose.traefik.yml ps
EOF
# 6⃣ Cleanup local artifacts
- name: Cleanup
shell: sh
run: |
rm -f /workspace/repo/screenshot-tools.tar.gz
echo "✅ Cleanup completed"