add docker

This commit is contained in:
Николай Вигдоров
2025-03-04 23:43:48 +03:00
parent f54a1480b9
commit 6121847fe3
6 changed files with 30 additions and 56 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
node_modules
npm-debug.log
dist
.env
.git
.gitignore

23
Dockerfile Normal file
View File

@ -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"]

View File

@ -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>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});

View File

@ -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();

View File

@ -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!');
});
});

View File

@ -1,9 +0,0 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}