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
136 changes: 136 additions & 0 deletions .github/workflows/coding-interview_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: CI for Coding Interview Platform

on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- '02-coding-interview/**'
push:
branches:
- main
paths:
- '02-coding-interview/**'

defaults:
run:
working-directory: 02-coding-interview

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 02-coding-interview/package-lock.json

- name: Install dependencies
run: npm ci

- name: Run ESLint (Frontend)
run: npm run lint -w @interview/frontend

- name: Run TypeScript compiler check
run: npm run build

test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_DB: interview_platform
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

docker:
image: docker:dind
options: --privileged
ports:
- 2375:2375
env:
DOCKER_TLS_CERTDIR: ""

env:
DOCKER_HOST: tcp://localhost:2375

steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 02-coding-interview/package-lock.json

- name: Install dependencies
run: npm ci

- name: Set up environment
run: |
cd packages/backend
cp .env.example .env

- name: Generate Prisma Client
run: |
cd packages/backend
npx prisma generate

- name: Run database migrations
run: |
cd packages/backend
echo "Running migrations..."
npx prisma migrate deploy
echo "Migration exit code: $?"
echo "Verifying tables..."
npx prisma db execute --stdin <<< "SELECT tablename FROM pg_tables WHERE schemaname = 'public';"
env:
DATABASE_URL: postgresql://admin:password@localhost:5432/interview_platform

- name: Wait for Docker and pull images
run: |
echo "Waiting for Docker daemon..."
timeout 60 sh -c 'until docker info > /dev/null 2>&1; do sleep 2; done'
echo "Docker is ready. Pulling test images..."
docker pull node:20-alpine
docker pull python:3.11-alpine

- name: Run integration tests
run: npm test -- --verbose
env:
DATABASE_URL: postgresql://admin:password@localhost:5432/interview_platform
REDIS_URL: redis://localhost:6379
NODE_ENV: test

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: 02-coding-interview/packages/backend/coverage/
18 changes: 18 additions & 0 deletions 02-coding-interview/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
node_modules
dist
.git
.gitignore
*.md
.env
.env.local
.DS_Store
packages/*/node_modules
packages/*/dist
packages/backend/.env
packages/backend/.env.local
packages/frontend/.env
packages/frontend/.env.local
coverage
*.log
.vscode
.idea
46 changes: 46 additions & 0 deletions 02-coding-interview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Dependencies
node_modules/
.pnp
.pnp.js

# Testing
coverage/

# Production
dist/
build/

# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Prisma - keep migrations tracked for CI/CD
# packages/backend/prisma/migrations/

# Temporary files
tmp/
temp/
*.tmp
57 changes: 57 additions & 0 deletions 02-coding-interview/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Multi-stage build for coding interview platform
FROM node:20-alpine AS builder

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./
COPY packages/shared/package*.json ./packages/shared/
COPY packages/backend/package*.json ./packages/backend/
COPY packages/frontend/package*.json ./packages/frontend/

# Install dependencies
RUN npm ci

# Copy source code
COPY packages/shared ./packages/shared
COPY packages/backend ./packages/backend
COPY packages/frontend ./packages/frontend

# Build all packages
RUN npm run build

# Production stage
FROM node:20-alpine

WORKDIR /app

# Copy package files for production install
COPY package*.json ./
COPY packages/shared/package*.json ./packages/shared/
COPY packages/backend/package*.json ./packages/backend/
COPY packages/frontend/package*.json ./packages/frontend/

# Install production dependencies only
RUN npm ci --production

# Copy built artifacts from builder
COPY --from=builder /app/packages/shared/dist ./packages/shared/dist
COPY --from=builder /app/packages/backend/dist ./packages/backend/dist
COPY --from=builder /app/packages/frontend/dist ./packages/frontend/dist

# Copy Prisma schema and migrations
COPY packages/backend/prisma ./packages/backend/prisma

# Generate Prisma Client
RUN cd packages/backend && npx prisma generate

# Expose port (Render uses PORT env var, defaults to 10000)
EXPOSE 10000

# Set environment to production
ENV NODE_ENV=production
ENV PORT=10000

# Start the backend server (which will serve the frontend)
CMD ["node", "packages/backend/dist/index.js"]
Loading
Loading