feat(phase-0): setup Docker Compose with TypeScript monorepo structure
- Create monorepo structure with apps/ and packages/ - Add Docker Compose for api, web, db, redis, worker services - Migrate existing Express.js logic to TypeScript with 100% backward compatibility - Preserve all existing API endpoints (/api/track, /api/v1/track) with identical behavior - Setup development environment with hot reload and proper networking - Add comprehensive TypeScript configuration with path mapping - Include production-ready Dockerfiles with multi-stage builds - Maintain existing rate limiting (100 req/hour/IP) and response formats - Add health checks and graceful shutdown handling - Setup Turbo for efficient monorepo builds and development
This commit is contained in:
61
apps/worker/Dockerfile
Normal file
61
apps/worker/Dockerfile
Normal file
@@ -0,0 +1,61 @@
|
||||
# Multi-stage build for production optimization
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
# Install Playwright dependencies
|
||||
RUN apk add --no-cache \
|
||||
chromium \
|
||||
nss \
|
||||
freetype \
|
||||
freetype-dev \
|
||||
harfbuzz \
|
||||
ca-certificates \
|
||||
ttf-freefont
|
||||
|
||||
# Tell Playwright to use the installed chromium
|
||||
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
||||
ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser
|
||||
|
||||
# Development stage
|
||||
FROM base AS dev
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
COPY apps/worker/package*.json ./apps/worker/
|
||||
COPY packages/database/package*.json ./packages/database/
|
||||
COPY packages/shared/package*.json ./packages/shared/
|
||||
|
||||
# Install all dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY apps/worker ./apps/worker
|
||||
COPY packages/database ./packages/database
|
||||
COPY packages/shared ./packages/shared
|
||||
|
||||
WORKDIR /app/apps/worker
|
||||
|
||||
CMD ["npm", "run", "dev"]
|
||||
|
||||
# Production stage
|
||||
FROM base AS production
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files and install dependencies
|
||||
COPY package*.json ./
|
||||
COPY apps/worker ./apps/worker
|
||||
COPY packages/database ./packages/database
|
||||
COPY packages/shared ./packages/shared
|
||||
|
||||
# Install dependencies and build
|
||||
RUN npm ci --only=production
|
||||
WORKDIR /app/apps/worker
|
||||
RUN npm run build
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nodejs
|
||||
|
||||
USER nodejs
|
||||
|
||||
CMD ["npm", "start"]
|
||||
31
apps/worker/package.json
Normal file
31
apps/worker/package.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@redirect-intelligence/worker",
|
||||
"version": "2.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "tsx watch --clear-screen=false src/index.ts",
|
||||
"build": "tsc",
|
||||
"start": "node dist/index.js",
|
||||
"test": "jest",
|
||||
"lint": "eslint src --ext .ts",
|
||||
"lint:fix": "eslint src --ext .ts --fix",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"bullmq": "^4.15.4",
|
||||
"ioredis": "^5.3.2",
|
||||
"@prisma/client": "*",
|
||||
"axios": "^1.6.7",
|
||||
"playwright": "^1.40.1",
|
||||
"dotenv": "^16.3.1",
|
||||
"winston": "^3.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.0",
|
||||
"tsx": "^4.6.2",
|
||||
"typescript": "^5.3.0",
|
||||
"jest": "^29.7.0",
|
||||
"@types/jest": "^29.5.8",
|
||||
"ts-jest": "^29.1.1"
|
||||
}
|
||||
}
|
||||
15
apps/worker/tsconfig.json
Normal file
15
apps/worker/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "../api/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
"**/*.test.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user