Skip to content

Commit d1bf351

Browse files
kstrassheimKonstantin Strassheim
andauthored
Init (#1)
* added vite project * added requirements file * added working static page serve * added working prod dev api switch * added full debug config * Add or update the Azure App Service build and deployment workflow config * Added frontend build * fixed intall python * added flatten output * added manual deployment * set azure startup command * reset deloyment file * added run command at the end * fixed dir * fixed debugging and action trigger --------- Co-authored-by: Konstantin Strassheim <konstantin.strassheim@gmail.com>
1 parent fecad85 commit d1bf351

File tree

22 files changed

+2703
-0
lines changed

22 files changed

+2703
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions
4+
5+
name: Build and deploy Python app to Azure Web App - fast-api-reference
6+
7+
on:
8+
pull_request:
9+
types: [closed]
10+
branches:
11+
- main
12+
workflow_dispatch:
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read #This is required for actions/checkout
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Download npm
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: '3.13'
27+
28+
- name: Set up Python version
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.13'
32+
33+
- name: Create and start virtual environment
34+
run: |
35+
cd backend
36+
python -m venv venv
37+
source venv/bin/activate
38+
39+
- name: Install dependencies
40+
run: |
41+
cd backend
42+
pip install -r requirements.txt
43+
44+
- name: Install Node dependencies
45+
run: |
46+
cd frontend
47+
npm install
48+
49+
- name: Build Frontend
50+
run: |
51+
cd frontend
52+
npm run build
53+
54+
- name: Zip artifact for deployment
55+
run: |
56+
cd backend
57+
zip -r ../release.zip ./*
58+
59+
- name: Upload artifact for deployment jobs
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: python-app
63+
path: |
64+
release.zip
65+
!venv/
66+
67+
deploy:
68+
runs-on: ubuntu-latest
69+
needs: build
70+
environment:
71+
name: 'Production'
72+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
73+
permissions:
74+
id-token: write #This is required for requesting the JWT
75+
contents: read #This is required for actions/checkout
76+
77+
steps:
78+
- name: Download artifact from build job
79+
uses: actions/download-artifact@v4
80+
with:
81+
name: python-app
82+
83+
- name: Unzip artifact for deployment
84+
run: unzip release.zip
85+
86+
87+
- name: Login to Azure
88+
uses: azure/login@v2
89+
with:
90+
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_07118B6326EE492693A4582BDAE9294E }}
91+
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_98091920E4D5432E9786AA6ADFC34B54 }}
92+
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_7BFCF659655641B8987A25BBEF11D64A }}
93+
94+
- name: 'Deploy to Azure Web App'
95+
uses: azure/webapps-deploy@v3
96+
id: deploy-to-webapp
97+
with:
98+
app-name: 'fast-api-reference'
99+
slot-name: 'Production'
100+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,6 @@ cython_debug/
172172

173173
# PyPI configuration file
174174
.pypirc
175+
176+
177+
backend/dist/*

.vscode/launch.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "FastAPI",
9+
"type": "python",
10+
"command": "pkill -f uvicorn || true",
11+
"request": "launch",
12+
"module": "uvicorn",
13+
"args": [
14+
"main:app", // Adjust to your FastAPI entry point
15+
"--reload"
16+
],
17+
"jinja": true,
18+
"justMyCode": true,
19+
"env": {
20+
"PYTHONPATH": "${workspaceFolder}/backend"
21+
},
22+
"cwd": "${workspaceFolder}/backend",
23+
"preLaunchTask": "Build Vite Frontend"
24+
},
25+
{
26+
"name": "Vite Dev Server",
27+
"type": "node-terminal",
28+
"request": "launch",
29+
"command": "npm run dev", // Assumes your package.json has a "dev" script for Vite
30+
"cwd": "${workspaceFolder}/frontend",
31+
"console": "integratedTerminal"
32+
},
33+
{
34+
"name": "Chrome Debug",
35+
"type": "chrome",
36+
"request": "launch",
37+
"url": "http://localhost:5173", // Adjust if your Vite dev server uses a different port
38+
"webRoot": "${workspaceFolder}/frontend"
39+
}
40+
],
41+
"compounds": [
42+
{
43+
"name": "Full Stack Debug",
44+
"configurations": [
45+
"FastAPI",
46+
"Vite Dev Server",
47+
"Chrome Debug"
48+
]
49+
}
50+
]
51+
}

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// filepath: /home/kstrassheim/projects/fastapi-reference/.vscode/settings.json
2+
{
3+
"python.terminal.activateEnvironment": true,
4+
"python.defaultInterpreterPath": "${workspaceFolder}/backend/venv/bin/python" // Adjust if your venv is in a different folder
5+
}

.vscode/tasks.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Build Vite Frontend",
6+
"type": "shell",
7+
"command": "npm run build",
8+
"options": {
9+
"cwd": "${workspaceFolder}/frontend"
10+
},
11+
"problemMatcher": []
12+
}
13+
]
14+
}

Dockerfile

Whitespace-only changes.

backend/_init_.py

Whitespace-only changes.

backend/main.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from fastapi import FastAPI, APIRouter
2+
from fastapi.middleware.cors import CORSMiddleware
3+
from fastapi.staticfiles import StaticFiles
4+
from fastapi.responses import FileResponse
5+
from os import path as os_path
6+
7+
app = FastAPI()
8+
9+
origins = [
10+
"http://localhost:5173",
11+
"localhost:5173"
12+
]
13+
14+
app.add_middleware(
15+
CORSMiddleware,
16+
allow_origins=origins,
17+
allow_credentials=True,
18+
allow_methods=["*"],
19+
allow_headers=["*"]
20+
)
21+
22+
api_router = APIRouter()
23+
24+
@api_router.get("/hello")
25+
def read_hello():
26+
return {"message": "Hello from API"}
27+
28+
app.include_router(api_router, prefix="/api")
29+
30+
# Mount static files on /static (adjust if you want a different prefix)
31+
app.mount("", StaticFiles(directory="./dist", html=True), name="client")
32+
33+
# Optional: Serve index.html at the root
34+
@app.get('/')
35+
async def client(): return RedirectResponse(url="client")
36+
37+
if __name__ == '__main__':
38+
uvicorn.run('main:app', reload=True)

backend/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fastapi==0.68.1
2+
uvicorn==0.15.0
3+
aiofiles==24.1.0

frontend/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

0 commit comments

Comments
 (0)