From 6599249d653a8b2d0a8895390c5786cb129ca055 Mon Sep 17 00:00:00 2001 From: sirius0xdev Date: Sat, 2 May 2026 22:29:06 +0000 Subject: [PATCH 1/2] feat(trade-dashboard): add GitHub Actions CI/CD pipeline - Build and push Docker image to ghcr.io on push to master - Update deployment to pull from ghcr.io instead of GCR - Tags: commit SHA + latest on default branch --- .github/workflows/trade-dashboard.yml | 52 +++++++++++++++++++ .../customer1/trade-dashboard/deployment.yaml | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/trade-dashboard.yml diff --git a/.github/workflows/trade-dashboard.yml b/.github/workflows/trade-dashboard.yml new file mode 100644 index 0000000..c72b162 --- /dev/null +++ b/.github/workflows/trade-dashboard.yml @@ -0,0 +1,52 @@ +name: Build and Push Trade Dashboard + +on: + push: + branches: [master] + paths: + - 'apps/base/customer1/trade-dashboard/**' + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository_owner }}/trade-dashboard + +permissions: + contents: read + packages: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha,prefix= + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: apps/base/customer1/trade-dashboard + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/apps/base/customer1/trade-dashboard/deployment.yaml b/apps/base/customer1/trade-dashboard/deployment.yaml index ec5e0bb..ced595d 100644 --- a/apps/base/customer1/trade-dashboard/deployment.yaml +++ b/apps/base/customer1/trade-dashboard/deployment.yaml @@ -22,7 +22,7 @@ spec: terminationGracePeriodSeconds: 30 containers: - name: dashboard - image: us-central1-docker.pkg.dev/devops-lab-cluster/customer1/trade-dashboard:latest + image: ghcr.io/sirius0xdev/trade-dashboard:latest imagePullPolicy: Always ports: - containerPort: 8000 From 23c7c707d8bee2860005e741bbfc8b26e2d90a03 Mon Sep 17 00:00:00 2001 From: sirius0xdev Date: Sat, 2 May 2026 22:44:38 +0000 Subject: [PATCH 2/2] fix(trade-dashboard): fix import errors and alembic migration - database.py: remove dead pre-definition of DATABASE_URL with undefined db_user/db_pass variables - models.py: add missing Table import from sqlalchemy - alembic/env.py: replace deprecated run_async() with asyncio.run() (removed in SQLAlchemy 2.0) - alembic 001_initial: use raw SQL for CREATE TYPE instead of op.create_enum() which requires alembic_postgresql_enum Migration 001_initial successfully applied to trading_data DB. --- .../base/customer1/trade-dashboard/alembic/env.py | 5 +++-- .../alembic/versions/001_initial.py | 2 +- .../customer1/trade-dashboard/app/database.py | 15 +++------------ apps/base/customer1/trade-dashboard/app/models.py | 2 +- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/apps/base/customer1/trade-dashboard/alembic/env.py b/apps/base/customer1/trade-dashboard/alembic/env.py index e474716..5fcf711 100644 --- a/apps/base/customer1/trade-dashboard/alembic/env.py +++ b/apps/base/customer1/trade-dashboard/alembic/env.py @@ -54,8 +54,9 @@ async def run_migrations_online() -> None: await connectable.dispose() +import asyncio + if context.is_offline_mode(): run_migrations_offline() else: - from sqlalchemy.ext.asyncio import run_async # noqa: E402 - run_async(run_migrations_online()) + asyncio.run(run_migrations_online()) diff --git a/apps/base/customer1/trade-dashboard/alembic/versions/001_initial.py b/apps/base/customer1/trade-dashboard/alembic/versions/001_initial.py index 51ed0d7..702c57d 100644 --- a/apps/base/customer1/trade-dashboard/alembic/versions/001_initial.py +++ b/apps/base/customer1/trade-dashboard/alembic/versions/001_initial.py @@ -15,7 +15,7 @@ depends_on = None def upgrade() -> None: - op.create_enum("position_direction", "long", "short", schema="public", create_type=True) + op.execute('CREATE TYPE position_direction AS ENUM (\'long\', \'short\')') op.create_table( "positions", diff --git a/apps/base/customer1/trade-dashboard/app/database.py b/apps/base/customer1/trade-dashboard/app/database.py index 2101b78..f6c74d9 100644 --- a/apps/base/customer1/trade-dashboard/app/database.py +++ b/apps/base/customer1/trade-dashboard/app/database.py @@ -1,17 +1,8 @@ -from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine -from sqlalchemy import MetaData - -# Connection to hermes-pgdb CNPG cluster -DATABASE_URL = ( - f"postgresql+asyncpg://{db_user}:{db_pass}" - f"@hermes-pgdb-rw.customer1.svc.cluster.local:5432/trading_data" -).format( - db_user="trading", - db_pass="TRADING_DB_PASSWORD", # overridden by env -) - import os +from sqlalchemy import MetaData +from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine + DB_USER = os.getenv("DB_USER", "trading") DB_PASS = os.getenv("DB_PASSWORD", "") DB_HOST = os.getenv("DB_HOST", "hermes-pgdb-rw.customer1.svc.cluster.local") diff --git a/apps/base/customer1/trade-dashboard/app/models.py b/apps/base/customer1/trade-dashboard/app/models.py index 8169975..9e0e92d 100644 --- a/apps/base/customer1/trade-dashboard/app/models.py +++ b/apps/base/customer1/trade-dashboard/app/models.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, String, Numeric, Enum, DateTime, JSON, func +from sqlalchemy import Column, String, Numeric, Enum, DateTime, JSON, func, Table from sqlalchemy.dialects.postgresql import UUID import uuid