Skip to content

Commit

Permalink
fix: make sure build arguments are correctly passed to Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-besbes committed Feb 26, 2024
1 parent 6970490 commit ea96f28
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
28 changes: 20 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# office_type: branch | head
ARG office_type
FROM node:18 as build

FROM node:18
# OFFICE_TYPE: branch | head
ARG OFFICE_TYPE
ENV OFFICE_TYPE=${OFFICE_TYPE:?}

# Set working directory
RUN mkdir app
WORKDIR app
WORKDIR /app

# Copy source code in container
COPY apps apps
Expand All @@ -21,7 +21,19 @@ RUN corepack enable
RUN yarn

# Build the app
RUN yarn build $office_type
RUN yarn build ${OFFICE_TYPE}

FROM node:18

ARG OFFICE_TYPE

# Set working directory
WORKDIR /app

COPY --from=build /app/dist dist
COPY --from=build /app/node_modules node_modules

# To avoid
RUN ln -vs dist/apps/${OFFICE_TYPE}/main.js main.js

# Run the app
CMD ["yarn", "start", "$office_type"]
CMD ["node", "main.js"]
4 changes: 2 additions & 2 deletions apps/branch/src/branch.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Logger, Module } from '@nestjs/common';
import { BranchController } from './branch.controller';
import { BranchService } from './branch.service';
import {
Expand Down Expand Up @@ -56,6 +56,6 @@ import { SyncModule } from '@sync/sync.module';
SyncModule,
],
controllers: [BranchController, ProductSalesController],
providers: [BranchService],
providers: [BranchService, Logger],
})
export class BranchModule {}
4 changes: 3 additions & 1 deletion apps/branch/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { NestFactory } from '@nestjs/core';
import { ConfigurationService } from '@config';
import { ValidationPipe } from '@nestjs/common';
import {Logger, ValidationPipe} from '@nestjs/common';
import { BaseInterceptor } from '@base';
import { BranchModule } from './branch.module';

async function bootstrap() {
const app = await NestFactory.create(BranchModule);
const configService = app.get(ConfigurationService);
const logger = app.get(Logger);

// enable validation
app.useGlobalPipes(
Expand All @@ -26,6 +27,7 @@ async function bootstrap() {
const { port } = configService.getMiscConfig();

await app.listen(port);
logger.log(`BRANCH OFFICE Listening on port ${port}`, "BootstrapFunction");
}

bootstrap();
4 changes: 2 additions & 2 deletions apps/head/src/head.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Logger, Module } from '@nestjs/common';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { HeadController } from './head.controller';
import { HeadService } from './head.service';
Expand Down Expand Up @@ -56,6 +56,6 @@ import { SyncModule } from '@sync/sync.module';
SyncModule,
],
controllers: [HeadController, ProductSalesController],
providers: [HeadService],
providers: [HeadService, Logger],
})
export class HeadModule {}
4 changes: 3 additions & 1 deletion apps/head/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { NestFactory } from '@nestjs/core';
import { ConfigurationService } from '@config';
import { ValidationPipe } from '@nestjs/common';
import {Logger, ValidationPipe} from '@nestjs/common';
import { BaseInterceptor } from '@base';
import { HeadModule } from './head.module';

async function bootstrap() {
const app = await NestFactory.create(HeadModule);
const configService = app.get(ConfigurationService);
const logger = app.get(Logger);

// enable validation
app.useGlobalPipes(
Expand All @@ -26,6 +27,7 @@ async function bootstrap() {
const { port } = configService.getMiscConfig();

await app.listen(port);
logger.log(`HEAD OFFICE Listening on port ${port}`, "BootstrapFunction");
}

bootstrap();
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
build:
context: .
args:
office_type: head
OFFICE_TYPE: head
restart: on-failure
env_file:
- apps/head/.env.example
Expand Down Expand Up @@ -76,7 +76,7 @@ services:
build:
context: .
args:
office_type: branch
OFFICE_TYPE: branch
restart: on-failure
env_file:
- apps/branch/.env.example
Expand Down

0 comments on commit ea96f28

Please sign in to comment.