Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
.env
.env.*
dist
.git
.gitignore
.git
.turbo
**/.turbo
dist
**/dist
node_modules
**/node_modules
Dockerfile
docker-compose*.yml
README.MD
.vscode
.idea
.DS_Store
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.github
48 changes: 29 additions & 19 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,76 @@ name: 🚀 Kizo Production Deploy
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
# --- STAGE 1: TEST ---
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
# Removed the npm cache requirement since we don't have a lockfile yet

- name: Install Deps
run: npm ci
# CHANGED: Use install instead of ci so it works without package-lock.json
run: npm install --legacy-peer-deps

- name: Prepare Workspace
run: |
npm run prepare:backend
npx turbo build --filter="./packages/*"
env:
DATABASE_URL: "postgresql://postgres:password@localhost:5432/postgres"
DIRECT_URL: "postgresql://postgres:password@localhost:5432/postgres"
REDIS_URL: "redis://localhost:6379"

- name: Run Vitest
run: npm test # Runs your "vitest run" script
run: npm test

# --- STAGE 2: BUILD & PUSH ---
# --- STAGE 2: BUILD & PUSH (MONOLITH) ---
build:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
include:
- app: "@kizo/api"
tag: "kizo-api"
- app: "@kizo/worker"
tag: "kizo-worker"
- app: "@kizo/processor"
tag: "kizo-processor"
steps:
- uses: actions/checkout@v4

- name: Docker Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.prod
build-args: TARGET_APP=${{ matrix.app }}
file: ./Dockerfile
push: true
tags: haribhakt/${{ matrix.tag }}:latest
# CHANGED: We now push the single monolith image
tags: haribhakt/kizo:latest

