Skip to content

Commit

Permalink
Merge branch 'main' into insert_readme_first
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclotruc authored Dec 25, 2024
2 parents 5cfe85f + fe02f66 commit 8d71753
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 5 deletions.
41 changes: 41 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Git
.git
.gitignore

# Python
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.log

# Virtual environment
venv
.env
.venv
ENV

# IDE
.idea
.vscode
*.swp
*.swo

# Project specific
docs/
tests/
*.md
LICENSE
pytest.ini
setup.py
33 changes: 33 additions & 0 deletions .github/workflows/unitest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Unit Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-asyncio
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e .
- name: Run tests
run: |
pytest
33 changes: 28 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
FROM python:3.12
# Build stage
FROM python:3.12-slim AS builder

WORKDIR /build

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install build dependencies and Python packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc python3-dev \
&& pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir --timeout 1000 -r requirements.txt \
&& rm -rf /var/lib/apt/lists/*

# Runtime stage
FROM python:3.12-slim

# Set Python environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

# Install git
RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Create a non-root user
RUN useradd -m -u 1000 appuser

COPY --from=builder /usr/local/lib/python3.12/site-packages/ /usr/local/lib/python3.12/site-packages/
COPY src/ ./
COPY requirements.txt ./

RUN pip install -r requirements.txt

# Change ownership of the application files
RUN chown -R appuser:appuser /app
Expand All @@ -18,4 +41,4 @@ USER appuser

EXPOSE 8000

CMD ["uvicorn", "main:app", "--reload", "--host", "0.0.0.0"]
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

0 comments on commit 8d71753

Please sign in to comment.