Skip to content

Commit 29bcda4

Browse files
sync: update from python-copier-template
1 parent ccd0407 commit 29bcda4

6 files changed

Lines changed: 105 additions & 24 deletions

File tree

.github/workflows/docker.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: docker
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
docker:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v6
19+
20+
# Reuses the Makefile targets so the docker commands live in one place
21+
# and CI validates the same entry points developers use.
22+
- name: Build image
23+
run: make build
24+
25+
- name: Run container
26+
run: make run
27+
28+
# Catches images that build but cannot start (missing runtime deps,
29+
# broken CMD...). Port 7000 matches the Makefile run target.
30+
- name: Smoke test (API responds on /health)
31+
run: |
32+
timeout 30 bash -c 'until curl -sf http://localhost:7000/health > /dev/null; do sleep 1; done'
33+
curl -sf http://localhost:7000/health
34+
35+
- name: Container logs
36+
if: always()
37+
run: make logs || true

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# First, build the application in the `/app` directory.
2-
FROM ghcr.io/astral-sh/uv:0.10.12-python3.14-bookworm-slim AS builder
2+
FROM ghcr.io/astral-sh/uv:0.10.12-python3.14-trixie-slim AS builder
33
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
44

55
# Disable Python downloads, because we want to use the system interpreter
@@ -22,9 +22,9 @@ RUN --mount=type=cache,target=/root/.cache/uv \
2222

2323

2424
# Then, use a final image without uv
25-
FROM python:3.14-slim-bookworm
25+
FROM python:3.14-slim-trixie
2626
# It is important to use the image that matches the builder, as the path to the
27-
# Python executable must be the same, e.g., using `python:3.11-slim-bookworm`
27+
# Python executable must be the same, e.g., using `python:3.11-slim-trixie`
2828
# will fail.
2929

3030
# Copy the application from the builder

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.ONESHELL:
2-
.PHONY: install hooks hooks-update ruff ty test test-api docker build run debug attach push
2+
.PHONY: install hooks hooks-update ruff ty test test-api docker build run logs debug attach push
33

44
SHELL=/bin/bash
55
DOCKER_IMG_NAME=ghcr.io/komorebi-ai/python-template
@@ -50,6 +50,9 @@ run:
5050
[ "$$(docker ps -a | grep $(DOCKER_CONTAINER))" ] && docker stop $(DOCKER_CONTAINER) && docker rm $(DOCKER_CONTAINER)
5151
docker run -d --restart=unless-stopped --name $(DOCKER_CONTAINER) -p 7000:80 $(DOCKER_IMG_NAME)
5252

53+
logs:
54+
docker logs $(DOCKER_CONTAINER)
55+
5356
debug:
5457
docker run -it $(DOCKER_IMG_NAME) /bin/bash
5558

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dependencies = [
1616
"pydantic",
1717
"uvicorn",
1818
"colorlog>=6.9.0",
19+
# uvicorn needs pyyaml to load the YAML log config (log_conf.yaml)
20+
"pyyaml",
1921
"typer",
2022
]
2123

@@ -112,8 +114,9 @@ addopts = ["-ra", "--strict-config", "--strict-markers"]
112114
filterwarnings = ["error", "ignore::DeprecationWarning"]
113115

114116
[tool.deptry]
115-
# colorlog is used in log_conf.yaml (not scanned by deptry)
116-
per_rule_ignores = {"DEP002" = ["colorlog"]}
117+
# colorlog is used in log_conf.yaml (not scanned by deptry); pyyaml is used
118+
# by uvicorn to load log_conf.yaml
119+
per_rule_ignores = {"DEP002" = ["colorlog", "pyyaml"]}
117120

118121
[tool.ty.terminal]
119122
error-on-warning = true

python_template/api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ def read_root() -> dict[str, str]:
4040
return {"python_template-api": f"version {__version__}"}
4141

4242

43+
@app.get("/health")
44+
def health() -> dict[str, str]:
45+
"""Health check for container orchestration and monitoring.
46+
47+
Stable endpoint: keep it when replacing the example endpoints below,
48+
since Docker healthchecks and CI smoke tests rely on it.
49+
"""
50+
return {"status": "ok"}
51+
52+
4353
@app.post("/predict")
4454
def predict(request: Request) -> Response:
4555
"""Mock prediction endpoint."""

0 commit comments

Comments
 (0)