Skip to content

Commit 1741045

Browse files
committed
Halfway
1 parent 265dd6f commit 1741045

File tree

17 files changed

+373
-9
lines changed

17 files changed

+373
-9
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
python-version: ${{ env.PYTHON_VERSION }}
6161

6262
- name: Establish a cache for dependencies
63-
uses: actions/cache@v2
63+
uses: actions/cache@v4
6464
with:
6565
path: |
6666
~/.local

.idea/runConfigurations/pytest_in_tests.xml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Convenience Makefile
3+
# Useful reference: https://makefiletutorial.com
4+
5+
GIT_SHA := $(shell git rev-parse --short HEAD)
6+
VERSION ?= 0.0.0-dev0.${GIT_SHA}
7+
PYTHON_VERSION := $(shell echo "${VERSION}" | sed -e 's/-dev0\./-dev0+/')
8+
9+
PYTHON_SOURCES := $(shell find src/mrmat_python_api_fastapi -name '*.py')
10+
PYTHON_TARGET := dist/mrmat_python_api_fastapi-${PYTHON_VERSION}-py3-none-any.whl
11+
CONTAINER_SOURCES := $(shell find var/container)
12+
HELM_SOURCES := $(shell find var/helm)
13+
HELM_TARGET := dist/mrmat-python-api-fastapi-$(VERSION).tgz
14+
15+
all: python container helm
16+
python: $(PYTHON_TARGET)
17+
helm: $(HELM_TARGET)
18+
19+
$(PYTHON_TARGET): $(PYTHON_SOURCES)
20+
MRMAT_VERSION="${PYTHON_VERSION}" python -mbuild -n --wheel
21+
22+
$(HELM_TARGET): $(HELM_SOURCES) container
23+
helm package \
24+
--app-version "$(VERSION)" \
25+
--version $(VERSION) \
26+
--destination dist/ \
27+
var/helm
28+
29+
container: $(PYTHON_TARGET) $(CONTAINER_SOURCES)
30+
docker build \
31+
-f var/container/Dockerfile \
32+
-t localhost:5001/mrmat-python-api-fastapi:$(VERSION) \
33+
--build-arg MRMAT_VERSION=$(VERSION) \
34+
.
35+
docker push localhost:5001/mrmat-python-api-fastapi:$(VERSION)
36+
37+
helm-install: $(HELM_TARGET)
38+
helm upgrade \
39+
mrmat-python-api-fastapi \
40+
${HELM_TARGET} \
41+
--install \
42+
--create-namespace \
43+
--namespace mrmat-python-api-fastapi
44+
45+
clean:
46+
rm -rf build dist

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespaces = true
4040
"*" = [".mo", "*.yml", "*.yaml", "*.md", "inventory", "*.j2", "*.html", "*.ico", "*.css", "*.js", "*.svg", "*.woff", "*.eot", "*.ttf"]
4141

4242
[project.scripts]
43-
mrmat_python_api_fastapi = "mrmat_python_api_fastapi.cli:run"
43+
mrmat-python-api-fastapi = "mrmat_python_api_fastapi.app:run"
4444

4545
[tool.mypy]
4646
plugins = [ 'pydantic.mypy' ]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
fastapi==0.115.6 # MIT
55
sqlalchemy[asyncio] # MIT
66
uvicorn==0.34.0 # BSD 3-Clause
7+
pydantic==2.10.4 # MIT

