diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0619be5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,45 @@ +# node_modules +node_modules +app/**/node_modules +libs/**/node_modules + +# build output +dist +app/**/dist +# libs/**/dist + +# dependency manager +.pnpm +.pnp +.pnp.js + +# git +.git +.gitignore +*.md + +# local dev configs +.vscode +.DS_Store +*.swp + +# logs +Thumbs.db +*.tmp +*.log + +# docker +Dockerfile +docker-compose.yml + +# test & coverage reports +coverage +*.test.js +*.spec.js +*.test.ts +*.spec.ts + +# env files +.env +.env.local +.env.*.local \ No newline at end of file diff --git a/.gitignore b/.gitignore index 22f55ad..99b4698 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # compiled output /dist /node_modules +**/dist +**/node_modules +**/tsconfig.tsbuildinfo # Logs logs diff --git a/apps/Dockerfile.app b/apps/Dockerfile.app new file mode 100644 index 0000000..5f75b36 --- /dev/null +++ b/apps/Dockerfile.app @@ -0,0 +1,35 @@ + +# Base Stage +FROM node:20-slim AS base + +ARG PKG_NAME +ARG PORT + +ENV PKG_NAME=$PKG_NAME +ENV PORT=$PORT +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" + +RUN corepack enable + +# Builder Stage +FROM base AS builder +WORKDIR /usr/src/app +COPY . . + +# Install dependencies: with dependency cache +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile + +# Build shared libraries & Auth application +RUN pnpm --filter "libs/*" build +RUN pnpm --filter=$PKG_NAME build + +# Remove unnecessary dependencies from production +RUN pnpm --filter=$PKG_NAME deploy --prod /prod + +# Prod Stage +FROM base AS prod +COPY --from=builder /prod /prod +WORKDIR /prod +EXPOSE $PORT +CMD [ "node", "dist/main" ] \ No newline at end of file diff --git a/apps/auth/package.json b/apps/auth/package.json new file mode 100644 index 0000000..e1331c1 --- /dev/null +++ b/apps/auth/package.json @@ -0,0 +1,12 @@ +{ + "name": "@apps/auth", + "version": "1.0.0", + "dependencies": { + "@libs/common": "workspace:*" + }, + "scripts": { + "start": "nest start", + "build": "nest build", + "test": "jest" + } +} diff --git a/apps/auth/tsconfig.json b/apps/auth/tsconfig.json new file mode 100644 index 0000000..ed464a9 --- /dev/null +++ b/apps/auth/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5db5796 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,15 @@ +version: '3.8' + +services: + auth: + image: 'hedwig/auth' + build: + context: . + dockerfile: ./apps/Dockerfile.app + args: + - PKG_NAME=@apps/auth + - PORT=3000 + container_name: auth + ports: + - '3000:3000' + restart: 'no' diff --git a/libs/common/package.json b/libs/common/package.json new file mode 100644 index 0000000..73861a9 --- /dev/null +++ b/libs/common/package.json @@ -0,0 +1,9 @@ +{ + "name": "@libs/common", + "version": "1.0.0", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "build": "tsc" + } +} diff --git a/libs/common/tsconfig.json b/libs/common/tsconfig.json new file mode 100644 index 0000000..ed464a9 --- /dev/null +++ b/libs/common/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} diff --git a/package.json b/package.json index 269d3c0..e684041 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,27 @@ { - "name": "yapp-web-2-server", + "name": "hedwig-server", "version": "0.0.1", "description": "", "author": "", "private": true, "license": "UNLICENSED", "scripts": { - "build": "nest build", + "start": "pnpm --recursive run start", + "build": "pnpm --recursive run build", + "auth": "pnpm -F @apps/auth", + "common": "pnpm -F @libs/common", "format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"", - "start": "nest start", - "start:dev": "nest start --watch", - "start:debug": "nest start --debug --watch", - "start:prod": "node dist/apps/yapp-web-2-server/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./apps/yapp-web-2-server/test/jest-e2e.json" + "test:e2e": "jest --config ./apps/hedwig-server/test/jest-e2e.json" }, + "workspaces": [ + "apps/*", + "libs/*" + ], "dependencies": { "@nestjs/common": "^10.0.0", "@nestjs/core": "^10.0.0", @@ -73,4 +76,4 @@ "^@app/common(|/.*)$": "/libs/common/src/$1" } } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4de397e..5e30877 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -88,6 +88,14 @@ importers: specifier: ^5.1.3 version: 5.4.5 + apps/auth: + dependencies: + '@libs/common': + specifier: workspace:* + version: link:../../libs/common + + libs/common: {} + packages: '@ampproject/remapping@2.3.0': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..8f80f0c --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,3 @@ +packages: + - 'apps/*' + - 'libs/*' diff --git a/tsconfig.json b/tsconfig.json index 4d730b8..fc0c74e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,12 +18,8 @@ "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false, "paths": { - "@app/common": [ - "libs/common/src" - ], - "@app/common/*": [ - "libs/common/src/*" - ] + "@libs/common/*": ["libs/common/src/*"] } - } -} \ No newline at end of file + }, + "include": ["apps/**/*", "libs/**/*"] +}