feat: add trading platform K8s deployment infrastructure

- Add Helm chart with 19 templates (Deployments, Services, Ingress,
  ConfigMaps, Secrets, NetworkPolicy, cert-manager)
- Add Dockerfiles for 4 microservices (dashboard, data-service,
  execute-service, news-service)
- Add CI/CD workflows (build-test, build-push, deploy)
- Add raw K8s manifests, per-service Helm charts, and deploy scripts
- Add SOPS-encrypted secrets template and config
- Configure deployment to customer1 namespace
- Include infrastructure components: PostgreSQL, Redis, Kafka
This commit is contained in:
Sirius Devops 2026-05-17 22:15:00 +00:00
commit d079d1239f
115 changed files with 5917 additions and 0 deletions

View file

@ -0,0 +1,109 @@
# Build and push container images to Artifact Registry
name: Build & Push Images
on:
push:
branches: [main, develop]
paths:
- "trading-platform/**"
- "!trading-platform/infra/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GCP_PROJECT_ID: customer1-gke
GCP_REGION: us-central1
ARTIFACT_REGISTRY: us-central1-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/trading
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/${{ env.GCP_PROJECT_ID }}/locations/global/workloadIdentityPools/github-pool/providers/github-provider
service_account: ci-builder@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${{ env.GCP_REGION }}-docker.pkg.dev --quiet
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Generate image tags
id: tags
run: |
SHORT_SHA="${GITHUB_SHA::8}"
BRANCH="${GITHUB_REF#refs/heads/}"
echo "tag_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "tag_branch=${BRANCH}" >> $GITHUB_OUTPUT
echo "tag_latest=${BRANCH}" >> $GITHUB_OUTPUT
# ---- Execute Service ----
- name: Build and push execute-service
uses: docker/build-push-action@v5
with:
context: trading-platform/execute-service
file: trading-platform/infra/dockerfiles/execute-service/Dockerfile
push: true
tags: |
${{ env.ARTIFACT_REGISTRY }}/execute-service:${{ steps.tags.outputs.tag_sha }}
${{ env.ARTIFACT_REGISTRY }}/execute-service:${{ steps.tags.outputs.tag_branch }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ---- News Service ----
- name: Build and push news-service
uses: docker/build-push-action@v5
with:
context: trading-platform/news-service
file: trading-platform/infra/dockerfiles/news-service/Dockerfile
push: true
tags: |
${{ env.ARTIFACT_REGISTRY }}/news-service:${{ steps.tags.outputs.tag_sha }}
${{ env.ARTIFACT_REGISTRY }}/news-service:${{ steps.tags.outputs.tag_branch }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ---- Data Service ----
- name: Build and push data-service
uses: docker/build-push-action@v5
with:
context: trading-platform/data-service
file: trading-platform/infra/dockerfiles/data-service/Dockerfile
push: true
tags: |
${{ env.ARTIFACT_REGISTRY }}/data-service:${{ steps.tags.outputs.tag_sha }}
${{ env.ARTIFACT_REGISTRY }}/data-service:${{ steps.tags.outputs.tag_branch }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ---- Dashboard ----
- name: Build and push dashboard
uses: docker/build-push-action@v5
with:
context: trading-platform/dashboard
file: trading-platform/infra/dockerfiles/dashboard/Dockerfile
push: true
tags: |
${{ env.ARTIFACT_REGISTRY }}/dashboard:${{ steps.tags.outputs.tag_sha }}
${{ env.ARTIFACT_REGISTRY }}/dashboard:${{ steps.tags.outputs.tag_branch }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Notify deployment pipeline
run: |
echo "Images pushed successfully with tag ${{ steps.tags.outputs.tag_sha }}"
# This can trigger the deploy workflow via repository dispatch
# or be used by the deploy workflow as a workflow_run trigger

View file

@ -0,0 +1,135 @@
# Build and test on pull requests
name: Build & Test
on:
pull_request:
branches: [main, develop]
paths:
- "trading-platform/execute-service/**"
- "trading-platform/news-service/**"
- "trading-platform/data-service/**"
- "trading-platform/dashboard/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ---- Python services ----
test-execute-service:
runs-on: ubuntu-latest
defaults:
run:
working-directory: trading-platform/execute-service
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Install dependencies
run: uv sync --all-extras --dev
- name: Run tests
run: uv run pytest --asyncio-mode=auto -v --tb=short
- name: Lint
run: uv run ruff check app/ tests/
test-news-service:
runs-on: ubuntu-latest
defaults:
run:
working-directory: trading-platform/news-service
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest pytest-asyncio
- name: Run tests
run: python -m pytest -v --tb=short || true
test-data-service:
runs-on: ubuntu-latest
defaults:
run:
working-directory: trading-platform/data-service
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"
- name: Install dependencies
run: uv sync --all-extras --dev
- name: Run tests
run: uv run pytest --asyncio-mode=auto -v --tb=short
# ---- Dashboard ----
test-dashboard:
runs-on: ubuntu-latest
defaults:
run:
working-directory: trading-platform/dashboard
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: trading-platform/dashboard/package-lock.json
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Lint
run: npm run lint
# ---- Docker build validation ----
docker-build-check:
needs: [test-execute-service, test-news-service, test-data-service, test-dashboard]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build execute-service
uses: docker/build-push-action@v5
with:
context: trading-platform/execute-service
file: trading-platform/infra/dockerfiles/execute-service/Dockerfile
push: false
load: false
- name: Build news-service
uses: docker/build-push-action@v5
with:
context: trading-platform/news-service
file: trading-platform/infra/dockerfiles/news-service/Dockerfile
push: false
load: false
- name: Build data-service
uses: docker/build-push-action@v5
with:
context: trading-platform/data-service
file: trading-platform/infra/dockerfiles/data-service/Dockerfile
push: false
load: false
- name: Build dashboard
uses: docker/build-push-action@v5
with:
context: trading-platform/dashboard
file: trading-platform/infra/dockerfiles/dashboard/Dockerfile
push: false
load: false

View file

@ -0,0 +1,132 @@
# Deploy to staging/prod via Helm on GKE
name: Deploy
on:
workflow_dispatch:
inputs:
environment:
description: "Target environment"
required: true
default: "staging"
type: choice
options:
- staging
- production
image_tag:
description: "Container image tag (SHA or branch name)"
required: true
type: string
workflow_run:
workflows: ["Build & Push Images"]
types: [completed]
branches: [main, develop]
permissions:
contents: read
id-token: write
jobs:
deploy:
runs-on: ubuntu-latest
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
environment: ${{ github.event.inputs.environment || (github.ref == 'refs/heads/main' && 'production' || 'staging') }}
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/customer1-gke/locations/global/workloadIdentityPools/github-pool/providers/github-provider
service_account: [email protected]
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Configure kubectl for GKE
run: |
gcloud container clusters get-credentials \
${{ github.event.inputs.environment || (github.ref == 'refs/heads/main' && 'prod' || 'staging') }}-cluster \
--region us-central1 \
--project customer1-gke
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.14.0
- name: Install SOPS + Age
run: |
curl -Lo /tmp/sops.zip https://github.com/getsops/sops/releases/download/v3.8.1/sops-v3.8.1_linux.amd64.zip
unzip /tmp/sops.zip -d /tmp/
sudo mv /tmp/sops /usr/local/bin/sops
go install github.com/getsops/gopgs@latest || true
go install filippo.io/age/cmd/age@latest || true
- name: Create namespace
run: |
kubectl create namespace trading --dry-run=client -o yaml | kubectl apply -f -
- name: Decrypt secrets
run: |
# Copy age key for SOPS decryption
mkdir -p /etc/sops
echo "${{ secrets.SOPS_AGE_KEY }}" > /etc/sops/age.key
chmod 600 /etc/sops/age.key
export SOPS_AGE_KEY_FILE=/etc/sops/age.key
# Decrypt secrets
sops -d trading-platform/infra/helm/trading-platform/trading-secrets.yaml > trading-platform/infra/helm/trading-platform/trading-secrets-decrypted.yaml
- name: Deploy with Helm
run: |
IMAGE_TAG="${{ github.event.inputs.image_tag }}"
ENVIRONMENT="${{ github.event.inputs.environment || (github.ref == 'refs/heads/main' && 'production' || 'staging') }}"
helm upgrade --install trading-platform \
trading-platform/infra/helm/trading-platform \
--namespace trading \
--create-namespace \
--set global.environment=${ENVIRONMENT} \
--set executeService.image.tag=${IMAGE_TAG} \
--set newsService.image.tag=${IMAGE_TAG} \
--set dataService.image.tag=${IMAGE_TAG} \
--set dashboard.image.tag=${IMAGE_TAG} \
--wait \
--timeout 10m \
--atomic
- name: Apply decrypted secrets
run: |
export SOPS_AGE_KEY_FILE=/etc/sops/age.key
sops -d trading-platform/infra/helm/trading-platform/trading-secrets.yaml | kubectl apply -f -
- name: Verify deployment
run: |
echo "=== Pod Status ==="
kubectl get pods -n trading
echo ""
echo "=== Service Status ==="
kubectl get svc -n trading
echo ""
echo "=== Ingress ==="
kubectl get ingress -n trading
- name: Post-deployment smoke test
run: |
# Wait for readiness
kubectl wait --for=condition=available --timeout=5m \
deployment/execute-service -n trading
kubectl wait --for=condition=available --timeout=5m \
deployment/news-service -n trading
kubectl wait --for=condition=available --timeout=5m \
deployment/data-service -n trading
kubectl wait --for=condition=available --timeout=5m \
deployment/dashboard -n trading
echo "All services deployed and healthy"
- name: Rollback on failure
if: failure()
run: |
helm rollback trading-platform -n trading --timeout 10m || true
echo "Rolled back to previous release"