From 1c3dc15c52818789ef74b6909e095fe5decb9db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=92=D0=B8?= =?UTF-8?q?=D0=B3=D0=B4=D0=BE=D1=80=D0=BE=D0=B2?= Date: Tue, 4 Mar 2025 23:46:40 +0300 Subject: [PATCH] add docker --- .dockerignore | 6 ++++++ Dockerfile | 23 +++++++++++++++++++++++ src/app.controller.spec.ts | 22 ---------------------- test/app.e2e-spec.ts | 25 ------------------------- test/jest-e2e.json | 9 --------- 5 files changed, 29 insertions(+), 56 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile delete mode 100644 src/app.controller.spec.ts delete mode 100644 test/app.e2e-spec.ts delete mode 100644 test/jest-e2e.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..631c59c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +npm-debug.log +dist +.env +.git +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b5137c9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Этап сборки +FROM node:18-alpine AS build +WORKDIR /app +COPY package*.json ./ +RUN npm ci +COPY . . +RUN npm run build + +# Этап продакшна +FROM node:18-alpine +WORKDIR /app +COPY --from=build /app/package*.json ./ +COPY --from=build /app/dist ./dist +RUN npm ci --only=production + +# Переменные окружения +ENV NODE_ENV production + +# Пользователь без привилегий для безопасности +USER node + +EXPOSE 3000 +CMD ["node", "dist/main"] \ No newline at end of file diff --git a/src/app.controller.spec.ts b/src/app.controller.spec.ts deleted file mode 100644 index d22f389..0000000 --- a/src/app.controller.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; - -describe('AppController', () => { - let appController: AppController; - - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); - - appController = app.get(AppController); - }); - - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); - }); -}); diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts deleted file mode 100644 index 4df6580..0000000 --- a/test/app.e2e-spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; -import * as request from 'supertest'; -import { App } from 'supertest/types'; -import { AppModule } from './../src/app.module'; - -describe('AppController (e2e)', () => { - let app: INestApplication; - - beforeEach(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication(); - await app.init(); - }); - - it('/ (GET)', () => { - return request(app.getHttpServer()) - .get('/') - .expect(200) - .expect('Hello World!'); - }); -}); diff --git a/test/jest-e2e.json b/test/jest-e2e.json deleted file mode 100644 index e9d912f..0000000 --- a/test/jest-e2e.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "moduleFileExtensions": ["js", "json", "ts"], - "rootDir": ".", - "testEnvironment": "node", - "testRegex": ".e2e-spec.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - } -}