From 5865d553929cb0799d5eb784fdcc9828069ce775 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 4 Oct 2024 22:55:24 +0100 Subject: [PATCH] yes? --- backend/Dockerfile | 30 +++++++++++++++++++++++++----- backend/package.json | 2 +- backend/src/main.ts | 4 +++- common/.dockerignore | 2 ++ common/package.json | 5 ----- package.json | 8 ++++---- pnpm-lock.yaml | 2 +- pnpm-workspace.yaml | 2 +- 8 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 common/.dockerignore diff --git a/backend/Dockerfile b/backend/Dockerfile index efad558..540e751 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,17 +1,37 @@ -FROM node:20-alpine3.17 +# Stage 1: Builder +FROM node:20-alpine3.17 AS builder -# Install pnpm +# Install pnpm globally RUN npm install -g pnpm ENV PNPM_HOME=/usr/local/bin WORKDIR /app +# Copy necessary files for installation COPY package.json* pnpm-lock.yaml* pnpm-workspace.yaml* ./ +COPY common ./common COPY backend ./backend -RUN pnpm install --filter backend -RUN pnpm run build:backend +# Install dependencies for all workspaces, including backend +RUN pnpm install +# Build the backend +RUN pnpm --filter backend build + +# Stage 2: Runner +FROM node:20-alpine3.17 AS runner + +WORKDIR /app + +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/backend/dist ./dist +COPY --from=builder /app/backend/package.json ./backend/package.json + +# Install production dependencies +RUN npm install -g pnpm && pnpm install --prod + +# Expose the port your application runs on EXPOSE 8080 -CMD ["pnpm", "start:backend"] \ No newline at end of file +# Command to run your app +CMD ["node", "dist/main.js"] diff --git a/backend/package.json b/backend/package.json index 2ba3fec..242b5bc 100644 --- a/backend/package.json +++ b/backend/package.json @@ -10,6 +10,7 @@ "start": "nest start" }, "dependencies": { + "@ssr/common": "workspace:*", "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", @@ -17,7 +18,6 @@ "rxjs": "^7.8.1" }, "devDependencies": { - "@ssr/common": "workspace:*", "concurrently": "^9.0.1", "nodemon": "^2.0.20", "tsup": "^8.3.0", diff --git a/backend/src/main.ts b/backend/src/main.ts index 357442b..c801e34 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -2,7 +2,9 @@ import { NestFactory } from "@nestjs/core"; import { AppModule } from "./app.module"; async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule, { + logger: ["error", "warn"], + }); await app.listen(8080); } bootstrap(); diff --git a/common/.dockerignore b/common/.dockerignore new file mode 100644 index 0000000..76add87 --- /dev/null +++ b/common/.dockerignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/common/package.json b/common/package.json index 448d060..7d7e083 100644 --- a/common/package.json +++ b/common/package.json @@ -1,15 +1,10 @@ { "name": "@ssr/common", "version": "1.0.0", - "description": "", - "main": "index.js", "scripts": { "dev": "tsup src/index.ts --watch", "build": "tsup src/index.ts" }, - "keywords": [], - "author": "", - "license": "ISC", "devDependencies": { "tsup": "^6.5.0", "typescript": "^5" diff --git a/package.json b/package.json index c1ca6dd..1d3c6f6 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,11 @@ "scripts": { "dev": "pnpm --parallel --workspace-concurrency=4 run -r dev", - "build:website": "pnpm --filter website... build", - "build:backend": "pnpm --filter backend... build", + "build:website": "pnpm --filter website build", + "build:backend": "pnpm --filter backend build", - "start:website": "pnpm --filter website... start", - "start:backend": "pnpm --filter backend... start" + "start:website": "pnpm --filter website start", + "start:backend": "pnpm --filter backend start" }, "author": "fascinated7", "license": "MIT" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6c49132..2ca6dc4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,7 +36,7 @@ importers: specifier: ^10.0.0 version: 10.4.4(@nestjs/common@10.4.4(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.4(@nestjs/common@10.4.4(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.4)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.4(@nestjs/common@10.4.4(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.4)) '@ssr/common': - specifier: workspace:* + specifier: workspace:common version: link:../common '@types/express': specifier: ^4.17.17 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 5f6bfb8..7818e6b 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,4 +1,4 @@ packages: + - "common" - "website" - "backend" - - "common" \ No newline at end of file