Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gopibabus committed Oct 24, 2023
1 parent 2e63fab commit 1bf4370
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/deploy.yml
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 added .gitignore
Empty file.
22 changes: 22 additions & 0 deletions .scripts/deploy.sh
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!"
20 changes: 19 additions & 1 deletion README.md
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/)
18 changes: 18 additions & 0 deletions main.py
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}

0 comments on commit 1bf4370

Please sign in to comment.