This commit is contained in:
59
.gitea/workflows/deploy.yml
Normal file
59
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
name: Deploy PHP App
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Deploy to server
|
||||||
|
env:
|
||||||
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
||||||
|
SSH_PORT: ${{ secrets.SSH_PORT }}
|
||||||
|
SSH_USER: ${{ secrets.SSH_USER }}
|
||||||
|
SSH_KEY: ${{ secrets.SSH_KEY }}
|
||||||
|
APP_DIR: ${{ secrets.APP_DIR }}
|
||||||
|
REPO_URL: ${{ gitea.server_url }}/${{ gitea.repository }}.git
|
||||||
|
BRANCH: ${{ gitea.ref_name }}
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_KEY" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
ssh-keyscan -p "$SSH_PORT" "$SSH_HOST" >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
ssh -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" "
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo '--- Preparing app directory ---'
|
||||||
|
mkdir -p \"$APP_DIR\"
|
||||||
|
|
||||||
|
if [ -d \"$APP_DIR/.git\" ]; then
|
||||||
|
echo 'Repo exists. Pulling latest code...'
|
||||||
|
cd \"$APP_DIR\"
|
||||||
|
git fetch origin
|
||||||
|
git reset --hard origin/$BRANCH
|
||||||
|
else
|
||||||
|
echo 'Repo does not exist. Cloning fresh copy...'
|
||||||
|
rm -rf \"$APP_DIR\"
|
||||||
|
git clone -b \"$BRANCH\" \"$REPO_URL\" \"$APP_DIR\"
|
||||||
|
cd \"$APP_DIR\"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo '--- Stopping old containers ---'
|
||||||
|
docker compose down --remove-orphans || true
|
||||||
|
|
||||||
|
echo '--- Removing old unused images ---'
|
||||||
|
docker image prune -af || true
|
||||||
|
|
||||||
|
echo '--- Starting new containers ---'
|
||||||
|
docker compose up -d --build
|
||||||
|
|
||||||
|
echo '--- Deployment completed ---'
|
||||||
|
"
|
||||||
Reference in New Issue
Block a user