Add deployment workflows for development and production environments
Some checks failed
Deploy Production (ss-tool.crewsportswear.app) / deploy (push) Failing after 3m16s
Some checks failed
Deploy Production (ss-tool.crewsportswear.app) / deploy (push) Failing after 3m16s
This commit is contained in:
111
.gitea/workflows/deploy.yml
Normal file
111
.gitea/workflows/deploy.yml
Normal 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"
|
||||
Reference in New Issue
Block a user