This commit is contained in:
93
.gitea/workflows/deploy.yml
Normal file
93
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,93 @@
|
||||
name: Deploy Production
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
shell: sh
|
||||
run: |
|
||||
git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git /workspace/repo || true
|
||||
cd /workspace/repo
|
||||
git fetch origin $GITHUB_REF_NAME
|
||||
git checkout $GITHUB_REF_NAME
|
||||
git pull origin $GITHUB_REF_NAME
|
||||
|
||||
- name: Build Docker Image
|
||||
shell: sh
|
||||
run: |
|
||||
cd /workspace/repo
|
||||
docker build -t tablejerseys-web:latest .
|
||||
docker save tablejerseys-web:latest | gzip > tablejerseys-web.tar.gz
|
||||
|
||||
- name: Setup SSH and Deploy
|
||||
shell: sh
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
echo "$DEPLOY_SSH_KEY" > ~/.ssh/deploy_key
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
ssh-keygen -y -f ~/.ssh/deploy_key > /dev/null 2>&1 || { echo "Error: Invalid SSH key format"; exit 1; }
|
||||
|
||||
cd /workspace/repo
|
||||
scp -o StrictHostKeyChecking=no -i ~/.ssh/deploy_key tablejerseys-web.tar.gz docker-compose.yml "$DEPLOY_USER@$DEPLOY_HOST:/tmp/"
|
||||
|
||||
ssh -o StrictHostKeyChecking=no -i ~/.ssh/deploy_key "$DEPLOY_USER@$DEPLOY_HOST" '
|
||||
DEPLOY_DIR="/var/www/apps/tablejerseys-web"
|
||||
mkdir -p $DEPLOY_DIR
|
||||
cd /tmp
|
||||
docker load < tablejerseys-web.tar.gz
|
||||
|
||||
echo "Removing old tablejerseys-web images"
|
||||
CURRENT_IMAGE=$(docker images tablejerseys-web:latest -q)
|
||||
docker images | grep tablejerseys-web | grep -v "$CURRENT_IMAGE" | awk "{print \$3}" | xargs -r docker rmi -f || true
|
||||
|
||||
cp docker-compose.yml $DEPLOY_DIR/
|
||||
cd $DEPLOY_DIR
|
||||
|
||||
echo "Checking .env file"
|
||||
if [ ! -f .env ]; then
|
||||
echo "Error: .env file not found at $DEPLOY_DIR/.env"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker compose down || true
|
||||
docker image prune -f
|
||||
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
|
||||
export DOMAIN=tablejerseys.com
|
||||
docker compose up -d
|
||||
sleep 10
|
||||
rm -f /tmp/tablejerseys-web.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 "Production deployment completed successfully!"
|
||||
echo "Application available at: https://tablejerseys.com"
|
||||
'
|
||||
env:
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
|
||||
- name: Health Check
|
||||
shell: sh
|
||||
run: |
|
||||
sleep 10
|
||||
curl -f https://tablejerseys.com || exit 1
|
||||
Reference in New Issue
Block a user