Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a6f4cd44c | |||
| 71cf0a4563 | |||
| 9659e63208 |
+6
-23
@@ -15,7 +15,7 @@ permissions:
|
|||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: git.farh.net
|
||||||
IMAGE_NAME: cartsnitch/api
|
IMAGE_NAME: cartsnitch/api
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -51,9 +51,6 @@ jobs:
|
|||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
credentials:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
env:
|
env:
|
||||||
POSTGRES_USER: cartsnitch
|
POSTGRES_USER: cartsnitch
|
||||||
POSTGRES_PASSWORD: cartsnitch_test
|
POSTGRES_PASSWORD: cartsnitch_test
|
||||||
@@ -67,9 +64,6 @@ jobs:
|
|||||||
--health-retries 5
|
--health-retries 5
|
||||||
redis:
|
redis:
|
||||||
image: redis:7-alpine
|
image: redis:7-alpine
|
||||||
credentials:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
ports:
|
ports:
|
||||||
- 6379:6379
|
- 6379:6379
|
||||||
options: >-
|
options: >-
|
||||||
@@ -122,19 +116,8 @@ jobs:
|
|||||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||||
echo "CalVer tag: $VERSION"
|
echo "CalVer tag: $VERSION"
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Gitea Container Registry
|
||||||
uses: docker/login-action@v3
|
run: echo "${{ github.token }}" | docker login git.farh.net -u ${{ github.actor }} --password-stdin
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Log in to GHCR
|
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Extract metadata
|
- name: Extract metadata
|
||||||
id: meta
|
id: meta
|
||||||
@@ -171,7 +154,7 @@ jobs:
|
|||||||
only-fixed: "true"
|
only-fixed: "true"
|
||||||
output-format: sarif
|
output-format: sarif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- name: Push Docker image
|
- name: Push Docker image
|
||||||
if: github.event_name == 'push'
|
if: github.event_name == 'push'
|
||||||
@@ -224,7 +207,7 @@ jobs:
|
|||||||
if: needs.build-and-push.result == 'success'
|
if: needs.build-and-push.result == 'success'
|
||||||
run: |
|
run: |
|
||||||
cd infra/apps/overlays/dev
|
cd infra/apps/overlays/dev
|
||||||
kustomize edit set image ghcr.io/cartsnitch/api:${{ steps.api_tag.outputs.tag }}
|
kustomize edit set image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.api_tag.outputs.tag }}
|
||||||
|
|
||||||
- name: Commit and push to infra
|
- name: Commit and push to infra
|
||||||
run: |
|
run: |
|
||||||
@@ -268,7 +251,7 @@ jobs:
|
|||||||
if: needs.build-and-push.result == 'success'
|
if: needs.build-and-push.result == 'success'
|
||||||
run: |
|
run: |
|
||||||
cd infra/apps/overlays/uat
|
cd infra/apps/overlays/uat
|
||||||
kustomize edit set image ghcr.io/cartsnitch/api:${{ steps.api_tag.outputs.tag }}
|
kustomize edit set image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.api_tag.outputs.tag }}
|
||||||
|
|
||||||
- name: Commit and push to infra
|
- name: Commit and push to infra
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -25,7 +25,14 @@ from cartsnitch_api.routes.user import router as user_router
|
|||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
|
# Lazy import: keep `dispose_engine` out of the top-level imports so a
|
||||||
|
# stale or partially-built database.py never breaks module load on
|
||||||
|
# container start. The function is required for graceful pool cleanup
|
||||||
|
# on shutdown; if the import fails, the cache_client.close() that
|
||||||
|
# follows the yield would mask it. See CAR-1135 for the original
|
||||||
|
# ImportError that motivated this pattern.
|
||||||
from cartsnitch_api.database import dispose_engine
|
from cartsnitch_api.database import dispose_engine
|
||||||
|
|
||||||
await cache_client.initialize()
|
await cache_client.initialize()
|
||||||
yield
|
yield
|
||||||
await cache_client.close()
|
await cache_client.close()
|
||||||
|
|||||||
@@ -3,8 +3,21 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
|
from cartsnitch_api.database import dispose_engine
|
||||||
from cartsnitch_api.main import app
|
from cartsnitch_api.main import app
|
||||||
|
|
||||||
|
|
||||||
|
def test_dispose_engine_importable_from_database():
|
||||||
|
"""Regression for CAR-1135: api main.py used to import dispose_engine
|
||||||
|
at module level. A stale database.py (no dispose_engine) crashed the
|
||||||
|
container at import time with ImportError on line 9. The fix moved
|
||||||
|
the import inside the lifespan function, but `dispose_engine` must
|
||||||
|
still be importable from `cartsnitch_api.database` for the lifespan
|
||||||
|
teardown to actually close pooled connections.
|
||||||
|
"""
|
||||||
|
assert callable(dispose_engine)
|
||||||
|
assert dispose_engine.__name__ == "dispose_engine"
|
||||||
|
|
||||||
EXPECTED_ROUTES = [
|
EXPECTED_ROUTES = [
|
||||||
# Auth (7)
|
# Auth (7)
|
||||||
("post", "/auth/register"),
|
("post", "/auth/register"),
|
||||||
|
|||||||
Reference in New Issue
Block a user