Skip to content

Commit

Permalink
Set up an automated workflow for playground deployment (GH-40)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyomVancyan authored Apr 19, 2024
2 parents 4d565f4 + 14f8982 commit 2bd2844
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/playground.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: playground

on:
push:
branches: [ master ]

jobs:
deploy:
environment:
name: Playground
url: https://playground.pysnippet.org/fastapi-oauth2
runs-on: ubuntu-latest
steps:
- name: Run deployment script on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY_ED25519 }}
port: ${{ secrets.PORT }}
script: sh ~/fastapi-oauth2/examples/demonstration/deploy.sh
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# fastapi-oauth2 <img src="https://github.com/pysnippet.png" align="right" height="64" />

[![PyPI](https://img.shields.io/pypi/v/fastapi-oauth2.svg)](https://pypi.org/project/fastapi-oauth2/)
[![Playground](https://img.shields.io/badge/playground-blue.svg?logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNzEzNTE0OTc5MTUzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjE2MjciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCI+PHBhdGggZD0iTTc2OCA1MDYuMDI2NjY3djExLjk0NjY2NmEzMi40MjY2NjcgMzIuNDI2NjY3IDAgMCAxLTE1Ljc4NjY2NyAyNy43MzMzMzRMMzcwLjM0NjY2NyA3NjhjLTIzLjA0IDEzLjY1MzMzMy0zNC45ODY2NjcgMTMuNjUzMzMzLTQ1LjIyNjY2NyA3LjY4bC0xMC42NjY2NjctNS45NzMzMzNhMzIuNDI2NjY3IDMyLjQyNjY2NyAwIDAgMS0xNS43ODY2NjYtMjYuODhWMjgxLjE3MzMzM2EzMi40MjY2NjcgMzIuNDI2NjY3IDAgMCAxIDE1Ljc4NjY2Ni0yNy43MzMzMzNsMTAuNjY2NjY3LTUuOTczMzMzYzEwLjI0LTUuOTczMzMzIDIyLjE4NjY2Ny01Ljk3MzMzMyA1Mi4wNTMzMzMgMTEuNTJsMzc1LjA0IDIxOS4zMDY2NjZhMzIuNDI2NjY3IDMyLjQyNjY2NyAwIDAgMSAxNS43ODY2NjcgMjcuNzMzMzM0eiIgcC1pZD0iMTYyOCIgZGF0YS1zcG0tYW5jaG9yLWlkPSJhMzEzeC5zZWFyY2hfaW5kZXguMC5pMS40NzE5M2E4MVdiYjYyWiIgY2xhc3M9IiIgZmlsbD0iI2ZmZmZmZiI+PC9wYXRoPjwvc3ZnPg==)](https://playground.pysnippet.org/fastapi-oauth2/)
[![Python](https://img.shields.io/pypi/pyversions/fastapi-oauth2.svg?logoColor=white)](https://pypi.org/project/fastapi-oauth2/)
[![FastAPI](https://img.shields.io/badge/fastapi-%E2%89%A50.68.1-009486)](https://pypi.org/project/fastapi-oauth2/)
[![Tests](https://github.com/pysnippet/fastapi-oauth2/actions/workflows/tests.yml/badge.svg)](https://github.com/pysnippet/fastapi-oauth2/actions/workflows/tests.yml)
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
pip install build

# build the wheel and install it
WHEEL_NAME=$(python -m build | grep -Po "fastapi_oauth2-.*\.whl" | tail -n 1)
WHEEL_NAME=$(python -m build | grep -Po "fastapi_oauth2-\S*\.whl" | tail -n 1)
pip install dist/$WHEEL_NAME
20 changes: 20 additions & 0 deletions examples/demonstration/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
cd ~/fastapi-oauth2/
git restore .
git pull

cd ~/fastapi-oauth2/examples/demonstration
echo "import main; from fastapi import FastAPI; app = FastAPI(); app.mount('/fastapi-oauth2', main.app)" > playground.py

sudo rm -r /var/www/playground/fastapi-oauth2/
sudo cp -r ~/fastapi-oauth2/examples/demonstration /var/www/playground/fastapi-oauth2/
sudo python3 -m pip install -r /var/www/playground/fastapi-oauth2/requirements.txt

# Update environment variables for production
ENV_FILE=/var/www/playground/fastapi-oauth2/.env
for ENV_KEY in OAUTH2_GITHUB_CLIENT_ID OAUTH2_GITHUB_CLIENT_SECRET OAUTH2_GOOGLE_CLIENT_ID OAUTH2_GOOGLE_CLIENT_SECRET;
do
sudo python3 -c "from dotenv import set_key; set_key('${ENV_FILE}', '${ENV_KEY}', '${!ENV_KEY}')";
done

sudo service playground.fastapi-oauth2 restart
9 changes: 9 additions & 0 deletions examples/demonstration/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fastapi
httpx>=0.23.0
oauthlib>=3.2.2
python-jose>=3.3.0
social-auth-core>=4.4.2
starlette>=0.19.1
sqlalchemy
python-dotenv
fastapi-oauth2

0 comments on commit 2bd2844

Please sign in to comment.