deploy workflow #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Python project to Nginx server | |
| on: | |
| push: | |
| branches: [ main, deploy-test ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install pip tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| - name: Setup SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | |
| - name: Upload repository to server | |
| run: | | |
| rsync -az --delete \ | |
| -e "ssh" \ | |
| --exclude '.git' \ | |
| . \ | |
| "${{ secrets.USERNAME }}@${{ secrets.SERVER_IP }}:${{ secrets.PROJECT_PATH }}/" | |
| - name: Install dependencies via SSH | |
| run: | | |
| ssh "${{ secrets.USERNAME }}@${{ secrets.SERVER_IP }}" " | |
| cd '${{ secrets.PROJECT_PATH }}' && \ | |
| python3 -m venv venv && \ | |
| source venv/bin/activate && \ | |
| pip install --upgrade pip && \ | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| " |