Skip to content

Commit 0971a56

Browse files
refactor(dockerfile): split multi-stage docker on 2 files to improve docker build time
1 parent 7e18f99 commit 0971a56

File tree

8 files changed

+48
-41
lines changed

8 files changed

+48
-41
lines changed

.github/CONTRIBUTING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ Você pode contribuir de várias maneiras, sendo as mais conhecidas as seguintes
5555
É preciso ter os seguintes programas instalados:
5656

5757
- [Git](https://git-scm.com/downloads)
58-
- [Node.js](https://nodejs.org/pt-br/download/)
58+
- [Node.js](https://nodejs.org/pt-br/download/) _(opcional)_
59+
- Se usar docker não será preciso instalar o Node
5960
- [Docker](https://www.docker.com/get-started)
6061
- [Docker-compose](https://docs.docker.com/compose/install/)
6162

@@ -75,7 +76,7 @@ make run-dev
7576

7677
1. [Fork](https://help.github.com/articles/fork-a-repo/) este repositório para sua própria conta GitHub, [clone](https://help.github.com/articles/cloning-a-repository/) no seu computador e, em seguida, acesse o diretório criado;
7778
1. Faça as alterações necessárias;
78-
1. Faça o seu commit usando `npm run commit`
79+
1. Faça o seu commit usando `npm run commit` _(opcional)_
7980
1. Envie um [pull request](https://help.github.com/articles/about-pull-requests/);
8081
1. Aguarde o resultado das validações realizadas na integração contínua. Caso haja alguma quebra, analise e faça as correções necessárias.
8182

@@ -163,7 +164,7 @@ Execute `npm run commit` para ter um painel interativo que permite seguir o padr
163164
164165
## 💥 Dockerfile lint
165166

166-
É utilizado o linter [Hadolint - Haskell Dockerfile Linter](https://github.com/hadolint/hadolint) para garantir que o [Dockerfile](../Dockerfile) segue as melhores práticas em sua estrutura.
167+
É utilizado o linter [Hadolint - Haskell Dockerfile Linter](https://github.com/hadolint/hadolint) para garantir que os Dockerfile de [produção](../Dockerfile), [desenvolvimento, teste](../Dockerfile.dev) e de [teste de infra](../Dockerfile) seguem as melhores práticas em sua estrutura.
167168

168169
---
169170

.github/workflows/continuous_delivery.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ jobs:
4242
steps:
4343
- name: Project checkout
4444
uses: actions/checkout@v2
45-
- name: Validate production and dev dockerfile (Dockerfile)
45+
- name: Validate production dockerfile (Dockerfile)
4646
run: docker run --rm -i hadolint/hadolint < Dockerfile
47+
- name: Validate dev dockerfile (Dockerfile.dev)
48+
run: docker run --rm -i hadolint/hadolint < Dockerfile.dev
4749
- name: Validate terratest dockerfile (Dockerfile.terratest)
4850
run: docker run --rm -i hadolint/hadolint < Dockerfile.terratest
4951

.github/workflows/continuous_integration.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ jobs:
5252
steps:
5353
- name: Project checkout
5454
uses: actions/checkout@v2
55-
- name: Validate production and dev dockerfile (Dockerfile)
55+
- name: Validate production dockerfile (Dockerfile)
5656
run: docker run --rm -i hadolint/hadolint < Dockerfile
57+
- name: Validate dev dockerfile (Dockerfile.dev)
58+
run: docker run --rm -i hadolint/hadolint < Dockerfile.dev
5759
- name: Validate terratest dockerfile (Dockerfile.terratest)
5860
run: docker run --rm -i hadolint/hadolint < Dockerfile.terratest
5961

.releaserc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module.exports = {
107107
]
108108
}],
109109
['@semantic-release/exec', {
110-
prepareCmd: 'docker build -t paulogoncalvesbh/serverest --target prod .'
110+
prepareCmd: 'make build'
111111
}],
112112
['semantic-release-docker', {
113113
name: 'paulogoncalvesbh/serverest'

Dockerfile

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM node:lts-alpine3.12@sha256:60ef0bed1dc2ec835cfe3c4226d074fdfaba571fd619c280474cc04e93f0ec5b as base
22

3+
# Production dockerfile
4+
35
LABEL repository="https://github.com/ServeRest/ServeRest" \
46
homepage="https://github.com/ServeRest/ServeRest" \
57
maintainer="Paulo Gonçalves <https://www.linkedin.com/in/paulo-goncalves/>"
@@ -8,38 +10,6 @@ WORKDIR /app
810

911
COPY package*.json ./
1012

11-
FROM base as test
12-
13-
ENV NODE_ENV=serverest-test
14-
15-
# hadolint ignore=DL3018
16-
RUN apk --no-cache add git ca-certificates wget=1.21.1-r1 bash \
17-
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
18-
&& wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \
19-
&& apk --no-cache add glibc-2.29-r0.apk \
20-
&& rm -rf /var/cache/apk/*
21-
22-
# hadolint ignore=DL3059
23-
RUN npm ci
24-
25-
COPY . .
26-
27-
FROM base as dev
28-
29-
ENV NODE_ENV=serverest-development
30-
ENV USERNAME='docker'
31-
ENV TERM=xterm-256color
32-
33-
RUN npm ci
34-
35-
COPY . .
36-
37-
EXPOSE 3000
38-
39-
CMD [ "npm", "run", "dev" ]
40-
41-
FROM base as prod
42-
4313
RUN npm ci --production --ignore-scripts
4414

4515
COPY . .

Dockerfile.dev

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM node:lts-alpine3.12@sha256:60ef0bed1dc2ec835cfe3c4226d074fdfaba571fd619c280474cc04e93f0ec5b as base
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
7+
RUN npm ci
8+
9+
COPY . .
10+
11+
FROM base as test
12+
13+
ENV NODE_ENV=serverest-test
14+
15+
# hadolint ignore=DL3018
16+
RUN apk --no-cache add git ca-certificates wget=1.21.1-r1 bash \
17+
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
18+
&& wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \
19+
&& apk --no-cache add glibc-2.29-r0.apk \
20+
&& rm -rf /var/cache/apk/*
21+
22+
FROM base as dev
23+
24+
ENV NODE_ENV=serverest-development
25+
ENV USERNAME='docker'
26+
ENV TERM=xterm-256color
27+
28+
EXPOSE 3000
29+
30+
CMD [ "npm", "run", "dev" ]

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
.PHONY: build run stop clean run-dev test-contract test test-unit test-integration test-mutation-diff test-mutation test-infra
22
# serverest
33

4-
NAME_IMAGE=serverest/serverest
4+
NAME_IMAGE=paulogoncalvesbh/serverest
55
HOST_PORT=3000
66

77
# COMANDOS PARA USAR A IMAGEM DE PRODUÇÃO \/
88

99
default: build run
1010

1111
build:
12-
@DOCKER_BUILDKIT=1 docker build -t ${NAME_IMAGE} --target prod .
12+
@DOCKER_BUILDKIT=1 docker build --file Dockerfile --tag ${NAME_IMAGE} .
1313

1414
run:
1515
@docker run -p ${HOST_PORT}:3000 ${NAME_IMAGE}

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ services:
44
base:
55
build:
66
context: .
7+
dockerfile: Dockerfile.dev
78
target: test
89
volumes:
910
- ./test:/app/test
1011

1112
run-dev:
1213
build:
1314
context: .
15+
dockerfile: Dockerfile.dev
1416
target: dev
1517
volumes:
1618
- .:/app
@@ -42,7 +44,7 @@ services:
4244
run-app-e2e:
4345
build:
4446
context: .
45-
target: prod
47+
dockerfile: Dockerfile
4648
environment:
4749
NODE_ENV: 'serverest-development'
4850

0 commit comments

Comments
 (0)