-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated example to include two services
- Loading branch information
1 parent
bd72ea1
commit ab4e046
Showing
92 changed files
with
440 additions
and
12,577 deletions.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
5 changes: 5 additions & 0 deletions
5
examples/kubernetes-tilt-dev/apps/python-fastapi-app/.env.example
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,5 @@ | ||
MONGO_ROOT_USERNAME=root | ||
MONGO_ROOT_PASSWORD=supersecret | ||
MONGO_USERNAME=user1 | ||
MONGO_PASSWORD=supersecurepassword | ||
MONGO_DATABASE=test_db |
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,8 @@ | ||
[flake8] | ||
ignore = E203, E266, E501, W503, F403, F401, B008 | ||
max-line-length = 89 | ||
max-complexity = 18 | ||
select = B,C,E,F,W,T4,B9 | ||
require-plugins = | ||
flake8-bugbear | ||
flake8-black |
146 changes: 146 additions & 0 deletions
146
examples/kubernetes-tilt-dev/apps/python-fastapi-app/.gitignore
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,146 @@ | ||
##### IDE's ##### | ||
# VisualStudioCode | ||
/.vscode/ | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
*.code-workspace | ||
.history | ||
|
||
# IntelliJ IDEA | ||
.idea/* | ||
|
||
##### Database ##### | ||
*.accdb | ||
*.db | ||
*.dbf | ||
*.mdb | ||
*.pdb | ||
*.sqlite3 | ||
|
||
##### Logs ##### | ||
*.log | ||
*.log* | ||
|
||
##### Python ##### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64 | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
bin/ | ||
|
||
# Environments | ||
Makefile | ||
.env | ||
.env.* | ||
!.env.example | ||
!.env.local | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
.flaskenv | ||
pyvenv.cfg | ||
|
||
# PyInstaller | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# PEP 582 | ||
__pypackages__/ | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# C extensions | ||
*.so | ||
|
||
##### Heroku (old) ##### | ||
Procfile | ||
|
||
### | ||
postgres-calculate/ | ||
|
||
app/authentication/test_view.py | ||
|
||
# Serverless | ||
node_modules/ | ||
.serverless/ | ||
|
||
# wsgi | ||
wsgi_handler.py | ||
serverless_wsgi.py | ||
.serverless-wsgi |
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
examples/kubernetes-tilt-dev/apps/python-fastapi-app/.pre-commit-config.yaml
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,13 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/ambv/black | ||
rev: 23.1.0 | ||
hooks: | ||
- id: black | ||
language_version: python3 | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.0.0 | ||
hooks: | ||
- id: flake8 | ||
additional_dependencies: [flake8-black, flake8-bugbear] |
58 changes: 58 additions & 0 deletions
58
examples/kubernetes-tilt-dev/apps/python-fastapi-app/Dockerfile
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,58 @@ | ||
# Stage 1: Build development dependencies | ||
FROM python:3.12.0 AS builder-dev | ||
|
||
WORKDIR /code | ||
|
||
# Copy development requirements files | ||
COPY requirements*.txt ./ | ||
|
||
# Install development dependencies | ||
RUN pip install --no-cache-dir -r requirements.dev.txt | ||
|
||
# Stage 2: Build production dependencies | ||
FROM python:3.12.0-alpine AS builder-prod | ||
|
||
WORKDIR /code | ||
|
||
# Copy production requirements file | ||
COPY requirements.txt ./ | ||
|
||
# Install production dependencies | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
FROM builder-dev AS development | ||
|
||
# Copy development dependencies from builder-dev stage | ||
COPY --from=builder-dev /usr/local /usr/local | ||
|
||
# Copy the application code | ||
COPY ./app ./app | ||
|
||
# Create a non-root user to run the application | ||
RUN adduser --disabled-password nonroot | ||
|
||
# Switch to the non-root user | ||
USER nonroot | ||
|
||
# Command to run the application | ||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--reload"] | ||
|
||
# Stage 3: Final image | ||
FROM python:3.12.0-alpine as production | ||
|
||
WORKDIR /code | ||
|
||
# Copy production dependencies from builder-prod stage | ||
COPY --from=builder-prod /usr/local /usr/local | ||
|
||
# Copy the application code | ||
COPY ./app ./app | ||
|
||
# Create a non-root user to run the application | ||
RUN adduser --disabled-password nonroot | ||
|
||
# Switch to the non-root user | ||
USER nonroot | ||
|
||
# Command to run the application | ||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] |
57 changes: 57 additions & 0 deletions
57
examples/kubernetes-tilt-dev/apps/python-fastapi-app/README.md
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,57 @@ | ||
# FastAPI Example 🚀 | ||
|
||
## Requirements 🛠️ | ||
|
||
To get started, make sure you have the following tools installed on your machine: | ||
|
||
- Docker 🐳 | ||
- Docker Compose 🐳 | ||
- Python 🐍 | ||
|
||
**Python Version:** You'll need Python 3.12 installed on your local development machine. You can use [pyenv](https://github.com/pyenv/pyenv) to easily switch Python versions between different projects. If you're on Windows, consider using [pyenv-win](https://github.com/pyenv-win/pyenv-win). | ||
|
||
```sh | ||
pyenv install | ||
pyenv local | ||
``` | ||
|
||
### Gotchas for Certain Environments 🧐 | ||
|
||
Depending on your development environment, you may also need to create and activate a virtual environment for Python. Follow these steps: | ||
|
||
```sh | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
pip install -r requirements.dev.txt | ||
``` | ||
|
||
For Windows users using WSL2, ensure you have Docker Desktop installed, running, and configured with a [WSL2 connection](https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers). | ||
|
||
## Setup the Development Environment 🛠️ | ||
|
||
- Install the project dependencies: | ||
|
||
```sh | ||
pip install -r requirements.dev.txt | ||
``` | ||
|
||
- Install pre-commit hooks: | ||
|
||
```sh | ||
pre-commit install | ||
``` | ||
|
||
## Running the App 🏃♀️🏃♂️ | ||
|
||
To launch the app, simply run: | ||
|
||
```sh | ||
cp .env.example .env # Then Edit .env file with your own values | ||
docker-compose up | ||
``` | ||
|
||
Your app will be up and running in no time! 🚀🎉 | ||
|
||
This will start the following services: | ||
|
||
- `web`: FastAPI server running at [http://localhost:80](http://localhost:80) |
Empty file.
9 changes: 9 additions & 0 deletions
9
examples/kubernetes-tilt-dev/apps/python-fastapi-app/app/config.py
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,9 @@ | ||
import os | ||
from typing import Any | ||
|
||
APP_VERSION: str = "1" | ||
|
||
app_configs: dict[str, Any] = { | ||
"title": "FastAPI Example", | ||
"root_path": os.getenv("ROOT_PATH", ""), | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/kubernetes-tilt-dev/apps/python-fastapi-app/app/main.py
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 | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from .config import app_configs | ||
from .router.routes import router as api_router | ||
|
||
ALLOWED_ORIGINS = [ | ||
"*", | ||
] | ||
app = FastAPI(**app_configs) | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=ALLOWED_ORIGINS, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
app.include_router(api_router) |
Empty file.
12 changes: 12 additions & 0 deletions
12
examples/kubernetes-tilt-dev/apps/python-fastapi-app/app/router/routes.py
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,12 @@ | ||
from fastapi import APIRouter | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/") | ||
async def root(): | ||
return {"message": "Hello World :D"} | ||
|
||
@router.get("/healthz") | ||
async def healthcheck() -> dict[str, str]: | ||
return {"status": "ok"} |
Oops, something went wrong.