Skip to content

Commit bd90fb5

Browse files
committedNov 24, 2021
chore: change docker config
1 parent c8b9585 commit bd90fb5

7 files changed

+90
-30
lines changed
 

‎.docker/entrypoint.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
cd /usr/src/app
3+
cd /home/node/app
44

55
yarn db:deploy
6-
yarn start:prod
6+
dumb-init node dist/main.js

‎.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ node_modules
33
dist
44
*.tsbuildinfo
55
coverage
6+
coverage-e2e
67
.dockerignore
78
Dockerfile
89
.git
910
.gitignore
1011
./test
12+
docker-compose*
13+
.docker/.yarn-cache

‎Dockerfile

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1-
FROM node:12
2-
3-
WORKDIR /usr/src/app
4-
1+
FROM node:14-alpine AS build
2+
WORKDIR /var/app
53
COPY package.json yarn.lock ./
6-
7-
RUN yarn
8-
4+
RUN yarn install --frozen-lockfile
95
COPY . .
6+
RUN yarn prisma:generate && \
7+
yarn build
8+
COPY src/i18n dist/i18n
109

11-
RUN yarn prisma:generate
12-
13-
RUN yarn build
14-
15-
EXPOSE 7100
16-
17-
ENTRYPOINT [ "sh", "./.docker/entrypoint.sh" ]
10+
FROM node:14-alpine AS dependencies
11+
WORKDIR /var/app
12+
COPY package.json yarn.lock ./
13+
RUN yarn install --production=true --frozen-lockfile
14+
COPY --from=build /var/app/node_modules/.prisma /var/app/node_modules/.prisma
15+
COPY --from=build /var/app/node_modules/prisma /var/app/node_modules/prisma
16+
17+
FROM node:14-alpine AS runtime
18+
ARG VERSION="1.0.0"
19+
ENV VERSION $VERSION
20+
ENV NODE_ENV production
21+
ENV TZ America/Sao_Paulo
22+
RUN apk add dumb-init
23+
USER node
24+
EXPOSE 4000
25+
COPY --chown=node:node --from=dependencies /var/app/node_modules /home/node/app/node_modules/
26+
COPY .docker/entrypoint.sh /home/node/app
27+
COPY prisma /home/node/app/prisma
28+
COPY package.json /home/node/app/package.json
29+
COPY --chown=node:node --from=build /var/app/dist /home/node/app/dist/
30+
31+
ENTRYPOINT [ "sh", "/home/node/app/entrypoint.sh" ]

‎Dockerfile.dev

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
FROM node:12.14-alpine3.11
2-
3-
RUN apk add --no-cache bash
4-
5-
RUN touch /root/.bashrc | echo "PS1='\w\$ '" >> /root/.bashrc
1+
FROM node:14-alpine
62

73
WORKDIR /usr/src/app
84

9-
EXPOSE 7100
5+
COPY . .
6+
7+
EXPOSE 4000
108

119
ENTRYPOINT [ "sh", "./.docker/entrypoint.dev.sh" ]

‎docker-compose-dev.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: '3.7'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile.dev
8+
container_name: template-api-dev
9+
image: template-api-dev
10+
platform: linux/amd64
11+
ports:
12+
- '4000:4000'
13+
volumes:
14+
- .:/usr/src/app
15+
networks:
16+
- 'app-network'
17+
depends_on:
18+
- db
19+
environment:
20+
- DATABASE_URL=postgresql://postgres:postgres@db:5432/template-api?schema=public
21+
22+
db:
23+
image: postgres:latest
24+
restart: unless-stopped
25+
volumes:
26+
- postgres-data:/var/lib/postgresql/data
27+
ports:
28+
- '5435:5432'
29+
environment:
30+
POSTGRES_PASSWORD: postgres
31+
POSTGRES_USER: postgres
32+
POSTGRES_DB: postgres
33+
networks:
34+
- 'app-network'
35+
36+
networks:
37+
app-network:
38+
driver: bridge
39+
40+
volumes:
41+
postgres-data:

‎docker-compose-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3'
1+
version: '3.7'
22

33
services:
44
test_db:

‎docker-compose.yml

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
version: '3'
1+
version: '3.7'
22

33
services:
44
app:
55
build:
66
context: .
7-
dockerfile: Dockerfile.dev
8-
entrypoint: ./.docker/entrypoint.dev.sh
9-
container_name: template-app
7+
dockerfile: Dockerfile
8+
container_name: template-api
9+
image: template-api
10+
# Uncomment this line in case you are in M1
11+
# platform: linux/amd64
1012
ports:
11-
- '7100:7100'
12-
volumes:
13-
- .:/usr/src/app
13+
- '4000:4000'
1414
networks:
1515
- 'app-network'
1616
depends_on:
1717
- db
18+
environment:
19+
- NODE_ENV=development
20+
- PORT=4000
21+
- DATABASE_URL=postgresql://postgres:postgres@db:5432/template-api?schema=public
1822

1923
db:
2024
image: postgres:latest

0 commit comments

Comments
 (0)
Please sign in to comment.