Skip to content

Commit

Permalink
docker compose setup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Sep 5, 2024
1 parent 4b1a3a4 commit b2c661a
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 8 deletions.
3 changes: 1 addition & 2 deletions api/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"collection": "@nestjs/schematics",
"compilerOptions": {
"deleteOutDir": true
},
"entryFile": "api/src/main"
}
}
6 changes: 5 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.2",
"pg": "^8.12.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
"rxjs": "^7.8.1",
"typeorm": "^0.3.20"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
Expand Down
34 changes: 33 additions & 1 deletion api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { join } from 'path';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as process from 'node:process';

@Module({
imports: [],
imports: [
ConfigModule.forRoot({
isGlobal: true,
cache: true,
envFilePath: [
join(__dirname, `../../shared/config/.env.${process.env.NODE_ENV}`),
join(__dirname, '../../shared/config/.env'),
],
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
// TODO: Move this to config service method
useFactory: (configService: ConfigService) => ({
type: 'postgres',
host: configService.get('DB_HOST'),
port: configService.get('DB_PORT'),
username: configService.get('DB_USERNAME'),
password: configService.get('DB_PASSWORD'),
database: configService.get('DB_NAME'),
entities: [join(__dirname, '**', '*.entity.{ts,js}')],
synchronize: true,
ssl:
process.env.NODE_ENV === 'production'
? { require: true, rejectUnauthorized: false }
: false,
}),
inject: [ConfigService],
}),
],
controllers: [AppController],
providers: [AppService],
})
Expand Down
5 changes: 5 additions & 0 deletions api/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import * as process from 'node:process';

@Injectable()
export class AppService {
constructor(private config: ConfigService) {}
getHello(): string {
console.log(this.config.get('JWT_SECRET'));
console.log('process', process.env.JWT_SECRET);
return 'Hello Blue Coast Carbon Tool!';
}
}
15 changes: 11 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ version: '3.8'

services:
api:
container_name: blue-carbon-cost-api
environment:
DB_HOST: database
build:
context: .
dockerfile: api/Dockerfile
ports:
- "4000:4000"
env_file:
- ./shared/config/.env
command: ["pnpm", "api:dev"]
networks:
- 4-growth-docker-network
depends_on:
- database

client:
build:
Expand All @@ -26,11 +32,12 @@ services:
- 4-growth-docker-network

database:
image: postgres:13
image: postgres:16
container_name: blue-carbon-cost-db
environment:
POSTGRES_USER: blue-carbon-coast
POSTGRES_PASSWORD: blue-carbon-coast
POSTGRES_DB: blue-carbon-coast
POSTGRES_USER: blue-carbon-cost
POSTGRES_PASSWORD: blue-carbon-cost
POSTGRES_DB: blc
ports:
- "5432:5432"
networks:
Expand Down
Loading

0 comments on commit b2c661a

Please sign in to comment.