Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41a887a73b |
@@ -175,3 +175,90 @@ jobs:
|
|||||||
git tag "v${{ steps.calver.outputs.version }}"
|
git tag "v${{ steps.calver.outputs.version }}"
|
||||||
git push origin "v${{ steps.calver.outputs.version }}"
|
git push origin "v${{ steps.calver.outputs.version }}"
|
||||||
|
|
||||||
|
deploy-dev:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build-and-push]
|
||||||
|
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main')
|
||||||
|
steps:
|
||||||
|
- name: Checkout infra repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: cartsnitch/infra
|
||||||
|
token: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
ref: main
|
||||||
|
path: infra
|
||||||
|
|
||||||
|
- name: Install kubectl
|
||||||
|
uses: azure/setup-kubectl@v4
|
||||||
|
|
||||||
|
- name: Install kustomize
|
||||||
|
uses: imranismail/setup-kustomize@v2
|
||||||
|
|
||||||
|
- name: Determine image tag
|
||||||
|
id: api_tag
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
||||||
|
echo "tag=${{ needs.build-and-push.outputs.calver_tag }}" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "tag=${{ needs.build-and-push.outputs.sha_tag }}" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Update api image tag
|
||||||
|
if: needs.build-and-push.result == 'success'
|
||||||
|
run: |
|
||||||
|
cd infra/apps/overlays/dev
|
||||||
|
kustomize edit set image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.api_tag.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Commit and push to infra
|
||||||
|
run: |
|
||||||
|
cd infra
|
||||||
|
git config user.name "cartsnitch-ci[bot]"
|
||||||
|
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
|
||||||
|
git add apps/overlays/dev/kustomization.yaml
|
||||||
|
git commit -m "ci(dev): update api image"
|
||||||
|
git pull --rebase origin main
|
||||||
|
git push origin main
|
||||||
|
|
||||||
|
deploy-uat:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build-and-push]
|
||||||
|
if: always() && !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/uat' || github.ref == 'refs/heads/main')
|
||||||
|
steps:
|
||||||
|
- name: Checkout infra repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: cartsnitch/infra
|
||||||
|
token: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
ref: main
|
||||||
|
path: infra
|
||||||
|
|
||||||
|
- name: Install kubectl
|
||||||
|
uses: azure/setup-kubectl@v4
|
||||||
|
|
||||||
|
- name: Install kustomize
|
||||||
|
uses: imranismail/setup-kustomize@v2
|
||||||
|
|
||||||
|
- name: Determine image tag
|
||||||
|
id: api_tag
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
||||||
|
echo "tag=${{ needs.build-and-push.outputs.calver_tag }}" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "tag=${{ needs.build-and-push.outputs.sha_tag }}" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Update api image tag
|
||||||
|
if: needs.build-and-push.result == 'success'
|
||||||
|
run: |
|
||||||
|
cd infra/apps/overlays/uat
|
||||||
|
kustomize edit set image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.api_tag.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Commit and push to infra
|
||||||
|
run: |
|
||||||
|
cd infra
|
||||||
|
git config user.name "cartsnitch-ci[bot]"
|
||||||
|
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
|
||||||
|
git add apps/overlays/uat/kustomization.yaml
|
||||||
|
git commit -m "ci(uat): update api image"
|
||||||
|
git pull --rebase origin main
|
||||||
|
git push origin main
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"mcpServers": {
|
|
||||||
"gitea": {
|
|
||||||
"type": "http",
|
|
||||||
"url": "https://git-mcp.farh.net/mcp",
|
|
||||||
"headers": {
|
|
||||||
"Authorization": "Bearer ${GITEA_TOKEN}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+8
-28
@@ -19,14 +19,6 @@ from cartsnitch_api.database import get_db
|
|||||||
from cartsnitch_api.main import create_app
|
from cartsnitch_api.main import create_app
|
||||||
from cartsnitch_api.models import Base
|
from cartsnitch_api.models import Base
|
||||||
|
|
||||||
|
|
||||||
def _set_timestamp_defaults(mapper, connection, target):
|
|
||||||
"""Populate created_at/updated_at before insert for SQLite compatibility."""
|
|
||||||
now = datetime.now(UTC)
|
|
||||||
for col in [c for c in mapper.columns if c.key in ("created_at", "updated_at")]:
|
|
||||||
if getattr(target, col.key, None) is None:
|
|
||||||
setattr(target, col.key, now)
|
|
||||||
|
|
||||||
TEST_JWT_SECRET = secrets.token_urlsafe(32)
|
TEST_JWT_SECRET = secrets.token_urlsafe(32)
|
||||||
TEST_SERVICE_KEY = secrets.token_urlsafe(32)
|
TEST_SERVICE_KEY = secrets.token_urlsafe(32)
|
||||||
TEST_FERNET_KEY = "7reF42nmTwbdN21PBoubGp7h_FU8qSimstmlaMLoRK8="
|
TEST_FERNET_KEY = "7reF42nmTwbdN21PBoubGp7h_FU8qSimstmlaMLoRK8="
|
||||||
@@ -61,28 +53,22 @@ def disable_rate_limiting():
|
|||||||
def engine():
|
def engine():
|
||||||
"""Sync in-memory SQLite engine for model unit tests.
|
"""Sync in-memory SQLite engine for model unit tests.
|
||||||
|
|
||||||
Strips PostgreSQL-specific server_default expressions and provides
|
Strips ALL PostgreSQL-specific server_default expressions so SQLite can
|
||||||
Python-side defaults for SQLite compatibility.
|
handle all column inserts without missing-function errors.
|
||||||
"""
|
"""
|
||||||
eng = create_engine("sqlite:///:memory:")
|
eng = create_engine("sqlite:///:memory:")
|
||||||
|
|
||||||
for tbl in Base.metadata.tables.values():
|
for table in Base.metadata.tables.values():
|
||||||
for col in tbl.columns.values():
|
for col in table.columns.values():
|
||||||
sd = col.server_default
|
sd = col.server_default
|
||||||
if sd is not None:
|
if sd is not None:
|
||||||
if not hasattr(sd, "expression"):
|
if not hasattr(sd, "expression"):
|
||||||
col.server_default = None
|
col.server_default = None
|
||||||
continue
|
continue
|
||||||
expr_str = str(sd.expression).lower()
|
expr_str = str(sd.expression).lower()
|
||||||
# Strip PostgreSQL-specific defaults
|
if "gen_random_uuid" in expr_str or "gen_random_bytes" in expr_str:
|
||||||
if any(x in expr_str for x in ["gen_random_uuid", "gen_random_bytes", "now()"]):
|
|
||||||
col.server_default = None
|
col.server_default = None
|
||||||
|
|
||||||
# Register event listener to populate timestamps on insert
|
|
||||||
for cls in Base.registry._class_registry.values():
|
|
||||||
if hasattr(cls, "__mapper__"):
|
|
||||||
event.listen(cls, "before_insert", _set_timestamp_defaults)
|
|
||||||
|
|
||||||
Base.metadata.create_all(eng)
|
Base.metadata.create_all(eng)
|
||||||
yield eng
|
yield eng
|
||||||
eng.dispose()
|
eng.dispose()
|
||||||
@@ -106,23 +92,17 @@ async def db_engine():
|
|||||||
cursor.execute("PRAGMA foreign_keys=ON")
|
cursor.execute("PRAGMA foreign_keys=ON")
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
for tbl in Base.metadata.tables.values():
|
for table in Base.metadata.tables.values():
|
||||||
for col in tbl.columns.values():
|
for col in table.columns.values():
|
||||||
sd = col.server_default
|
sd = col.server_default
|
||||||
if sd is not None:
|
if sd is not None:
|
||||||
if not hasattr(sd, "expression"):
|
if not hasattr(sd, "expression"):
|
||||||
col.server_default = None
|
col.server_default = None
|
||||||
continue
|
continue
|
||||||
expr_str = str(sd.expression).lower()
|
expr_str = str(sd.expression).lower()
|
||||||
# Strip PostgreSQL-specific defaults
|
if "gen_random_uuid" in expr_str or "gen_random_bytes" in expr_str:
|
||||||
if any(x in expr_str for x in ["gen_random_uuid", "gen_random_bytes", "now()"]):
|
|
||||||
col.server_default = None
|
col.server_default = None
|
||||||
|
|
||||||
# Register event listener to populate timestamps on insert
|
|
||||||
for cls in Base.registry._class_registry.values():
|
|
||||||
if hasattr(cls, "__mapper__"):
|
|
||||||
event.listen(cls, "before_insert", _set_timestamp_defaults)
|
|
||||||
|
|
||||||
async with engine.begin() as conn:
|
async with engine.begin() as conn:
|
||||||
await conn.run_sync(Base.metadata.create_all)
|
await conn.run_sync(Base.metadata.create_all)
|
||||||
await conn.execute(
|
await conn.execute(
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ from cartsnitch_api.models.user import User, UserStoreAccount
|
|||||||
def engine():
|
def engine():
|
||||||
eng = create_engine("sqlite:///:memory:")
|
eng = create_engine("sqlite:///:memory:")
|
||||||
|
|
||||||
for tbl in Base.metadata.tables.values():
|
for table in Base.metadata.tables.values():
|
||||||
for col in tbl.columns.values():
|
for col in table.columns.values():
|
||||||
sd = col.server_default
|
sd = col.server_default
|
||||||
if sd is not None:
|
if sd is not None:
|
||||||
if not hasattr(sd, "expression"):
|
if not hasattr(sd, "expression"):
|
||||||
|
|||||||
Reference in New Issue
Block a user