Skip to content

Commit 5be965b

Browse files
committed
build: add docker
1 parent 0ddc806 commit 5be965b

8 files changed

Lines changed: 395 additions & 229 deletions

File tree

.claude/agents/devops-hardened-engineer.md

Lines changed: 202 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main, develop, feature/*]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
unit-test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 30
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Run unit tests
19+
run: make test-unit
20+
21+
integration-test:
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 30
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Run integration tests
30+
run: make test-integration

.github/workflows/unit-tests.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

CLAUDE.md

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,10 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5-
## Project Structure Overview
5+
## About the Project
66

7-
The application is organized in a modular monolith with clear separation:
8-
9-
- `app/main.py`: Entry point with FastAPI app creation
10-
- `app/api/router.py`: REST router endpoints
11-
- `app/core`: Core utilities
12-
- `app.db.session`: Database session management
13-
- `app.modules.orders`: Complete order module with models, schemas, repository, service, routes
14-
- `alembic`: Database migration tool
15-
- `tests/unit`: Unit tests (SQLite in-memory)
16-
- `tests/integration`: Integration tests (PostgreSQL)
17-
18-
## Key Development Commands
19-
20-
**Setup and Run**
21-
```bash
22-
# Create virtual environment
23-
python -m venv .venv
24-
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
25-
26-
# Install dependencies
27-
pip install --upgrade pip
28-
pip install -e '.[dev]'
29-
30-
# Run fresh database
31-
docker stop postgres-dev || true
32-
docker rm postgres-dev || true
33-
docker run -d \
34-
--name postgres-dev \
35-
-e POSTGRES_USER=postgres \
36-
-e POSTGRES_PASSWORD=postgres \
37-
-e POSTGRES_DB=app \
38-
-p 5432:5432 \
39-
postgres:15
40-
41-
# Run API in background
42-
uvicorn app.main:app --reload &
43-
```
44-
45-
**Testing**
46-
```bash
47-
pytest # Uses in-memory SQLite, no database setup needed
48-
```
49-
50-
**Database Migrations**
51-
```bash
52-
python -m alembic revision --autogenerate -m "init"
53-
python -m alembic upgrade head
54-
```
55-
56-
## Architecture Notes
57-
58-
- The project uses a feature-based modular structure
59-
- `modules/orders` contains end-to-end functionality
60-
- `repository.py` → database access layer
61-
- `service.py` → business logic
62-
- `routes.py` → API layer
63-
64-
This structure supports future evolution into microservices if needed.
7+
Read the `README.md` file for information about the project, its architecture,
8+
how to run it and how to test it.
659

6610
## Current State
6711

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
gcc \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Copy requirements and install Python dependencies
11+
COPY pyproject.toml .
12+
RUN pip install --upgrade pip && pip install -e '.[dev]'
13+
14+
# Copy application code
15+
COPY . .
16+
17+
# Expose port
18+
EXPOSE 8000
19+
20+
# Run the application
21+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.PHONY: help run run-dev test-unit test-integration clean stop
2+
3+
help:
4+
@echo "Available commands:"
5+
@echo " build - Build the docker container"
6+
@echo " run - Run the application (development with auto-reload, debug mode)"
7+
@echo " test-unit - Run unit tests"
8+
@echo " test-integration - Run integration tests with fresh database"
9+
@echo " stop - Stop the application"
10+
@echo " clean - Clean up Docker containers and volumes"
11+
12+
build:
13+
docker build -t python-fastapi-example-oms:dev .
14+
15+
run:
16+
$(MAKE) build
17+
docker compose up -d
18+
@echo "Waiting for database to be ready..."
19+
until nc -zv localhost 5432; do sleep 1; done
20+
@echo "Running migrations..."
21+
docker compose run --rm app python -m alembic upgrade head
22+
@echo "Application running at http://localhost:8000"
23+
@echo "Swagger UI is available at http://localhost:8000/docs"
24+
25+
stop:
26+
@echo "Stopping the application..."
27+
docker compose stop
28+
29+
test-unit:
30+
$(MAKE) build
31+
@echo "Running unit tests..."
32+
docker compose run --rm app python -m pytest tests/unit/ -v
33+
34+
test-integration:
35+
$(MAKE) clean
36+
$(MAKE) run
37+
@echo "Running integration tests..."
38+
docker compose run --rm app python -m pytest tests/integration/ -v
39+
$(MAKE) clean
40+
41+
clean:
42+
$(MAKE) stop
43+
@echo "Cleaning all data..."
44+
docker compose down -v

0 commit comments

Comments
 (0)