Skip to content

Commit

Permalink
build: update docker build for auth service #41
Browse files Browse the repository at this point in the history
Update docker compose, Dockerfile, and package, for the auth service build.
  • Loading branch information
ckng0221 authored Feb 2, 2024
2 parents c71309f + 045f2d5 commit 930ccd4
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apps/Dockerfile.apigateway
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY . .
RUN turbo prune ${service} --docker

# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
FROM base AS development
ARG service

WORKDIR /app
Expand Down Expand Up @@ -40,7 +40,7 @@ RUN npm install --omit=dev --workspace=${service}

# COPY . .

COPY --from=installer /app/dist/apps/${service} ./dist
COPY --from=development /app/dist/apps/${service} ./dist

CMD ["node", "dist/server.js"]

Expand Down
1 change: 1 addition & 0 deletions apps/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/morgan": "^1.9.9",
Expand Down
7 changes: 7 additions & 0 deletions apps/auth/src/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Post,
Expand All @@ -14,6 +15,12 @@ import { AuthDto, VerificationDto } from './dto/auth.dto';
export class AuthController {
constructor(private authService: AuthService) {}

@HttpCode(HttpStatus.OK)
@Get('')
healthCheck() {
return 'Auth ok';
}

@HttpCode(HttpStatus.OK)
@Post('login')
signIn(@Body() signInDto: AuthDto) {
Expand Down
2 changes: 1 addition & 1 deletion apps/auth/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document, { customSiteTitle: 'Auth' });

const PORT = process.env.PORT || 8001;
const PORT = process.env.PORT || 8005;
const loggingMode =
process.env.NODE_ENV === 'production' ? 'combined' : 'dev';
app.use(morgan(loggingMode));
Expand Down
31 changes: 29 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
environment:
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-book
- RABBIT_MQ_URI=amqp://rabbitmq:5672
- BASEURL_AUTH=http://auth:8005
depends_on:
- mongodb
- rabbitmq
Expand All @@ -35,6 +36,7 @@ services:
- ./apps/customer/.env
environment:
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-customer
- BASEURL_AUTH=http://auth:8005
depends_on:
- mongodb
# ports:
Expand All @@ -55,6 +57,7 @@ services:
environment:
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-borrowing
- RABBIT_MQ_URI=amqp://rabbitmq:5672
- BASEURL_AUTH=http://auth:8005
depends_on:
- mongodb
- rabbitmq
Expand All @@ -77,6 +80,7 @@ services:
environment:
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-payment
- RABBIT_MQ_URI=amqp://rabbitmq:5672
- BASEURL_AUTH=http://auth:8005
depends_on:
- mongodb
- rabbitmq
Expand All @@ -87,6 +91,28 @@ services:
links:
- mongodb
- rabbitmq
auth:
build:
context: .
dockerfile: ./apps/Dockerfile.service
target: production
args:
service: auth
env_file:
- ./apps/auth/.env
depends_on:
- mongodb
# ports:
# - '8005:8005'
networks:
- node-network
links:
- book
- customer
- borrowing
- payment
environment:
- BASEURL_CUSTOMER=http://customer:8002
notification:
build:
context: .
Expand Down Expand Up @@ -119,6 +145,7 @@ services:
- customer
- borrowing
- payment
- auth
- notification
ports:
- '8000:8000'
Expand All @@ -133,8 +160,6 @@ services:
service: apigateway
env_file:
- ./apps/apigateway/.env
depends_on:
- view
ports:
- '8080:8080'
networks:
Expand All @@ -144,11 +169,13 @@ services:
- customer
- borrowing
- payment
- auth
environment:
- BASEURL_BOOK=http://book:8001
- BASEURL_CUSTOMER=http://customer:8002
- BASEURL_BORROWING=http://borrowing:8003
- BASEURL_PAYMENT=http://payment:8004
- BASEURL_AUTH=http://auth:8005

# Dependencies
rabbitmq:
Expand Down
38 changes: 34 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
environment:
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-book
- RABBIT_MQ_URI=amqp://rabbitmq:5672
- BASEURL_AUTH=http://auth:8005
depends_on:
- mongodb
- rabbitmq
Expand All @@ -40,6 +41,7 @@ services:
- ./apps/customer/.env
environment:
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-customer
- BASEURL_AUTH=http://auth:8005
depends_on:
- mongodb
volumes:
Expand All @@ -65,6 +67,7 @@ services:
environment:
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-borrowing
- RABBIT_MQ_URI=amqp://rabbitmq:5672
- BASEURL_AUTH=http://auth:8005
depends_on:
- mongodb
- rabbitmq
Expand Down Expand Up @@ -92,6 +95,7 @@ services:
environment:
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-payment
- RABBIT_MQ_URI=amqp://rabbitmq:5672
- BASEURL_AUTH=http://auth:8005
depends_on:
- mongodb
- rabbitmq
Expand All @@ -105,6 +109,30 @@ services:
links:
- mongodb
- rabbitmq
auth:
image: libraryapp-dev-auth
build:
context: .
dockerfile: ./apps/Dockerfile.service
target: development
args:
service: auth
env_file:
- ./apps/auth/.env
depends_on:
- mongodb
ports:
- '8005:8005'
networks:
- node-network
links:
- book
- customer
- borrowing
- payment
command: npm run start:dev auth
environment:
- BASEURL_CUSTOMER=http://customer:8002
notification:
image: libraryapp-dev-notification
build:
Expand All @@ -123,8 +151,8 @@ services:
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- '8005:8005'
# ports:
# - '8005:8005'
networks:
- node-network
links:
Expand All @@ -145,6 +173,7 @@ services:
- customer
- borrowing
- payment
- auth
- notification
volumes:
- .:/usr/src/app
Expand All @@ -165,8 +194,6 @@ services:
command: npm run dev:apigateway
env_file:
- ./apps/apigateway/.env
depends_on:
- view
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
Expand All @@ -179,11 +206,14 @@ services:
- customer
- borrowing
- payment
- auth
environment:
- NODE_ENV=development
- BASEURL_BOOK=http://book:8001
- BASEURL_CUSTOMER=http://customer:8002
- BASEURL_BORROWING=http://borrowing:8003
- BASEURL_PAYMENT=http://payment:8004
- BASEURL_AUTH=http://auth:8005

# Dependencies
rabbitmq:
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 930ccd4

Please sign in to comment.