From 6121847fe3d936f4e7ef13dac970d9fe2a8cbd10 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:43:48 +0300 Subject: [PATCH] add docker --- .dockerignore | 6 ++++++ Dockerfile | 23 +++++++++++++++++++++++ src/app.controller.spec.ts | 22 ---------------------- src/main.ts | 2 +- test/app.e2e-spec.ts | 24 ------------------------ test/jest-e2e.json | 9 --------- 6 files changed, 30 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 c8f10c2..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/src/main.ts b/src/main.ts index a7ed6ff..4b74724 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,6 +21,6 @@ async function bootstrap() { const document = SwaggerModule.createDocument(app, options); SwaggerModule.setup('api', app, document); - await app.listen(4003); + await app.listen(3000); } bootstrap(); diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts deleted file mode 100644 index e0081de..0000000 --- a/test/app.e2e-spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {Test, TestingModule} from '@nestjs/testing'; -import {INestApplication} from '@nestjs/common'; -import * as request from 'supertest'; -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" - } -}