Adding some changes to dockerfile to use env vars for ports and redis config

This commit is contained in:
Collin Duncan 2023-05-26 16:34:50 -05:00
parent 1def4de40c
commit 1e2933e780
No known key found for this signature in database
3 changed files with 15 additions and 2 deletions

View file

@ -3,6 +3,10 @@ services:
build: build:
context: .. context: ..
dockerfile: ./docker/server/Dockerfile dockerfile: ./docker/server/Dockerfile
args:
- PORT=3000
- REDIS_HOST=redis
- REDIS_PORT=6379
restart: always restart: always
environment: environment:
- PORT=3000 - PORT=3000

View file

@ -42,6 +42,15 @@ RUN npm run build
FROM base as app FROM base as app
ARG PORT=3000
ENV PORT=$PORT
ARG REDIS_HOST=localhost
ENV REDIS_HOST=$REDIS_HOST
ARG REDIS_PORT=6379
ENV REDIS_PORT=$REDIS_PORT
COPY --chown=node:node --from=builder /app/dist ./dist COPY --chown=node:node --from=builder /app/dist ./dist
ENTRYPOINT ["node", "./dist/main.js"] ENTRYPOINT ["node", "./dist/main.js"]

View file

@ -6,10 +6,10 @@ import { CustomResponseTransformInterceptor } from './common/customResponse'
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule, { abortOnError: false }) const app = await NestFactory.create(AppModule, { abortOnError: false })
const config = app.get(ConfigService) const config = app.get(ConfigService)
const port = config.get('PORT') const port = config.get('PORT', 3000)
app.enableShutdownHooks() app.enableShutdownHooks()
app.useGlobalInterceptors(new CustomResponseTransformInterceptor()) app.useGlobalInterceptors(new CustomResponseTransformInterceptor())
await app.listen(port) await app.listen(port, () => console.log(`Listening on port ${port}`))
} }
bootstrap() bootstrap()