src/mrmat_python_api_fastapi/apis/healthz/api.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,36 @@
2525
"""
2626

2727
from fastapi import APIRouter
28+
from pydantic import BaseModel
2829

2930
router = APIRouter()
3031

32+
class HealthzSchema(BaseModel):
33+
status: str
34+
35+
class LivenessSchema(BaseModel):
36+
status: str
37+
38+
class ReadinessSchema(BaseModel):
39+
status: str
3140

3241
@router.get('/',
33-
name='Assess application health',
34-
description='Get an indication of application health')
35-
async def get():
36-
return {'code': 200, 'message': 'OK'}, 200
42+
name='Get application health',
43+
description='Get an indication of application health',
44+
response_model=HealthzSchema)
45+
async def healthz() -> HealthzSchema:
46+
return HealthzSchema(status='OK')
47+
48+
@router.get('/liveness/',
49+
name='Get application liveness',
50+
description='Get an indication of application liveness',
51+
response_model=LivenessSchema)
52+
async def liveness() -> LivenessSchema:
53+
return LivenessSchema(status='OK')
3754

55+
@router.get('/readiness/',
56+
name='Get application readiness',
57+
description='Get an indication of application readiness',
58+
response_model=ReadinessSchema)
59+
async def readiness() -> ReadinessSchema:
60+
return ReadinessSchema(status='OK')

src/mrmat_python_api_fastapi/app.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222

2323
from fastapi import FastAPI
2424

25-
from mrmat_python_api_fastapi import app_config
2625
from mrmat_python_api_fastapi.apis.healthz import api_healthz
2726
from mrmat_python_api_fastapi.apis.greeting import api_greeting_v1, api_greeting_v2, api_greeting_v3
2827
from mrmat_python_api_fastapi.apis.resource import api_resource_v1
2928

3029
app = FastAPI(title='MrMat :: Python :: API :: FastAPI')
31-
app.include_router(api_healthz, prefix='/healthz', tags=['health'])
30+
app.include_router(api_healthz, prefix='/api/healthz', tags=['health'])
3231
app.include_router(api_greeting_v1, prefix='/api/greeting/v1', tags=['greeting'])
3332
app.include_router(api_greeting_v2, prefix='/api/greeting/v2', tags=['greeting'])
3433
app.include_router(api_greeting_v3, prefix='/api/greeting/v3', tags=['greeting'])
@@ -37,4 +36,14 @@
3736

3837
@app.get('/')
3938
def index():
40-
return {'Hello': f'World (Using db {app_config.db_url}'}
39+
return {'Hello': 'World'}
40+
41+
def run() -> int:
42+
"""
43+
This is the main entry point for the application when running via the CLI wrapper
44+
Returns:
45+
- int: The exit code
46+
"""
47+
import uvicorn
48+
uvicorn.run(app, host='0.0.0.0', port=8000)
49+
return 0

var/container/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.12-alpine AS build
2+
ARG MRMAT_VERSION="0.0.0.dev0"
3+
ADD dist/mrmat_python_api_fastapi-*-py3-none-any.whl /
4+
RUN pip install --user /mrmat_python_api_fastapi-*-py3-none-any.whl
5+
6+
FROM python:3.12-alpine
7+
ARG MRMAT_VERSION="0.0.0.dev0"
8+
LABEL VERSION=$MRMAT_VERSION
9+
RUN addgroup -g 1000 app && \
10+
adduser -g 'App User' -u 1000 -G app -D app
11+
COPY --from=build /root/.local /home/app/.local
12+
RUN chown -R 1000:1000 /home/app/.local
13+
14+
USER app:app
15+
EXPOSE 8000
16+
#CMD ["/home/app/.local/bin/uvicorn", "--host", "0.0.0.0", "--port", "8000", "mrmat_python_api_fastapi.app:app"]
17+
CMD ["/home/app/.local/bin/mrmat-python-api-fastapi"]

var/helm/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

var/helm/Chart.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v2
2+
name: mrmat-python-api-fastapi
3+
description: A Helm chart for MrMat Python API FastAPI
4+
type: application
5+
6+
# This is the chart version. This version number should be incremented each time you make changes
7+
# to the chart and its templates, including the app version.
8+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
9+
version: "0.0.0"
10+
11+
# This is the version number of the application being deployed. This version number should be
12+
# incremented each time you make changes to the application. Versions are not expected to
13+
# follow Semantic Versioning. They should reflect the version the application is using.
14+
# It is recommended to use it with quotes.
15+
appVersion: "0.0.0.dev0"

0 commit comments

Comments
 (0)