-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Deploy to Server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
password: ${{ secrets.SSH_PASSWORD }} | ||
port: ${{ secrets.SSH_PORT }} | ||
script: "cd /var/www/python-api && chmod +x ./.scripts/deploy.sh && bash ./.scripts/deploy.sh" |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
PYTHON_PATH=/usr/bin/python3 | ||
PIP_PATH=/usr/bin/pip | ||
UVICORN_PATH=/usr/local/bin/uvicorn | ||
|
||
echo "Deployment started ..." | ||
|
||
# Enter maintenance mode or return true if already in maintenance mode | ||
kill -SIGINT $(ps aux | grep uvicorn | grep -v grep | awk '{print $2}') || true | ||
|
||
# Pull the latest version of the app | ||
git fetch origin master | ||
git reset --hard origin/master | ||
git pull origin master | ||
|
||
# Exit maintenance mode | ||
$PYTHON_PATH $PIP_PATH $UVICORN_PATH main:app | ||
|
||
echo "Deployment finished!" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
# python-api | ||
# Python API | ||
Python API | ||
|
||
### Install Fast API | ||
```bash | ||
pip install "fastapi[all]" | ||
``` | ||
|
||
### Start & Stop Server | ||
```bash | ||
#Start | ||
uvicorn main:app | ||
|
||
#Stop | ||
kill -SIGINT $(ps aux | grep uvicorn | grep -v grep | awk '{print $2}') | ||
``` | ||
|
||
### API Documentataion | ||
|
||
[api.gopibabu.dev](https://api.gopibabu.dev/) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from fastapi import FastAPI | ||
import random | ||
|
||
app = FastAPI() | ||
|
||
@app.get('/') | ||
async def root(): | ||
return {'example': 'This is an example', 'data': 0} | ||
|
||
@app.get('/random') | ||
async def get_random(): | ||
rn: int = random.randint(0, 100) | ||
return {'number': rn, 'limit': 100} | ||
|
||
@app.get('/random/{limit}') | ||
async def get_random(limit: int): | ||
rn: int = random.randint(0, limit) | ||
return {'number': rn, 'limit': limit} |