Skip to content

Commit 67f3009

Browse files
Merge pull request #4 from bleu/jefferson/cow-523-create-baseline-solver-on-python-template
Add Python Baseline Solver & Multi-Engine Architecture
2 parents 17798d7 + 29b40af commit 67f3009

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+5538
-2308
lines changed

.dockerignore

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

.env.sample

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

.github/workflows/deploy.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ jobs:
1313
packages: write
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1717

18-
- uses: docker/login-action@v1
18+
- uses: docker/login-action@v3
1919
with:
2020
registry: ghcr.io
2121
username: ${{ github.actor }}
2222
password: ${{ secrets.GITHUB_TOKEN }}
2323

2424
- id: meta
25-
uses: docker/metadata-action@v3
25+
uses: docker/metadata-action@v5
2626
with:
2727
images: ghcr.io/${{ github.repository }}
2828
labels: |
2929
org.opencontainers.image.licenses=MIT OR Apache-2.0
30-
- uses: docker/build-push-action@v2
30+
- uses: docker/build-push-action@v5
3131
with:
3232
context: .
3333
file: Dockerfile

.github/workflows/pull-request.yaml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,35 @@ name: pull request
22
on:
33
pull_request:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
jobs:
77
python:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
11-
- name: Setup Python 3.10
12-
uses: actions/setup-python@v2
10+
- uses: actions/checkout@v4
11+
- name: Setup Python 3.11
12+
id: setup-python
13+
uses: actions/setup-python@v4
1314
with:
14-
python-version: '3.10'
15-
- name: Install Requirements
16-
run:
17-
pip install -r requirements.txt
15+
python-version: "3.11"
16+
- name: Install Poetry
17+
uses: snok/install-poetry@v1
18+
with:
19+
version: latest
20+
virtualenvs-create: true
21+
virtualenvs-in-project: true
22+
- name: Cache dependencies
23+
uses: actions/cache@v3
24+
with:
25+
path: .venv
26+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
27+
- name: Install dependencies
28+
run: poetry install --no-interaction
1829
- name: Lint
19-
run:
20-
pylint src/
30+
run: poetry run pylint src/
2131
- name: Format
22-
run:
23-
black --check ./
32+
run: poetry run black --check ./
2433
- name: Type Check
25-
run:
26-
mypy src --strict
34+
run: poetry run mypy src --strict
2735
- name: Unit Tests
28-
run:
29-
python -m pytest tests/unit
36+
run: poetry run python -m pytest src/tests/ -v

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
poetry.lock
2+
.venv/
3+
14
*.pyc
25
*/__pycache__
36
venv/

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python 3.11.9
2+
poetry 2.2.1

Dockerfile

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,52 @@
1-
FROM python:3.10-alpine
1+
# Multi-stage build for Poetry-based Python application
2+
FROM python:3.11-slim as builder
23

3-
RUN apk add --update gcc libc-dev linux-headers
4+
# Install Poetry
5+
RUN pip install poetry==1.8.4
46

7+
# Set Poetry configuration
8+
ENV POETRY_NO_INTERACTION=1 \
9+
POETRY_VENV_IN_PROJECT=1 \
10+
POETRY_CACHE_DIR=/tmp/poetry_cache
11+
12+
# Set work directory
513
WORKDIR /app
614

7-
# First copy over the requirements.txt and install dependencies, this makes
8-
# building subsequent images easier.
9-
COPY requirements.txt .
10-
RUN pip install -r requirements.txt
15+
# Copy Poetry files
16+
COPY pyproject.toml poetry.lock ./
17+
18+
# Install dependencies
19+
RUN poetry install --only=main --no-root && rm -rf $POETRY_CACHE_DIR
20+
21+
# Production stage
22+
FROM python:3.11-slim
23+
24+
# Create non-root user
25+
RUN groupadd -r appuser && useradd -r -g appuser appuser
26+
27+
# Set work directory
28+
WORKDIR /app
29+
30+
# Copy virtual environment from builder
31+
COPY --from=builder /app/.venv /app/.venv
32+
33+
# Copy application code
34+
COPY src/ ./src/
35+
COPY data/ ./data/
36+
37+
# Make sure we use the virtual environment
38+
ENV PATH="/app/.venv/bin:$PATH"
39+
40+
# Change ownership to non-root user
41+
RUN chown -R appuser:appuser /app
42+
USER appuser
43+
44+
# Expose port
45+
EXPOSE 8080
1146

12-
# Copy full source (see .dockerignore)
13-
COPY . .
47+
# Health check
48+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
49+
CMD curl -f http://localhost:8080/healthz || exit 1
1450

15-
CMD [ "python3", "-m" , "src._server"]
51+
# Run the application
52+
CMD ["python", "-m", "src.infra.cli", "run", "--host", "0.0.0.0", "--port", "8080"]

Makefile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# CoW Protocol Solver Template - Makefile
2+
# Poetry-based commands for development and testing
3+
4+
.PHONY: help run format test clean install
5+
6+
# Default target
7+
help:
8+
@echo "CoW Protocol Solver Template - Available Commands:"
9+
@echo ""
10+
@echo " make run - Start the solver server"
11+
@echo " make format - Format code with black"
12+
@echo " make test - Run all tests"
13+
@echo " make install - Install dependencies with Poetry"
14+
@echo " make clean - Clean up temporary files"
15+
@echo " make help - Show this help message"
16+
@echo ""
17+
@echo "Examples:"
18+
@echo " make run # Start server on http://localhost:8080"
19+
@echo " make format # Format all Python code"
20+
@echo " make test # Run test suite"
21+
22+
# Start the solver server
23+
run:
24+
@echo "🚀 Starting CoW Protocol Solver..."
25+
@echo "Server will be available at: http://localhost:8080"
26+
@echo "Press Ctrl+C to stop"
27+
@echo ""
28+
poetry run python -m src.infra.cli run
29+
30+
# Format code with black
31+
format:
32+
@echo "🎨 Formatting code with black..."
33+
poetry run black src/ --line-length 88
34+
@echo "✅ Code formatting complete!"
35+
36+
# Run tests
37+
test:
38+
@echo "🧪 Running test suite..."
39+
poetry run pytest src/tests/ -v
40+
@echo "✅ Tests complete!"
41+
42+
# Install dependencies
43+
install:
44+
@echo "📦 Installing dependencies with Poetry..."
45+
poetry install
46+
@echo "✅ Installation complete!"
47+
@echo "Dependencies are managed by Poetry"
48+
49+
# Clean up temporary files
50+
clean:
51+
@echo "🧹 Cleaning up temporary files..."
52+
find . -type f -name "*.pyc" -delete
53+
find . -type d -name "__pycache__" -delete
54+
find . -type d -name "*.egg-info" -exec rm -rf {} +
55+
rm -rf .pytest_cache/
56+
rm -rf build/
57+
rm -rf dist/
58+
@echo "✅ Cleanup complete!"
59+
60+
# Poetry-specific commands
61+
poetry-install:
62+
@echo "📦 Installing dependencies with Poetry..."
63+
poetry install
64+
65+
poetry-update:
66+
@echo "🔄 Updating dependencies..."
67+
poetry update
68+
69+
poetry-check:
70+
@echo "🔍 Checking dependencies..."
71+
poetry check
72+
73+
poetry-export:
74+
@echo "📤 Exporting requirements.txt for compatibility..."
75+
poetry export -f requirements.txt --output requirements.txt --without-hashes

0 commit comments

Comments
 (0)