From 80056903c6666e4627cec4fa8218fa300939111b Mon Sep 17 00:00:00 2001 From: Anthony Mineo Date: Mon, 31 Aug 2020 17:12:04 -0400 Subject: [PATCH] Set API https --- app/api/src/main.ts | 11 +++++++++-- build/api/Dockerfile | 8 ++++---- docker-compose.yml | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/api/src/main.ts b/app/api/src/main.ts index 94d3ee4..1b4ab33 100644 --- a/app/api/src/main.ts +++ b/app/api/src/main.ts @@ -1,3 +1,4 @@ +import * as fs from 'fs'; import { NestFactory } from '@nestjs/core'; import { ValidationPipe } from '@nestjs/common'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; @@ -5,7 +6,13 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { AppModule } from './app.module'; async function bootstrap() { - const app = await NestFactory.create(AppModule); + // Use local gen'd cert in container + const httpsOptions = { + key: fs.readFileSync('/localcert/key.pem', 'utf8'), + cert: fs.readFileSync('/localcert/cert.pem', 'utf8') + }; + + const app = await NestFactory.create(AppModule, { httpsOptions }); app.enableCors({ credentials: true @@ -33,6 +40,6 @@ async function bootstrap() { const document = SwaggerModule.createDocument(app, swaggerOptions); SwaggerModule.setup('docs', app, document); - await app.listen(8080); + await app.listen(8443); } bootstrap(); diff --git a/build/api/Dockerfile b/build/api/Dockerfile index 4e97e3a..8c88507 100644 --- a/build/api/Dockerfile +++ b/build/api/Dockerfile @@ -23,7 +23,7 @@ RUN apk update && apk add --no-cache openssl bash curl # Default envs as prod ENV HOST=0.0.0.0 \ - PORT=8080 \ + PORT=8443 \ NODE_ENV=production \ APP_NAME=NestJS @@ -42,7 +42,7 @@ WORKDIR /opt/node_app #USER node # Generate a localhost cert -# RUN openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /localcert/key.pem -out /localcert/cert.pem -subj "/C=US/ST=New Jersey/L=Warren/O=localhost/OU=IT/CN=127.0.0.1" +RUN openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /localcert/key.pem -out /localcert/cert.pem -subj "/C=US/ST=New Jersey/L=Warren/O=localhost/OU=IT/CN=127.0.0.1" ENV PATH /opt/node_app/node_modules/.bin:$PATH @@ -62,9 +62,9 @@ COPY ./app/api/package.json ./app/api/package-lock.json* ./ COPY ./build/api/ecosystem._PROD_.config.js /opt/node_app/ecosystem._PROD_.config.js COPY ./build/api/entrypoint.sh /entrypoint.sh -EXPOSE 8080 +EXPOSE 8080 8443 HEALTHCHECK --interval=20s --timeout=30s --start-period=5s --retries=5 \ - CMD curl -f -k http://localhost:8080/ || exit 1 + CMD curl -f -k https://localhost:8443/ || exit 1 ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 96fca0c..dd5080c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,7 +44,7 @@ services: replicas: 1 api: - image: "amineo/t2-stats-api:v0.0.2" + image: "amineo/t2-stats-api:v0.0.3" build: context: . dockerfile: ./build/api/Dockerfile