Last active
February 26, 2023 01:32
-
-
Save aybruhm/68d99656efa35b4d103e003975329be8 to your computer and use it in GitHub Desktop.
This is an action workflow that will deploy your python (django, fastapi, flask) application to a VPS (Digital Ocean, EC2 Instance, etc)
This file contains 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: Build & Deploy | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Pull New Changes | |
uses: appleboy/ssh-action@v0.1.5 | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
port: ${{ secrets.SSH_PORT }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} # if you deploying to aws ec2, replace ssh_key with your pem file | |
script: | | |
cd /path/to/project_dir | |
git pull origin dev | |
- name: Deploy Backend | |
uses: appleboy/ssh-action@v0.1.5 | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
port: ${{ secrets.SSH_PORT }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} # if you deploying to aws ec2, replace ssh_key with your pem file | |
script: | | |
cd /path/to/project_dir | |
# --------------------------------- | |
# INSERT DEPLOYMENT COMMAND HERE | |
# --------------------------------- | |
echo 'Deployment successful!' |
Where;
- secrets.SSH_HOST is the IP address of the server you wish to SSH into
- secrets.SSH_PORT is the port number of the server you wish to SSH into. Default is 22
- secrets.SSH_KEY is the private key of the server or pem file for ec2 instance
- secrets.SSH_USERNAME is the user of the server you want to SSH into. Default is ubuntu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the section where you see: "INSERT DEPLOYMENT COMMAND HERE", kindly replace the entire comment with the deployment command for the Python web framework you are using.
Examples
1). For Django, update with the following:
2). For FastAPI, update with the following:
3). For Flask, update with the following: