From 3ece0079884804ea1ca0a5803ccee3450a37fd62 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:15:27 -0400 Subject: [PATCH 1/9] feat(ci) Add github action with github service container --- .github/workflows/unittest.yml | 60 ++++++++++++++++++++++++++++++++++ docker-compose.yml.example | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/unittest.yml diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..1d6e409 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,60 @@ +name: FastAPI Tests with PostgreSQL and uv + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + services: + postgres: + image: pgvector/pgvector:pg15 + env: + POSTGRES_DB: test + POSTGRES_USER: testuser + POSTGRES_PASSWORD: testpwd + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v2 + with: + enable-cache: true + cache-dependency-glob: "uv.lock" + + - name: "Set up Python" + uses: actions/setup-python@v5 + with: + python-version-file: "pyproject.toml" + + - name : Install the project + run: uv sync --all-extras --dev + + - name: Run Tests + run: uv run pytest + env: + CONNECTION_URI: postgresql+psycopg://testuser:testpwd@localhost:5432/test + USE_AUTH_SERVICE: false + SENTRY_ENABLED: false + OPENTELEMETRY_ENABLED: false + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }} + AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} + AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }} + AZURE_OPENAI_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_DEPLOYMENT }} + AZURE_OPENAI_EMBED_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_EMBED_DEPLOYMENT }} + + + diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 67b36a5..452c969 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -26,7 +26,7 @@ services: env_file: - .env database: - image: ankane/pgvector + image: pgvector/pgvector:pg15 restart: always ports: - 5432:5432 From 820fae0a42a061ce40fd2e95b0f87fe754333821 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:19:00 -0400 Subject: [PATCH 2/9] chore(ci) Change hostname for service container --- .github/workflows/unittest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 1d6e409..9d18c96 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -45,7 +45,7 @@ jobs: - name: Run Tests run: uv run pytest env: - CONNECTION_URI: postgresql+psycopg://testuser:testpwd@localhost:5432/test + CONNECTION_URI: postgresql+psycopg://testuser:testpwd@postgres:5432/test USE_AUTH_SERVICE: false SENTRY_ENABLED: false OPENTELEMETRY_ENABLED: false From 1c465f58121fd76b36faae5028b165d872843a96 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:26:05 -0400 Subject: [PATCH 3/9] chore(ci) Add Trust Flag --- .github/workflows/unittest.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 9d18c96..2688dab 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -11,12 +11,13 @@ jobs: runs-on: ubuntu-latest services: - postgres: + database: image: pgvector/pgvector:pg15 env: - POSTGRES_DB: test + POSTGRES_DB: testdb POSTGRES_USER: testuser POSTGRES_PASSWORD: testpwd + POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 options: >- @@ -45,7 +46,7 @@ jobs: - name: Run Tests run: uv run pytest env: - CONNECTION_URI: postgresql+psycopg://testuser:testpwd@postgres:5432/test + CONNECTION_URI: postgresql+psycopg://testuser:testpwd@database:5432/testdb USE_AUTH_SERVICE: false SENTRY_ENABLED: false OPENTELEMETRY_ENABLED: false From 1a4d1dcaaab03f7fa1b08a6b5f13b37fe51a37f9 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:30:45 -0400 Subject: [PATCH 4/9] chore(ci) Use Defaults --- .github/workflows/unittest.yml | 8 ++++---- tests/conftest.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 2688dab..382f8df 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -14,9 +14,9 @@ jobs: database: image: pgvector/pgvector:pg15 env: - POSTGRES_DB: testdb - POSTGRES_USER: testuser - POSTGRES_PASSWORD: testpwd + POSTGRES_DB: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 @@ -46,7 +46,7 @@ jobs: - name: Run Tests run: uv run pytest env: - CONNECTION_URI: postgresql+psycopg://testuser:testpwd@database:5432/testdb + CONNECTION_URI: postgresql+psycopg://postgres:postgres@database:5432/postgres USE_AUTH_SERVICE: false SENTRY_ENABLED: false OPENTELEMETRY_ENABLED: false diff --git a/tests/conftest.py b/tests/conftest.py index 4288afe..2dcaad3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,7 +27,7 @@ # Test database URL # TODO use environment variable CONNECTION_URI = make_url(os.getenv("CONNECTION_URI")) -TEST_DB_URL = CONNECTION_URI.set(database="test") +TEST_DB_URL = CONNECTION_URI.set(database="postgres") DEFAULT_DB_URL = str(CONNECTION_URI.set(database="postgres")) From 660a66b08fd004bb7f076cacc14fb2f231d74429 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:34:47 -0400 Subject: [PATCH 5/9] readability --- .github/workflows/unittest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 382f8df..9d0b29b 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -44,7 +44,7 @@ jobs: run: uv sync --all-extras --dev - name: Run Tests - run: uv run pytest + run: uv run pytest -x env: CONNECTION_URI: postgresql+psycopg://postgres:postgres@database:5432/postgres USE_AUTH_SERVICE: false From ac626c2b46610d73ffe538b39edb75c4d2664256 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:40:42 -0400 Subject: [PATCH 6/9] Try to use localhost --- .github/workflows/unittest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 9d0b29b..f524439 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -46,7 +46,7 @@ jobs: - name: Run Tests run: uv run pytest -x env: - CONNECTION_URI: postgresql+psycopg://postgres:postgres@database:5432/postgres + CONNECTION_URI: postgresql+psycopg://postgres:postgres@localhost:5432/postgres USE_AUTH_SERVICE: false SENTRY_ENABLED: false OPENTELEMETRY_ENABLED: false From 19b7127018c33bb5fd6c0b19bf4049c0518eb69d Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:45:13 -0400 Subject: [PATCH 7/9] chore(ci) Use non-default database --- .github/workflows/unittest.yml | 9 ++++----- tests/conftest.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index f524439..46ec4aa 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -14,10 +14,9 @@ jobs: database: image: pgvector/pgvector:pg15 env: - POSTGRES_DB: postgres - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: test_db + POSTGRES_USER: testuser + POSTGRES_PASSWORD: testpwd ports: - 5432:5432 options: >- @@ -46,7 +45,7 @@ jobs: - name: Run Tests run: uv run pytest -x env: - CONNECTION_URI: postgresql+psycopg://postgres:postgres@localhost:5432/postgres + CONNECTION_URI: postgresql+psycopg://testuser:testpwd@localhost:5432/test_db USE_AUTH_SERVICE: false SENTRY_ENABLED: false OPENTELEMETRY_ENABLED: false diff --git a/tests/conftest.py b/tests/conftest.py index 2dcaad3..279a670 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,7 +27,7 @@ # Test database URL # TODO use environment variable CONNECTION_URI = make_url(os.getenv("CONNECTION_URI")) -TEST_DB_URL = CONNECTION_URI.set(database="postgres") +TEST_DB_URL = CONNECTION_URI.set(database="test_db") DEFAULT_DB_URL = str(CONNECTION_URI.set(database="postgres")) From d17d2d7ea99738e204e6c5c43ccde1a5e2f693f7 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:26:26 -0400 Subject: [PATCH 8/9] Try with default credentials but non-standard db --- .github/workflows/unittest.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 46ec4aa..2a07829 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -15,8 +15,8 @@ jobs: image: pgvector/pgvector:pg15 env: POSTGRES_DB: test_db - POSTGRES_USER: testuser - POSTGRES_PASSWORD: testpwd + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres ports: - 5432:5432 options: >- @@ -45,7 +45,7 @@ jobs: - name: Run Tests run: uv run pytest -x env: - CONNECTION_URI: postgresql+psycopg://testuser:testpwd@localhost:5432/test_db + CONNECTION_URI: postgresql+psycopg://postgres:postgres@localhost:5432/test_db USE_AUTH_SERVICE: false SENTRY_ENABLED: false OPENTELEMETRY_ENABLED: false From c6de3e252a1f0b37dd191f9f567f9dd55d23df99 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:29:15 -0400 Subject: [PATCH 9/9] Try to ignore pwd --- .github/workflows/unittest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 2a07829..3586002 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -17,6 +17,7 @@ jobs: POSTGRES_DB: test_db POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 options: >-