# --- STAGE 3: DEPLOY ---
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Copy prod.yml
uses: appleboy/scp-action@master
with:
host: ${{ secrets.GCP_VM_IP }}
username: ${{ secrets.GCP_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "prod.yml"
source: "prod.yml" # Make sure your docker-compose is named prod.yml in your repo!
target: "~/kizo"

- name: SSH Deploy
uses: appleboy/ssh-action@master
with:
Expand All @@ -71,8 +81,8 @@ jobs:
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
mkdir -p ~/kizo
echo "${{ secrets.PROD_ENV_FILE }}" > ~/kizo/.env
echo "${{ secrets.PROD_ENV_FILE }}" > ~/kizo/.env.prod
cd ~/kizo
docker compose -f prod.yml pull
docker compose -f prod.yml up -d
docker system prune -f
docker system prune -f
73 changes: 48 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
FROM node:20-alpine

# --- STAGE 1: Builder ---
FROM node:22-slim AS builder
RUN apt-get update -y && apt-get install -y openssl wget && rm -rf /var/lib/apt/lists/*
WORKDIR /app
RUN corepack enable

COPY pnpm-workspace.yaml pnpm-lock.yaml ./
COPY package.json turbo.json ./
COPY packages ./packages
COPY apps ./apps

# ✅ install dev deps so turbo exists
RUN pnpm install --frozen-lockfile

ARG DIRECT_URL
ENV DIRECT_URL=$DIRECT_URL
ENV NODE_ENV=production

# prisma like local
RUN pnpm --filter @kizo/db exec prisma generate

ARG PACKAGE_NAME
RUN pnpm build --filter ${PACKAGE_NAME}

ARG APP_DIR
WORKDIR /app/apps/${APP_DIR}

CMD ["node", "dist/server.js"]
# 1. Copy Manifests individually to FORCE the correct directory structure
COPY package*.json turbo.json ./
COPY apps/kizo-api/package.json ./apps/kizo-api/
COPY apps/kizo-worker/package.json ./apps/kizo-worker/
COPY apps/kizo-processor/package.json ./apps/kizo-processor/

# Explicitly copy each package manifest so the directory exists for npm
COPY packages/kizo-db/package.json ./packages/kizo-db/
COPY packages/kizo-shared/package.json ./packages/kizo-shared/
COPY packages/kizo-logger/package.json ./packages/kizo-logger/
COPY packages/kizo-metrics/package.json ./packages/kizo-metrics/
COPY packages/kizo-queue/package.json ./packages/kizo-queue/

# 2. Install (This will now correctly find local workspaces)
RUN npm install --legacy-peer-deps

# 3. Copy source and build EVERYTHING
COPY . .
ENV DATABASE_URL="postgresql://stub:stub@localhost:5432/stub"
ENV DIRECT_URL="postgresql://stub:stub@localhost:5432/stub"

# Build all apps (API, Worker, Processor)
RUN ./node_modules/.bin/turbo build \
--filter=@kizo/api... \
--filter=@kizo/worker... \
--filter=@kizo/processor...

# 4. Prune for production size
RUN npm prune --production

# --- STAGE 2: Runner ---
FROM node:22-slim AS runner
WORKDIR /app
RUN apt-get update -y && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/apps ./apps
COPY --from=builder /app/packages ./packages

# Start all three in one container
CMD node --max-old-space-size=256 apps/kizo-api/dist/server.js & \
node --max-old-space-size=256 apps/kizo-worker/dist/server.js & \
node --max-old-space-size=256 apps/kizo-processor/dist/server.js & \
wait
24 changes: 13 additions & 11 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
FROM node:22-slim

RUN apt-get update -y && apt-get install -y openssl wget
# Install system dependencies for Prisma/Postgres
RUN apt-get update -y && apt-get install -y openssl wget \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

RUN npm install -g turbo tsx prisma
# Install global CLI tools
RUN npm install -g turbo

COPY package*.json ./
COPY turbo.json ./
# Copy all package.jsons so npm knows about the workspaces
COPY packages/kizo-db/package.json ./packages/kizo-db/
COPY packages/kizo-logger/package.json ./packages/kizo-logger/
COPY packages/kizo-queue/package.json ./packages/kizo-queue/
# 📦 1. Copy root config and ALL package.jsons using wildcards
COPY package*.json turbo.json ./
COPY packages/*/package.json ./packages/
COPY apps/*/package.json ./apps/

# 🏗️ 2. First install (installs structure and links)
RUN npm install

# 📂 3. Copy the rest of the code
COPY . .

# 🚀 THE FIX: Force npm to re-symlink everything inside the Linux environment
RUN npm install

# 🔄 4. Generate Prisma (Points specifically to your DB package)
RUN npx prisma generate --schema=./packages/kizo-db/prisma/schema.prisma

# Final command for dev
CMD ["turbo", "run", "dev"]
26 changes: 2 additions & 24 deletions apps/kizo-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
"scripts": {
"predev": "npm -w @kizo/db exec prisma generate",
"dev": "tsx watch src/server.ts",

"prebuild": "pnpm --filter @kizo/db exec prisma generate",
"prebuild": "npm -w @kizo/db exec prisma generate",
"build": "tsc",

"start": "node dist/server.js",
"test": "vitest",
"test:stress": "tsx apps/kizo-api/scripts/stress-test.ts"
Expand All @@ -21,29 +19,9 @@
"@kizo/logger": "*",
"@kizo/metrics": "*",
"@kizo/queue": "*",
"@kizo/shared": "*",
"@supabase/supabase-js": "^2.88.0",
"argon2": "^0.43.0",
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"express": "^5.1.0",
"json2csv": "6.0.0-alpha.2",
"jsonwebtoken": "^9.0.2",
"multer": "^2.0.2",
"pino-loki": "^3.0.0",
"sharp": "^0.34.5",
"swagger-ui-express": "^5.0.1",
"uuid": "^13.0.0",
"yaml": "^2.8.2"
"@kizo/shared": "*"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.9",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.3",
"@types/json2csv": "^5.0.7",
"@types/multer": "^2.0.0",
"@types/node": "^24.0.3",
"@types/swagger-ui-express": "^4.1.8",
"tsx": "^4.21.0",
"typescript": "^5.4.0"
}
Expand Down
Loading
Loading