Skip to content

Commit

Permalink
build,pref: optimise docker build and rearrange package build depende…
Browse files Browse the repository at this point in the history
…ncies
  • Loading branch information
ckng0221 committed Jan 5, 2024
1 parent 1cf3903 commit cebdaf4
Show file tree
Hide file tree
Showing 12 changed files with 603 additions and 78 deletions.
9 changes: 4 additions & 5 deletions apps/Dockerfile.apigateway
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY apps/${service}/package*.json ./

WORKDIR /usr/src/app

RUN npm install
RUN npm install --workspace=${service}

COPY . .

Expand All @@ -24,7 +24,6 @@ FROM node:alpine as production
ARG service
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
ENV SERVICE ${service}

WORKDIR /usr/src/app

Expand All @@ -36,14 +35,14 @@ COPY apps/${service}/package*.json ./

WORKDIR /usr/src/app

RUN npm install --omit=dev
RUN npm install --omit=dev --workspace=${service}
# RUN echo ${service}

# COPY . .

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

CMD node dist/apps/$SERVICE/server.js
CMD ["node", "dist/server.js"]

# docker build --build-arg="service=apigateway" -f ./apps/Dockerfile.apigateway . -t libraryapp-apigateway
# docker run -p 8080:8080 libraryapp/apigateway
25 changes: 20 additions & 5 deletions apps/Dockerfile.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install
WORKDIR /usr/src/app/apps/${service}

COPY apps/${service}/package*.json ./

WORKDIR /usr/src/app

RUN npm install --workspace=${service}

COPY . .

Expand All @@ -17,16 +23,25 @@ FROM node:alpine as production
ARG service
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
ENV SERVICE ${service}

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --omit=dev
WORKDIR /usr/src/app/apps/${service}

COPY apps/${service}/package*.json ./

WORKDIR /usr/src/app

RUN npm install --omit=dev --workspace=${service}
# RUN echo ${service}

# COPY . .

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

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

CMD node dist/apps/$SERVICE/main
# docker build --build-arg="service=apigateway" -f ./apps/Dockerfile.apigateway . -t libraryapp-apigateway
# docker run -p 8080:8080 libraryapp/apigateway
21 changes: 18 additions & 3 deletions apps/Dockerfile.view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ WORKDIR /usr/src/app

COPY package*.json ./

WORKDIR /usr/src/app/apps/ui
WORKDIR /usr/src/app/apps/${service}
COPY apps/${service}/package*.json ./

WORKDIR /usr/src/app/apps/ui
COPY apps/ui/package*.json ./

WORKDIR /usr/src/app/packages/common
COPY packages/common/package*.json ./

WORKDIR /usr/src/app

RUN npm install
RUN npm install --workspace=${service}
RUN npm install --workspace=@repo/common
RUN npm install --workspace=ui

COPY . .

Expand All @@ -31,10 +38,18 @@ WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --omit=dev
WORKDIR /usr/src/app/apps/${service}

COPY apps/${service}/package*.json ./

WORKDIR /usr/src/app

RUN npm install --omit=dev --workspace=${service}

# COPY . .

# NOTE: keep the app folder name, as will be serving dist/ui/index.html
COPY --from=development /usr/src/app/dist ./dist

# Execute from this workdir, as shared for both ui and view
CMD node dist/apps/$SERVICE/main
2 changes: 2 additions & 0 deletions apps/apigateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/cors": "^2.8.17",
"@types/morgan": "^1.9.9",
"jest": "^29.7.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-node-dev": "^2.0.0",
"turbo": "^1.11.2",
"typescript": "^5.3.3"
}
}
48 changes: 48 additions & 0 deletions apps/book/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,53 @@
"start:prod": "cd ../.. && node dist/apps/book/main",
"dev": "cd ../.. && npm run start:dev book",
"build": "cd ../.. && npm run build book"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/microservices": "^10.2.10",
"@nestjs/mongoose": "^10.0.2",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.3.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/swagger": "^7.1.15",
"@nestjs/websockets": "^10.3.0",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.3",
"class-validator": "^0.14.0",
"joi": "^17.11.0",
"mongoose": "^8.0.0",
"morgan": "^1.10.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@golevelup/nestjs-rabbitmq": "^4.1.0",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.5",
"mongodb-memory-server": "^9.1.1",
"prettier": "^3.0.0",
"react-router-dom": "^6.20.1",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"turbo": "^1.11.2",
"typescript": "^5.1.3"
}
}
48 changes: 48 additions & 0 deletions apps/borrowing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,53 @@
"start:prod": "cd ../.. && node dist/apps/borrowing/main",
"dev": "cd ../.. && npm run start:dev borrowing",
"build": "cd ../.. && npm run build borrowing"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/microservices": "^10.2.10",
"@nestjs/mongoose": "^10.0.2",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.3.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/swagger": "^7.1.15",
"@nestjs/websockets": "^10.3.0",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.3",
"class-validator": "^0.14.0",
"joi": "^17.11.0",
"mongoose": "^8.0.0",
"morgan": "^1.10.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@golevelup/nestjs-rabbitmq": "^4.1.0",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.5",
"mongodb-memory-server": "^9.1.1",
"prettier": "^3.0.0",
"react-router-dom": "^6.20.1",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"turbo": "^1.11.2",
"typescript": "^5.1.3"
}
}
48 changes: 48 additions & 0 deletions apps/customer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,53 @@
"start:prod": "cd ../.. && node dist/apps/customer/main",
"dev": "cd ../.. && npm run start:dev customer",
"build": "cd ../.. && npm run build customer"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/microservices": "^10.2.10",
"@nestjs/mongoose": "^10.0.2",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.3.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/swagger": "^7.1.15",
"@nestjs/websockets": "^10.3.0",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.3",
"class-validator": "^0.14.0",
"joi": "^17.11.0",
"mongoose": "^8.0.0",
"morgan": "^1.10.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@golevelup/nestjs-rabbitmq": "^4.1.0",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.5",
"mongodb-memory-server": "^9.1.1",
"prettier": "^3.0.0",
"react-router-dom": "^6.20.1",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"turbo": "^1.11.2",
"typescript": "^5.1.3"
}
}
48 changes: 48 additions & 0 deletions apps/notification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,53 @@
"start:prod": "cd ../.. && node dist/apps/notification/main",
"dev": "cd ../.. && npm run start:dev notification",
"build": "cd ../.. && npm run build notification"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/microservices": "^10.2.10",
"@nestjs/mongoose": "^10.0.2",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.3.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/swagger": "^7.1.15",
"@nestjs/websockets": "^10.3.0",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.3",
"class-validator": "^0.14.0",
"joi": "^17.11.0",
"mongoose": "^8.0.0",
"morgan": "^1.10.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@golevelup/nestjs-rabbitmq": "^4.1.0",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.5",
"mongodb-memory-server": "^9.1.1",
"prettier": "^3.0.0",
"react-router-dom": "^6.20.1",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"turbo": "^1.11.2",
"typescript": "^5.1.3"
}
}
Loading

0 comments on commit cebdaf4

Please sign in to comment.