diff --git a/envSample b/.env.example similarity index 88% rename from envSample rename to .env.example index 764b41b2..fcb50611 100644 --- a/envSample +++ b/.env.example @@ -1,29 +1,39 @@ # Domain + # This would be set to the production domain with an env var on deployment + # used by Traefik to transmit traffic and aqcuire TLS certificates + DOMAIN=localhost + # To test the local Traefik config + # DOMAIN=localhost.tiangolo.com # Used by the backend to generate links in emails to the frontend + FRONTEND_HOST=http://localhost:5173 + # In staging and production, set this env var to the frontend host, e.g. + # FRONTEND_HOST=https://dashboard.example.com # Environment: local, staging, production -ENVIRONMENT=local +ENVIRONMENT=local PROJECT_NAME="AI Platform" STACK_NAME=ai-platform # Backend + BACKEND_CORS_ORIGINS="http://localhost:5173" SECRET_KEY=changethis FIRST_SUPERUSER=admin@example.com FIRST_SUPERUSER_PASSWORD=changethis # Emails + SMTP_HOST= SMTP_USER= SMTP_PASSWORD= @@ -33,14 +43,19 @@ SMTP_SSL=False SMTP_PORT=587 # Postgres + POSTGRES_SERVER=localhost POSTGRES_PORT=5432 -POSTGRES_DB=app +POSTGRES_DB=ai_platform POSTGRES_USER=postgres -POSTGRES_PASSWORD=changethis +POSTGRES_PASSWORD=postgres SENTRY_DSN= # Configure these with your own Docker registry images + DOCKER_IMAGE_BACKEND=backend -DOCKER_IMAGE_FRONTEND=frontend \ No newline at end of file +DOCKER_IMAGE_FRONTEND=frontend + +CI="" +OPENAI_API_KEY="this_is_not_a_secret" diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 51e01133..8b548a42 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,13 +1,13 @@ ## Summary Target issue is #_PLEASE_TYPE_ISSUE_NUMBER_ - Explain the **motivation** for making this change. What existing problem does the pull request solve? +Explain the **motivation** for making this change. What existing problem does the pull request solve? ## Checklist Before submitting a pull request, please ensure that you mark these task. -- [ ] Ran `poetry run uvicorn src.app.main:app --reload` in the repository root and test. +- [ ] Ran `fastapi run --reload app/main.py` or `docker compose up` in the repository root and test. - [ ] If you've fixed a bug or added code that is tested and has test cases. ## Notes diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml new file mode 100644 index 00000000..0d1d2e94 --- /dev/null +++ b/.github/workflows/continuous_integration.yml @@ -0,0 +1,69 @@ +name: AI Platform CI + +on: + push: + branches: [staging] + pull_request: + branches: [staging] + +jobs: + checks: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:16 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: ai_platform + ports: + - 5432:5432 + options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5 + + strategy: + matrix: + python-version: ["3.11.7"] + redis-version: [6] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Making env file + run: cp .env.example .env + + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + version: "0.4.15" + enable-cache: true + + - name: Install dependencies + run: uv sync + working-directory: backend + + - name: Activate virtual environment and run Alembic migrations + run: | + source .venv/bin/activate + alembic upgrade head + working-directory: backend + + - name: Run tests + run: uv run bash scripts/tests-start.sh "Coverage for ${{ github.sha }}" + working-directory: backend + + - name: Upload coverage reports to codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true + + - name: Check coverage percentage + run: | + source .venv/bin/activate + coverage report --fail-under=70 + working-directory: backend diff --git a/README.md b/README.md index 701bb0a3..57cf5af3 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ You can **just fork or clone** this repository and use it as is. Create env file using example file ```bash -cp envSample .env +cp .env.example .env ``` You can then update configs in the `.env` files to customize your configurations. @@ -26,7 +26,8 @@ Before deploying it, make sure you change at least the values for: - `SECRET_KEY` - `FIRST_SUPERUSER_PASSWORD` - `POSTGRES_PASSWORD` -```bash + +````bash ### Generate Secret Keys @@ -36,7 +37,7 @@ You have to change them with a secret key, to generate secret keys you can run t ```bash python -c "import secrets; print(secrets.token_urlsafe(32))" -``` +```` Copy the content and use that as password / secret key. And run that again to generate another secure key. @@ -62,7 +63,6 @@ or by visiting: http://[your-domain]:8000/api/v1/utils/health-check/ in the brow Backend docs: [backend/README.md](./backend/README.md). - ## Deployment Deployment docs: [deployment.md](./deployment.md). diff --git a/backend/scripts/test.sh b/backend/scripts/test.sh index df23f702..8355f8e1 100755 --- a/backend/scripts/test.sh +++ b/backend/scripts/test.sh @@ -1,8 +1,15 @@ -#!/usr/bin/env bash - +#!/bin/bash set -e set -x +# Run tests with coverage tracking coverage run --source=app -m pytest + +# Generate a human-readable coverage report in the terminal coverage report --show-missing + +# Generate an HTML report for local viewing coverage html --title "${@-coverage}" + +# Generate the XML report for Codecov +coverage xml \ No newline at end of file