Skip to content

Commit

Permalink
feat: Add Docker support for disability-max-ratings-api
Browse files Browse the repository at this point in the history
This PR adds Docker support to run the disability-max-ratings-api service in a containerized environment.

- Added `Dockerfile` with Python 3.12.3 and Poetry setup
- Added `docker-compose.yml` for local development
- Added healthcheck to monitor service availability
- Fixed Poetry configuration in `pyproject.toml`
  - Added required `authors` field
  - Removed unsupported `package-mode` field

1. Build and start the container:
```bash
docker compose up --build
```

2. Test the API health/docs:
```bash
curl http://localhost:8130/docs
```

3. Test the API endpoint with a sample request:
```bash
curl -X POST http://localhost:8130/disability-max-ratings/ \
  -H "Content-Type: application/json" \
  -d '{"diagnostic_codes": [6260]}'
```

Expected response:
```json
{
    "ratings": [
        {
            "diagnostic_code": 6260,
            "max_rating": 10
        }
    ]
}
```

4. Monitor container health:
```bash
docker compose ps
```

- Uses Python slim base image to minimize container size
- Installs only production dependencies with `--only main`
- Configures Poetry to run without virtual environments in container
- Exposes port 8130 for API access
- Includes curl for healthcheck functionality
- Mounts local directory for development convenience

- Runs with `no-new-privileges` security option
- Cleans up apt cache to reduce image size
- Uses official Python base image
```
  • Loading branch information
gabezurita committed Dec 19, 2024
1 parent 865a00e commit 0702147
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 106 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.3
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM python:3.12.3-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && \
apt-get install -y curl && \
rm -rf /var/lib/apt/lists/*

# Install poetry
RUN pip install poetry==1.7.1

# Copy poetry files
COPY pyproject.toml poetry.lock ./

# Configure poetry
RUN poetry config virtualenvs.create false && \
poetry config warnings.export false

# Install dependencies
RUN poetry install --only main --no-interaction --no-ansi

# Copy application code
COPY . .

# Expose the port the app runs on
EXPOSE 8130

# Command to run the application
CMD ["poetry", "run", "uvicorn", "src.python_src.api:app", "--host", "0.0.0.0", "--port", "8130"]
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
api:
build: .
container_name: disability-max-ratings-api
ports:
- "8130:8130"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8130/docs"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
restart: unless-stopped
environment:
- ENV=local
volumes:
- .:/app
security_opt:
- no-new-privileges:true
Loading

0 comments on commit 0702147

Please sign in to comment.