diff --git a/apps/cache-proxy/Dockerfile b/apps/cache-proxy/Dockerfile index 537ce02..45c0ee8 100644 --- a/apps/cache-proxy/Dockerfile +++ b/apps/cache-proxy/Dockerfile @@ -1,45 +1,51 @@ -# This Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker. -# Make sure you update both files! +ARG NODE_VERSION=22 +ARG PROJECT=cache-proxy -FROM node:alpine AS builder -RUN corepack enable && corepack prepare pnpm@8.9.0 --activate -ENV PNPM_HOME=/usr/local/bin -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk add --no-cache libc6-compat +# Alpine image +FROM node:${NODE_VERSION}-alpine AS alpine RUN apk update -# Set working directory +RUN apk add --no-cache libc6-compat + +FROM alpine as base +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN apk add --no-cache libc6-compat && \ + corepack enable && \ + pnpm install turbo@2.3.2 dotenv-cli --global + +FROM base AS pruner +ARG PROJECT WORKDIR /app -RUN pnpm add -g turbo@1.12.4 dotenv-cli COPY . . -RUN turbo prune --scope=api --docker +RUN turbo prune --scope=${PROJECT} --docker -# Add lockfile and package.json's of isolated subworkspace -FROM node:alpine AS installer -RUN corepack enable && corepack prepare pnpm@latest --activate -ENV PNPM_HOME=/usr/local/bin -RUN apk add --no-cache libc6-compat -RUN apk update +FROM base AS builder WORKDIR /app -# First install dependencies (as they change less often) -COPY .gitignore .gitignore -COPY --from=builder /app/out/json/ . -COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml -COPY --from=builder /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml -RUN pnpm install +COPY --from=pruner /app/out/json/ . +COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml +COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml + +RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --prod --frozen-lockfile + +COPY --from=pruner /app/out/full/ . -# Build the project and its dependencies -COPY --from=builder /app/out/full/ . COPY turbo.json turbo.json -RUN pnpm dotenv -e .env turbo run build --filter=api... +COPY .env .env + +RUN dotenv -e .env turbo run build --filter=${PROJECT}... +RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm prune --prod --no-optional +RUN rm -rf ./**/*/src + +FROM alpine AS runner +ARG PROJECT + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 appuser +USER appuser -FROM node:alpine AS runner WORKDIR /app +COPY --from=builder --chown=nodejs:nodejs /app . +WORKDIR /app/apps/${PROJECT} -# Don't run production as root -RUN addgroup --system --gid 1001 nestjs -RUN adduser --system --uid 1001 nestjs -USER nestjs -COPY --from=installer /app . - -CMD node apps/api/dist/main.js +CMD ["node", "dist/main.js"] diff --git a/apps/cache-proxy/package.json b/apps/cache-proxy/package.json index f64c45a..c0bf098 100644 --- a/apps/cache-proxy/package.json +++ b/apps/cache-proxy/package.json @@ -20,39 +20,40 @@ "test:e2e": "jest --config ./test/jest-e2e.json" }, "dependencies": { + "@nestjs/cli": "^10.0.0", + "@nestjs/schematics": "^10.0.0", "@nestjs/cache-manager": "^2.2.1", "@nestjs/common": "^10.0.0", "@nestjs/config": "^3.2.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", "@nestjs/platform-fastify": "^10.3.3", + "@types/node": "catalog:", + "fastify": "^4.26.1", + "dotenv-cli": "catalog:", "cache-manager": "^5.4.0", "cache-manager-ioredis": "^2.1.0", "ioredis": "^5.3.2", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", + "source-map-support": "^0.5.21", + "tsconfig-paths": "^4.2.0", + "typescript": "catalog:", "zod": "catalog:" }, "devDependencies": { - "@nestjs/cli": "^10.0.0", - "@nestjs/schematics": "^10.0.0", "@nestjs/testing": "^10.0.0", + "@repo/eslint-config": "workspace:*", "@repo/typescript-config": "workspace:*", "@types/jest": "^29.5.2", - "@types/node": "catalog:", "@types/supertest": "^6.0.0", - "dotenv-cli": "catalog:", "eslint": "catalog:", - "fastify": "^4.26.1", "jest": "^29.5.0", "prettier": "catalog:", - "source-map-support": "^0.5.21", "supertest": "^6.3.3", "ts-jest": "29.1.1", "ts-loader": "^9.4.3", - "ts-node": "^10.9.1", - "tsconfig-paths": "^4.2.0", - "typescript": "catalog:" + "ts-node": "^10.9.1" }, "jest": { "moduleFileExtensions": [ diff --git a/apps/cache-proxy/tsconfig.json b/apps/cache-proxy/tsconfig.json index a7f602d..d1bdb60 100644 --- a/apps/cache-proxy/tsconfig.json +++ b/apps/cache-proxy/tsconfig.json @@ -6,7 +6,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, - "target": "ES2021", + "target": "ES2022", "sourceMap": true, "outDir": "./dist", "baseUrl": "./", @@ -18,5 +18,6 @@ "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false }, - "exclude": ["node_modules"] + "include": ["."], + "exclude": ["dist", "build", "node_modules"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6cf48f3..06ddcde 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,7 +23,7 @@ catalogs: version: 2.2.2 autoprefixer: specifier: ^10.4.20 - version: 10.4.21 + version: 10.4.20 dayjs: specifier: ^1.11.3 version: 1.11.13 @@ -35,7 +35,7 @@ catalogs: version: 9.21.0 graphql: specifier: ^16.9.0 - version: 16.11.0 + version: 16.9.0 husky: specifier: ^9.1.7 version: 9.1.7 @@ -44,13 +44,13 @@ catalogs: version: 9.0.2 lint-staged: specifier: ^15.2.10 - version: 15.5.2 + version: 15.2.10 lucide-react: specifier: ^0.462.0 version: 0.462.0 postcss: specifier: ^8.4.49 - version: 8.5.6 + version: 8.4.49 postcss-load-config: specifier: ^6.0.1 version: 6.0.1 @@ -59,7 +59,7 @@ catalogs: version: 3.6.2 radashi: specifier: ^12.5.1 - version: 12.6.0 + version: 12.5.1 react: specifier: ^19.1.1 version: 19.1.1 @@ -68,19 +68,19 @@ catalogs: version: 19.1.1 tailwindcss: specifier: ^3.4.15 - version: 3.4.17 + version: 3.4.15 typescript: specifier: ^5.7 - version: 5.8.3 + version: 5.7.2 vite-tsconfig-paths: specifier: ^5.1.4 version: 5.1.4 vitest: specifier: ^2.1.8 - version: 2.1.9 + version: 2.1.8 zod: specifier: ^3.24.1 - version: 3.25.71 + version: 3.24.1 importers: @@ -193,6 +193,9 @@ importers: '@nestjs/cache-manager': specifier: ^2.2.1 version: 2.3.0(@nestjs/common@10.4.20(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.20)(cache-manager@5.7.6)(rxjs@7.8.1) + '@nestjs/cli': + specifier: ^10.0.0 + version: 10.4.9 '@nestjs/common': specifier: ^10.0.0 version: 10.4.20(reflect-metadata@0.2.2)(rxjs@7.8.1) @@ -208,12 +211,24 @@ importers: '@nestjs/platform-fastify': specifier: ^10.3.3 version: 10.4.20(@nestjs/common@10.4.20(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.20) + '@nestjs/schematics': + specifier: ^10.0.0 + version: 10.2.3(chokidar@3.6.0)(typescript@5.7.2) + '@types/node': + specifier: 'catalog:' + version: 20.17.8 cache-manager: specifier: ^5.4.0 version: 5.7.6 cache-manager-ioredis: specifier: ^2.1.0 version: 2.1.0 + dotenv-cli: + specifier: 'catalog:' + version: 7.4.4 + fastify: + specifier: ^4.26.1 + version: 4.29.1 ioredis: specifier: ^5.3.2 version: 5.7.0 @@ -223,49 +238,43 @@ importers: rxjs: specifier: ^7.8.1 version: 7.8.1 + source-map-support: + specifier: ^0.5.21 + version: 0.5.21 + tsconfig-paths: + specifier: ^4.2.0 + version: 4.2.0 + typescript: + specifier: 'catalog:' + version: 5.7.2 zod: specifier: 'catalog:' version: 3.24.1 devDependencies: - '@nestjs/cli': - specifier: ^10.0.0 - version: 10.4.9 - '@nestjs/schematics': - specifier: ^10.0.0 - version: 10.2.3(chokidar@3.6.0)(typescript@5.7.2) '@nestjs/testing': specifier: ^10.0.0 version: 10.4.20(@nestjs/common@10.4.20(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.20)(@nestjs/platform-express@10.4.20) + '@repo/eslint-config': + specifier: workspace:* + version: link:../../packages/eslint-config '@repo/typescript-config': specifier: workspace:* version: link:../../packages/typescript-config '@types/jest': specifier: ^29.5.2 version: 29.5.14 - '@types/node': - specifier: 'catalog:' - version: 20.17.8 '@types/supertest': specifier: ^6.0.0 version: 6.0.3 - dotenv-cli: - specifier: 'catalog:' - version: 7.4.4 eslint: specifier: 'catalog:' version: 9.21.0(jiti@2.4.1) - fastify: - specifier: ^4.26.1 - version: 4.29.1 jest: specifier: ^29.5.0 version: 29.7.0(@types/node@20.17.8)(ts-node@10.9.2(@types/node@20.17.8)(typescript@5.7.2)) prettier: specifier: 'catalog:' version: 3.6.2 - source-map-support: - specifier: ^0.5.21 - version: 0.5.21 supertest: specifier: ^6.3.3 version: 6.3.4 @@ -278,12 +287,6 @@ importers: ts-node: specifier: ^10.9.1 version: 10.9.2(@types/node@20.17.8)(typescript@5.7.2) - tsconfig-paths: - specifier: ^4.2.0 - version: 4.2.0 - typescript: - specifier: 'catalog:' - version: 5.7.2 apps/web: dependencies: diff --git a/turbo.json b/turbo.json index ef949f2..d430a15 100644 --- a/turbo.json +++ b/turbo.json @@ -13,7 +13,10 @@ "BOT_TOKEN", "NEXTAUTH_SECRET", "BOT_URL", - "BOT_PROVIDER_TOKEN" + "BOT_PROVIDER_TOKEN", + "REDIS_HOST", + "REDIS_PORT", + "REDIS_PASSWORD" ] }, "lint": {