Changing env vars to use config service

This commit is contained in:
Collin Duncan 2023-06-28 11:26:17 +02:00
parent a4076796af
commit 962644fb3a
No known key found for this signature in database
4 changed files with 41 additions and 34 deletions

View file

@ -22,14 +22,5 @@ COPY --chown=node:node tsconfig.json tsconfig.json
RUN CXX=g++-12 npm install
ARG PORT=3000
ENV PORT=$PORT
ARG REDIS_HOST=localhost
ENV REDIS_HOST=$REDIS_HOST
ARG REDIS_PORT=6379
ENV REDIS_PORT=$REDIS_PORT
RUN npm run migrations
ENTRYPOINT ["npm", "run", "start"]

19
package-lock.json generated
View file

@ -12,7 +12,7 @@
"@nestjs/bull": "^0.6.3",
"@nestjs/cli": "^9.0.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.3.2",
"@nestjs/config": "^2.3.4",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/schedule": "^2.2.2",
@ -2014,11 +2014,11 @@
"integrity": "sha512-5svOrSA2w3iGFDs1HibEVBGbDrAY82bFQ3HZ3ixB+88nsbsWQoKqDRb5UBYAUPEzbBn6dAp5gRNXglySbx1MlA=="
},
"node_modules/@nestjs/config": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-2.3.2.tgz",
"integrity": "sha512-VtGV8PBpxzMzz68kdxTWqPm9v7SYCSZXQ0tC72AMNnjdmU+CVjUSLpEpdnm0XcWHxE1nV6wSI3HZxsATIV4ZxA==",
"version": "2.3.4",
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-2.3.4.tgz",
"integrity": "sha512-IGdSF+0F9MJO6dCRTEahdxPz4iVijjtolcFBxnY+2QYM3bXYQvAgzskGZi+WkAFJN/VzR3TEp60gN5sI74GxPA==",
"dependencies": {
"dotenv": "16.0.3",
"dotenv": "16.1.4",
"dotenv-expand": "10.0.0",
"lodash": "4.17.21",
"uuid": "9.0.0"
@ -4691,11 +4691,14 @@
}
},
"node_modules/dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
"version": "16.1.4",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz",
"integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/motdotla/dotenv?sponsor=1"
}
},
"node_modules/dotenv-expand": {

View file

@ -27,7 +27,7 @@
"@nestjs/bull": "^0.6.3",
"@nestjs/cli": "^9.0.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.3.2",
"@nestjs/config": "^2.3.4",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/schedule": "^2.2.2",

View file

@ -5,30 +5,43 @@ import { TypeOrmModule } from '@nestjs/typeorm'
import { resolve } from 'path'
import { ReservationsModule } from './reservations/module'
import { RunnerModule } from './runner/module'
import { ConfigModule } from '@nestjs/config'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { LoggerMiddleware } from './logger/middleware'
import { LoggerModule } from './logger/module'
@Module({
imports: [
TypeOrmModule.forRoot({
ConfigModule.forRoot({ isGlobal: true }),
TypeOrmModule.forRootAsync({
useFactory: (configService: ConfigService) => ({
type: 'sqlite',
database: resolve('./db/autobaan_db'),
migrations: [resolve('./database/migrations/*.ts')],
database: configService.get<string>(
'DATABASE',
resolve('./db/autobaan_db'),
),
migrations: [
configService.get<string>(
'DATABASE_MIGRATIONS',
resolve('./database/migrations/*.ts'),
),
],
autoLoadEntities: true,
logging: true,
}),
BullModule.forRoot({
}),
BullModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
redis: {
host: process.env.REDIS_HOST,
port: Number.parseInt(process.env.REDIS_PORT || '6379'),
host: configService.get<string>('REDIS_HOST', 'localhost'),
port: configService.get<number>('REDIS_PORT', 6379),
},
defaultJobOptions: {
removeOnComplete: true,
},
}),
}),
ScheduleModule.forRoot(),
ConfigModule.forRoot({ isGlobal: true }),
ReservationsModule,
RunnerModule,
LoggerModule,