Add deployment workflows for development and production environments
Some checks failed
Deploy Production (ss-tool.crewsportswear.app) / deploy (push) Failing after 3m16s

This commit is contained in:
Frank John Begornia
2025-12-23 01:58:25 +08:00
parent 7ae0929e91
commit a60488b222
3 changed files with 225 additions and 3 deletions

View File

@@ -0,0 +1,111 @@
name: Deploy Development (dev.ss-tool.crewsportswear.app)
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 screenshot-tools:dev .
docker save screenshot-tools:dev | gzip > screenshot-tools-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/screenshot-tools-dev.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-dev"
sudo mkdir -p "$DEPLOY_DIR"
sudo chown $USER:$USER "$DEPLOY_DIR"
echo "📦 Loading Docker image"
docker load < /tmp/screenshot-tools-dev.tar.gz
docker tag screenshot-tools:dev screenshot-tools:latest
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://dev.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-dev.tar.gz
echo "✅ Development 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-dev.tar.gz
echo "✅ Cleanup completed"

111
.gitea/workflows/deploy.yml Normal file
View File

@@ -0,0 +1,111 @@
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"