diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..76bfd39 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +.github +venv +__pycache__ +.pytest_cache +tests +htmlcov +.coverage +.env +docs +*.pyc \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e69de29..12029b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: TaskTracker CI + +on: + push: + branches: + - main + - develop + - feature/** + pull_request: + branches: + - main + - develop + +jobs: + test: + + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:16 + + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: tasktracker + + ports: + - 5432:5432 + + options: >- + --health-cmd="pg_isready -U postgres" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + + env: + DATABASE_URL: postgresql://postgres:postgres@localhost:5432/tasktracker + APP_PORT: 8000 + LOG_LEVEL: INFO + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run Tests + run: | + pytest -v + + - name: Generate Coverage Report + run: | + pytest --cov=app --cov-report=term-missing + + - name: Build Docker Image + run: | + docker build -t tasktracker:latest . \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e69de29..a6bbfa5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.12.10-slim-bookworm AS builder + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir --prefix=/install -r requirements.txt + +FROM python:3.12.10-slim-bookworm + +RUN useradd -m app + +WORKDIR /app + +COPY --from=builder /install /usr/local +COPY app ./app + +USER app + +EXPOSE 8000 + +CMD ["uvicorn","app.main:app","--host","0.0.0.0","--port","8000"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e69de29..e96c888 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: "3.9" + +services: + + postgres: + image: postgres:16 + container_name: tasktracker-postgres + restart: always + environment: + POSTGRES_DB: tasktracker + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - "5432:5432" + + api: + build: . + container_name: tasktracker-api + depends_on: + - postgres + environment: + DATABASE_URL: postgresql://postgres:postgres@postgres:5432/tasktracker + APP_PORT: 8000 + LOG_LEVEL: INFO + ports: + - "8000:8000" \ No newline at end of file diff --git a/docs/pipeline.md b/docs/pipeline.md new file mode 100644 index 0000000..dae6608 --- /dev/null +++ b/docs/pipeline.md @@ -0,0 +1,24 @@ +# CI/CD Pipeline Documentation + +## Overview + +The TaskTracker project uses GitHub Actions for Continuous Integration. + +Pipeline executes automatically on: + +- Push to feature branches +- Push to develop +- Push to main +- Pull Requests + +--- + +## Pipeline Stages + +### 1. Checkout + +Downloads repository source code. + +```yaml +uses: actions/checkout@v4 +``` \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..ecb310f --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,5 @@ +-r requirements.txt + +pytest +pytest-cov +httpx \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index bd51310..c72d4a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,12 @@ -fastapi -uvicorn -sqlalchemy +fastapi==0.116.1 +uvicorn==0.35.0 +sqlalchemy==2.0.41 psycopg2-binary pydantic pydantic-settings python-dotenv email-validator -pytest -pytest-cov alembic +pytest-cov pytest httpx \ No newline at end of file