Skip to content

Commit b4726e2

Browse files
committed
Deploy workflow
1 parent b593e51 commit b4726e2

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Deploy to server
2+
3+
on:
4+
push:
5+
branches: [ main, deploy-workflow ]
6+
7+
jobs:
8+
build-and-deploy:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Setup SSH
16+
run: |
17+
mkdir -p ~/.ssh
18+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
19+
chmod 600 ~/.ssh/id_rsa
20+
ssh-keyscan -H "${{ secrets.SERVER_IP }}" >> ~/.ssh/known_hosts
21+
22+
- name: Upload entire repository (preserve venv on server)
23+
run: |
24+
rsync -az --delete \
25+
--exclude='venv/' \
26+
-e "ssh -o StrictHostKeyChecking=yes" \
27+
./ \
28+
"${{ secrets.USERNAME }}@${{ secrets.SERVER_IP }}:${{ secrets.PROJECT_PATH }}/"
29+
30+
- name: Install deps and restart service on server
31+
run: |
32+
ssh -T -o StrictHostKeyChecking=yes \
33+
"${{ secrets.USERNAME }}@${{ secrets.SERVER_IP }}" <<'EOF' > /dev/null
34+
set -euo pipefail
35+
cd "${{ secrets.PROJECT_PATH }}"
36+
# Activate existing venv and install/upgrade deps
37+
source "${{ secrets.PROJECT_PATH }}/venv/bin/activate"
38+
pip3 install --upgrade pip
39+
pip3 install -r requirements.txt
40+
# Restart your service
41+
sudo systemctl restart parktrack-api-server
42+
EOF

src/api/api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from fastapi import FastAPI
22
from pydantic import BaseModel
3+
from fastapi.middleware.cors import CORSMiddleware
34

45

56
class URL(BaseModel):
@@ -20,6 +21,14 @@ def __init__(self, db_manager):
2021
version=self.version,
2122
description=self.description
2223
)
24+
self.app.add_middleware(
25+
CORSMiddleware,
26+
allow_origins=[
27+
"https://parktrack-swagger.nawinds.dev",
28+
"https://parktrack-labeler.nawinds.dev"
29+
],
30+
allow_credentials=True,
31+
)
2332
self._setup_routes()
2433

2534
def run(self, listen_on: URL):
@@ -35,4 +44,4 @@ def get_health():
3544

3645
@self.app.get("/version")
3746
def get_version():
38-
return {self.version}
47+
return {"api_version": self.version}

src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def main():
55
api_server = PublicAPI(db_manager=DBManager("mock"))
6-
api_server.run(URL(host="0.0.0.0", port=8000))
6+
api_server.run(URL(host="127.0.0.1", port=8000))
77

88
if __name__ == "__main__":
99
main()

0 commit comments

Comments
 (0)