Skip to content

Commit 8fb03ae

Browse files
committed
feat: add Docker support with docker-compose and Prometheus integration
1 parent 40139d5 commit 8fb03ae

6 files changed

Lines changed: 119 additions & 23 deletions

File tree

.dockerignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# ===============================
2+
# Python bytecode / caches
3+
# ===============================
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
8+
# ===============================
9+
# Virtual environments
10+
# ===============================
11+
.venv/
12+
venv/
13+
ENV/
14+
env/
15+
16+
# ===============================
17+
# Test / coverage artifacts
18+
# ===============================
19+
.pytest_cache/
20+
.coverage
21+
.coverage.*
22+
htmlcov/
23+
.tox/
24+
25+
# ===============================
26+
# Build / packaging outputs
27+
# ===============================
28+
build/
29+
dist/
30+
*.egg-info/
31+
32+
# ===============================
33+
# Editor / OS junk
34+
# ===============================
35+
.vscode/
36+
.idea/
37+
.DS_Store
38+
Thumbs.db
39+
40+
# ===============================
41+
# Git / CI
42+
# ===============================
43+
.git/
44+
.gitignore
45+
.github/
46+
47+
# ===============================
48+
# Logs
49+
# ===============================
50+
*.log
51+
52+
# ===============================
53+
# Local tooling caches
54+
# ===============================
55+
.ruff_cache/
56+
.mypy_cache/
57+
.isort_cache/
58+
59+
# ===============================
60+
# Node (just in case)
61+
# ===============================
62+
node_modules/
63+
64+
# ===============================
65+
# Docker files you DON'T need inside image
66+
# ===============================
67+
docker-compose.yml
68+
69+
# ===============================
70+
# IMPORTANT: DO NOT IGNORE THESE
71+
# ===============================
72+
# pyproject.toml
73+
# uv.lock
74+
# src/

Dockerfile

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder
22
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
3-
43
ENV UV_NO_DEV=1
5-
64
ENV UV_PYTHON_DOWNLOADS=0
7-
85
WORKDIR /app
96
RUN --mount=type=cache,target=/root/.cache/uv \
107
--mount=type=bind,source=uv.lock,target=uv.lock \
@@ -14,26 +11,15 @@ COPY . /app
1411
RUN --mount=type=cache,target=/root/.cache/uv \
1512
uv sync --locked
1613

17-
FROM python:3.13-slim-bookworm
18-
14+
FROM python:3.13-slim-bookworm AS runtime
1915
RUN apt-get update \
2016
&& apt-get upgrade -y \
2117
&& apt-get clean \
2218
&& rm -rf /var/lib/apt/lists/*
23-
2419
RUN groupadd --system --gid 999 nonroot \
25-
&& useradd --system --gid 999 --uid 999 --create-home nonroot
26-
27-
COPY --from=builder --chown=nonroot:nonroot /app /app
28-
20+
&& useradd --system --gid 999 --uid 999 --create-home nonroot
21+
COPY --from=builder --chown=nonroot:nonroot /app/ /app
2922
ENV PATH="/app/.venv/bin:$PATH"
30-
3123
USER nonroot
32-
33-
WORKDIR /app
34-
35-
USER nonroot
36-
37-
WORKDIR /app
38-
39-
CMD ["python", "-m","sample_python_app.main"]
24+
WORKDIR /app/src
25+
CMD ["python", "-m", "sample_python_app.main"]

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
services:
2+
python-app:
3+
build: .
4+
container_name: python-app
5+
ports:
6+
- "8000:8000"
7+
environment:
8+
- PYTHONUNBUFFERED=1
9+
10+
prometheus:
11+
image: prom/prometheus:latest
12+
container_name: prometheus
13+
ports:
14+
- "9090:9090"
15+
volumes:
16+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
17+
18+
grafana:
19+
image: grafana/grafana:latest
20+
container_name: grafana
21+
ports:
22+
- "3000:3000"
23+
depends_on:
24+
- prometheus
25+
environment:
26+
- GF_SECURITY_ADMIN_PASSWORD
27+
volumes:
28+
- grafana-data:/var/lib/grafana
29+
30+
volumes:
31+
grafana-data:

prometheus.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
global:
2+
scrape_interval: 15s
3+
4+
scrape_configs:
5+
- job_name: "python-app"
6+
static_configs:
7+
- targets: ["python-app:8000"]

src/sample_python_app/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
"""Sample Python app package initialization."""
2-
3-
from sample_python_app.main import run_app
4-
5-
__all__ = ["run_app"]

src/sample_python_app/core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pydantic_extra_types.coordinate import Coordinate, Latitude, Longitude
66
from pydantic_settings import BaseSettings, SettingsConfigDict
7+
from pydantic import SecretStr
78

89

910
class WeatherSettings(BaseSettings):
@@ -26,6 +27,7 @@ class Settings(BaseSettings):
2627
DATE_FORMAT: str = "%Y-%m-%d %I:%M:%S %p %Z"
2728
TIMEZONE: str = "America/Chicago"
2829
PROMETHEUS_METRICS_PORT: int = 8000
30+
GF_SECURITY_ADMIN_PASSWORD: SecretStr = SecretStr("admin")
2931

3032
model_config = SettingsConfigDict(
3133
env_file=".env",

0 commit comments

Comments
 (0)