Updated deploy script
This commit is contained in:
@@ -78,27 +78,74 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Deploy via SSH
|
- name: Deploy to server
|
||||||
uses: appleboy/ssh-action@v1
|
env:
|
||||||
with:
|
DEPLOY_HOST: ${{ vars.DEPLOY_HOST }}
|
||||||
host: ${{ vars.DEPLOY_HOST }}
|
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
|
||||||
port: ${{ vars.SSH_PORT }}
|
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
|
||||||
username: ${{ vars.DEPLOY_USER }}
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
SSH_KNOWN_HOSTS: ${{ vars.SSH_KNOWN_HOSTS }}
|
||||||
known_hosts: ${{ vars.SSH_KNOWN_HOSTS }}
|
SSH_PORT: ${{ vars.SSH_PORT || '22' }}
|
||||||
script: |
|
run: |
|
||||||
cd ${{ vars.DEPLOY_PATH }}
|
# Install tools missing from runner image
|
||||||
git pull origin main
|
sudo apt-get update -qq && sudo apt-get install -y -qq rsync openssh-client > /dev/null 2>&1 || true
|
||||||
|
|
||||||
|
# Write SSH credentials
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
SSH_OPTS="-i ~/.ssh/deploy_key -o StrictHostKeyChecking=no -p $SSH_PORT"
|
||||||
|
|
||||||
|
# Sync application files
|
||||||
|
rsync -avz --delete \
|
||||||
|
--exclude '.git/' \
|
||||||
|
--exclude '.gitea/' \
|
||||||
|
--exclude '.env' \
|
||||||
|
--exclude '.venv/' \
|
||||||
|
--exclude '__pycache__/' \
|
||||||
|
--exclude '.pytest_cache/' \
|
||||||
|
--exclude 'logs/' \
|
||||||
|
--exclude '*.pyc' \
|
||||||
|
--exclude 'frontend/node_modules/' \
|
||||||
|
--exclude 'frontend/dist/' \
|
||||||
|
-e "ssh $SSH_OPTS" \
|
||||||
|
./ ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/
|
||||||
|
|
||||||
|
# Install deps & restart on server
|
||||||
|
ssh $SSH_OPTS ${DEPLOY_USER}@${DEPLOY_HOST} << REMOTE_SCRIPT
|
||||||
|
set -e
|
||||||
|
cd ${DEPLOY_PATH}
|
||||||
|
|
||||||
|
# Create venv if not exists
|
||||||
|
if [ ! -d ".venv" ]; then
|
||||||
|
python3 -m venv .venv
|
||||||
|
fi
|
||||||
|
|
||||||
source .venv/bin/activate
|
source .venv/bin/activate
|
||||||
pip install -e .
|
pip install --quiet --upgrade pip
|
||||||
|
pip install --quiet -e .
|
||||||
|
|
||||||
|
# Setup DB and run migrations
|
||||||
if [ "${{ inputs.run_setup_db }}" = "true" ] || [ "${{ github.event.inputs.run_setup_db }}" = "true" ]; then
|
if [ "${{ inputs.run_setup_db }}" = "true" ] || [ "${{ github.event.inputs.run_setup_db }}" = "true" ]; then
|
||||||
chmod +x deploy/setup_db.sh
|
chmod +x deploy/setup_db.sh
|
||||||
./deploy/setup_db.sh
|
./deploy/setup_db.sh
|
||||||
else
|
else
|
||||||
alembic upgrade head
|
alembic upgrade head
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Build frontend
|
||||||
cd frontend
|
cd frontend
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
npm run build
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
|
# Restart service
|
||||||
sudo systemctl restart stock-data-backend
|
sudo systemctl restart stock-data-backend
|
||||||
|
echo "✓ stock-data-backend deployed"
|
||||||
|
|
||||||
|
REMOTE_SCRIPT
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -f ~/.ssh/deploy_key
|
||||||
|
|||||||
Reference in New Issue
Block a user