Skip to content

Instantly share code, notes, and snippets.

@arynyklas
Created November 7, 2024 12:01
Show Gist options
  • Save arynyklas/cd90089ea14ea44671c1ed3f90682b8e to your computer and use it in GitHub Desktop.
Save arynyklas/cd90089ea14ea44671c1ed3f90682b8e to your computer and use it in GitHub Desktop.
Auto deploy application using Github Workflow
name: Deploy to Server
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create SSH Key File
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > /tmp/deploy_key
chmod 600 /tmp/deploy_key
- name: Deploy to Server
run: |
ssh -o StrictHostKeyChecking=no -i /tmp/deploy_key -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
cd /home/app/
git reset --hard
git pull origin main
source .venv/bin/activate
pip install -r requirements.txt > /dev/null
sudo /usr/local/bin/restart-app.sh && echo "Deployed successfully"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment