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:
parent
af4cb3d321
commit
d079d1239f
115 changed files with 5917 additions and 0 deletions
26
trading-platform/deploy/dockerfiles/api-gateway.Dockerfile
Normal file
26
trading-platform/deploy/dockerfiles/api-gateway.Dockerfile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# =============================================================================
|
||||
# API Gateway Dockerfile — Nginx-based reverse proxy with rate limiting
|
||||
# =============================================================================
|
||||
FROM nginx:1.25-alpine AS production
|
||||
|
||||
# Copy custom nginx configuration
|
||||
COPY deploy/k8s/base/gateway/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY deploy/k8s/base/gateway/conf.d/ /etc/nginx/conf.d/
|
||||
|
||||
# Create required directories
|
||||
RUN mkdir -p /etc/nginx/ssl \
|
||||
/etc/nginx/conf.d \
|
||||
/var/cache/nginx \
|
||||
/var/run/nginx \
|
||||
/var/log/nginx \
|
||||
&& touch /var/run/nginx/nginx.pid
|
||||
|
||||
# Security: run as nginx user (already exists in alpine image)
|
||||
USER nginx
|
||||
|
||||
EXPOSE 8080 8443
|
||||
|
||||
HEALTHCHECK --interval=15s --timeout=3s --start-period=10s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
40
trading-platform/deploy/dockerfiles/dashboard.Dockerfile
Normal file
40
trading-platform/deploy/dockerfiles/dashboard.Dockerfile
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# =============================================================================
|
||||
# Dashboard Dockerfile — Next.js multi-stage build with static export
|
||||
# =============================================================================
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies first (better layer caching)
|
||||
COPY trading-platform/dashboard/package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Copy source and build
|
||||
COPY trading-platform/dashboard/ ./
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM node:20-alpine AS production
|
||||
|
||||
# Security: non-root user
|
||||
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy built output and package.json from builder
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
32
trading-platform/deploy/dockerfiles/data-service.Dockerfile
Normal file
32
trading-platform/deploy/dockerfiles/data-service.Dockerfile
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# =============================================================================
|
||||
# Data Service Dockerfile — Multi-stage build
|
||||
# =============================================================================
|
||||
FROM python:3.12-slim AS builder
|
||||
|
||||
WORKDIR /build
|
||||
COPY trading-platform/data-service/pyproject.toml ./
|
||||
RUN pip install --no-cache-dir --prefix=/install .
|
||||
|
||||
# Production stage
|
||||
FROM python:3.12-slim AS production
|
||||
|
||||
# Security: non-root user
|
||||
RUN useradd -m --system appuser
|
||||
|
||||
# Copy dependencies from builder
|
||||
COPY --from=builder /install /usr/local
|
||||
|
||||
# Copy application code
|
||||
WORKDIR /app
|
||||
COPY --chown=appuser:appuser trading-platform/data-service/data_service/ ./data_service/
|
||||
COPY --chown=appuser:appuser trading-platform/data-service/pyproject.toml ./
|
||||
|
||||
USER appuser
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=15s --timeout=5s --start-period=15s --retries=3 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8001/health')" || exit 1
|
||||
|
||||
EXPOSE 8001
|
||||
|
||||
CMD ["uvicorn", "data_service.app.main:app", "--host", "0.0.0.0", "--port", "8001"]
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# =============================================================================
|
||||
# Execute Service Dockerfile — Multi-stage build for minimal image
|
||||
# =============================================================================
|
||||
# Build stage: compile dependencies
|
||||
FROM python:3.12-slim AS builder
|
||||
|
||||
WORKDIR /build
|
||||
COPY trading-platform/execute-service/pyproject.toml ./
|
||||
RUN pip install --no-cache-dir --prefix=/install .
|
||||
|
||||
# Production stage
|
||||
FROM python:3.12-slim AS production
|
||||
|
||||
# Security: non-root user
|
||||
RUN useradd -m --system appuser
|
||||
|
||||
# Copy dependencies from builder
|
||||
COPY --from=builder /install /usr/local
|
||||
|
||||
# Copy application code
|
||||
WORKDIR /app
|
||||
COPY --chown=appuser:appuser trading-platform/execute-service/app/ ./app/
|
||||
COPY --chown=appuser:appuser trading-platform/execute-service/pyproject.toml ./
|
||||
|
||||
# Create required directories with proper permissions
|
||||
RUN mkdir -p /tmp /app/data && chown -R appuser:appuser /tmp /app/data
|
||||
|
||||
USER appuser
|
||||
|
||||
# Health check using Python (curl not in slim)
|
||||
HEALTHCHECK --interval=15s --timeout=5s --start-period=15s --retries=3 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
41
trading-platform/deploy/dockerfiles/news-service.Dockerfile
Normal file
41
trading-platform/deploy/dockerfiles/news-service.Dockerfile
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# =============================================================================
|
||||
# News Service Dockerfile — Multi-stage build with NLTK data
|
||||
# =============================================================================
|
||||
FROM python:3.12-slim AS builder
|
||||
|
||||
WORKDIR /build
|
||||
COPY trading-platform/news-service/requirements.txt ./
|
||||
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
||||
|
||||
# Production stage
|
||||
FROM python:3.12-slim AS production
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
gcc libpq-dev && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies from builder
|
||||
COPY --from=builder /install /usr/local
|
||||
|
||||
# Download NLTK data for textblob
|
||||
RUN python -c "import nltk; nltk.download('punkt'); nltk.download('punkt_tab'); nltk.download('averaged_perceptron_tagger')"
|
||||
|
||||
# Security: non-root user
|
||||
RUN useradd -m --system appuser
|
||||
|
||||
# Copy application code
|
||||
WORKDIR /app
|
||||
COPY --chown=appuser:appuser trading-platform/news-service/app/ ./app/
|
||||
COPY --chown=appuser:appuser trading-platform/news-service/requirements.txt ./
|
||||
|
||||
USER appuser
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8002/health')" || exit 1
|
||||
|
||||
EXPOSE 8002
|
||||
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8002", "--workers", "4"]
|
||||
Loading…
Reference in a new issue