Skip to content

Commit d616742

Browse files
committed
build(backend): 👷 Deploy backend via docker
1 parent 47dcae8 commit d616742

File tree

8 files changed

+130
-32
lines changed

8 files changed

+130
-32
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules
22
dist
33
.vscode
44
*.log
5+
packages/**/dist
6+
packages/**/node_modules

.yarnrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
registry: "https://registry.yarnpkg.com"
2+
"@bcdapps:registry" "http://192.168.1.8:4873/"

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
ARG BUILD_USER=build
3+
ARG APPLICATION_USER=application
4+
ARG NODE_VERSION=12.16.1
5+
6+
FROM node:${NODE_VERSION}-alpine as os
7+
8+
ARG BUILD_USER
9+
ENV buildUser=$BUILD_USER
10+
11+
RUN addgroup -S appgroup && adduser -S $buildUser -G appgroup
12+
USER $buildUser
13+
14+
15+
16+
WORKDIR /home/$buildUser
17+
18+
FROM os AS install
19+
COPY package*.json ./
20+
ADD .yarnrc ./
21+
COPY yarn.lock ./
22+
COPY babel.config.js ./
23+
COPY patches/nestjs-flub+0.2.0.patch ./patches/nestjs-flub+0.2.0.patch
24+
RUN yarn install --only=production
25+
RUN cp -R node_modules /tmp/production_modules
26+
RUN yarn install --frozen-lockfile
27+
COPY . .
28+
29+
30+
FROM install AS build
31+
USER root
32+
WORKDIR /home/$buildUser
33+
RUN yarn build:backend
34+
35+
36+
FROM node:${NODE_VERSION}-alpine
37+
38+
ARG APPLICATION_USER
39+
ARG BUILD_USER
40+
ENV applicationUser=$APPLICATION_USER
41+
ENV buildUser=$BUILD_USER
42+
RUN apk add --update --no-cache bash
43+
RUN addgroup -S appgroup && adduser -S $applicationUser -G appgroup
44+
45+
46+
WORKDIR /home/$applicationUser
47+
48+
COPY --from=install /tmp/production_modules node_modules
49+
COPY --from=build /home/$buildUser/dist dist
50+
51+
COPY free.bcdapps.client.certificate free.bcdapps.client.certificate
52+
COPY protos protos
53+
RUN mkdir -p packages/backend/src/graphql
54+
COPY packages/backend/src/**/*.graphql packages/backend/src/graphql/
55+
56+
EXPOSE 3000
57+
CMD ["node", "dist/packages/backend/main.js"]

docker-compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: '3'
2+
services:
3+
node-server:
4+
build: ./
5+
image: node-server
6+
ports:
7+
- 5000:5000
8+
- 3001:3001
9+
environment:
10+
NODE_ENV: development
11+
DB_URI: https://a.free.bcdapps.ravendb.cloud
12+
DB_NAME: sampledatabase
13+
DB_CERTS: free.bcdapps.client.certificate/free.bcdapps.client.certificate.pfx
14+
HOST: 0.0.0.0
15+
PORT: 3001
16+
links:
17+
- verdaccio
18+
depends_on:
19+
- verdaccio
20+
networks:
21+
- backend_network
22+
envoy:
23+
build: ./docker/envoy
24+
image: envoy-grpc-backend
25+
restart: always
26+
ports:
27+
- '8080:8080'
28+
- '9901:9901'
29+
networks:
30+
- backend_network
31+
verdaccio:
32+
image: verdaccio/verdaccio:latest
33+
ports:
34+
- 4873:4873
35+
networks:
36+
- backend_network
37+
networks:
38+
backend_network:
39+
driver: 'bridge'

dockerfile.debug

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG NODE_VERSION=12.16.1
2+
3+
FROM node:${NODE_VERSION}-alpine as os
4+
RUN mkdir -p /home/application
5+
RUN chmod -R 777 /home/application
6+
WORKDIR /home/application
7+
ADD package*.json ./
8+
ADD yarn.lock ./
9+
ADD .yarnrc ./
10+
11+
COPY babel.config.js ./
12+
COPY patches/nestjs-flub+0.2.0.patch ./patches/nestjs-flub+0.2.0.patch
13+
RUN yarn install
14+
COPY . .
15+
RUN yarn build:backend
16+
17+
COPY free.bcdapps.client.certificate free.bcdapps.client.certificate
18+
19+
EXPOSE 3000
20+
CMD ["node", "dist/packages/backend/main.js"]

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,16 @@
157157
"tsdx": "^0.13.3",
158158
"typesafe-actions": "^5.1.0",
159159
"typescript": "^4.0.2",
160-
"yup": "^0.29.1"
160+
"yup": "^0.29.1",
161+
162+
"@nestjs/cli": "^7.2.0",
163+
"@nestjs/schematics": "^7.0.0",
164+
"@nestjs/testing": "^7.1.1",
165+
"@types/bunyan": "^1.8.6",
166+
"@types/node": "^14.0.6",
167+
"@types/supertest": "^2.0.9",
168+
"grpc-tools": "^1.9.1",
169+
"protobufjs": "^6.10.1"
161170
},
162171
"peerDependencies": {
163172
"babel-eslint": "^9.0.0",

packages/backend/package.json

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,5 @@
1313
"gen:typings": "ts-node src/generate-typings.ts",
1414
"typecheck": "tsc -p tsconfig.json"
1515

16-
},
17-
"dependencies": {
18-
"@grpc/proto-loader": "^0.5.5",
19-
"@nestjs/config": "^0.5.0",
20-
"@nestjs/microservices": "^7.4.2",
21-
"@nestjs/platform-express": "^7.1.1",
22-
"@types/yup": "^0.29.3",
23-
"async-exit-hook": "^2.0.1",
24-
"bunyan": "^1.8.14",
25-
"bunyan-prettystream": "^0.1.3",
26-
"class-transformer": "^0.3.1",
27-
"graphql-type-json": "^0.3.2",
28-
"grpc": "^1.24.3",
29-
"http-json-errors": "^1.2.8",
30-
"inversify": "^5.0.1",
31-
"rxjs": "^6.5.5",
32-
"yup": "^0.29.1"
33-
},
34-
"devDependencies": {
35-
"@nestjs/cli": "^7.2.0",
36-
"@nestjs/graphql": "^7.6.0",
37-
"@nestjs/schematics": "^7.0.0",
38-
"@nestjs/testing": "^7.1.1",
39-
"@types/bunyan": "^1.8.6",
40-
"@types/node": "^14.0.6",
41-
"@types/supertest": "^2.0.9",
42-
"class-validator": "^0.12.2",
43-
"envalid": "^6.0.2",
44-
"grpc-tools": "^1.9.1",
45-
"nestjs-flub": "^0.2.0",
46-
"protobufjs": "^6.10.1"
4716
}
4817
}

yarn.lock

100644100755
File mode changed.

0 commit comments

Comments
 (0)