Skip to content

Commit ba1e6c8

Browse files
committed
Add multistage Dockerfile documentation
1 parent f222aa6 commit ba1e6c8

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,20 @@ Locally:
8282
* `make generate-proto`: Generates grpcio python stubs from `.proto` files in `grpc_app/proto` directory
8383
* `make check`: Run tests, code style and lint checks
8484
* `make fix`: Run tests, code style and lint checks with automatic fixes (where possible)
85+
86+
## Multistage dockerfile configuration
87+
88+
Python docker image tend to become large after installing the application requirements
89+
(the slim base is ~150 MB uncompressed), therefore it's important to spend efforts
90+
to minimise the image size, even if it produces a slightly more complex multistage
91+
Dockerfile.
92+
93+
The following setup makes sure the production image will keep to a minimal size ("only" 390MB):
94+
* 150MB base image
95+
* 165MB python installed dependencies
96+
* 73MB poetry + updated pip
97+
98+
Using the following pipeline the "test" image is instead ~850MB, more than 400MB that would
99+
end up as a cost in traffic on each image pull.
100+
101+
![](docker-container.png)

docker-container.png

75.6 KB
Loading

docker-container.puml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
@startuml
2+
usecase base [
3+
=Base
4+
----
5+
""Contains system runtime ""
6+
""libraries necessary to run""
7+
""all the applications""
8+
""(e.g. libmysql)""
9+
]
10+
usecase base_builder [
11+
=Base Builder
12+
----
13+
""Contains system libraries""
14+
""necessary to build python""
15+
""dependencies""
16+
""(e.g. gcc, library headers)""
17+
]
18+
usecase test [
19+
=Test
20+
----
21+
""Fat image containing everything""
22+
""necessary to run and test""
23+
""all the applications""
24+
]
25+
usecase base_app [
26+
=Base app
27+
----
28+
""Copies shared application logic""
29+
""independent from the used framework""
30+
""(domains, storage, etc.)""
31+
]
32+
33+
rectangle HTTP {
34+
usecase http_builder [
35+
=Http builder
36+
----
37+
""Builds HTTP dependencies""
38+
]
39+
usecase http_app [
40+
=Http app
41+
----
42+
""Copies HTTP framework""
43+
""shared logic""
44+
""and dependencies""
45+
"" to run the application""
46+
]
47+
}
48+
rectangle GRPC {
49+
usecase grpc_builder [
50+
=GRPC builder
51+
----
52+
""Builds GRPC dependencies""
53+
]
54+
usecase grpc_app [
55+
=GRPC app
56+
----
57+
""Copies HTTP framework""
58+
""shared logic""
59+
""and dependencies""
60+
"" to run the application""
61+
]
62+
}
63+
64+
base ==r=> base_builder
65+
base ==l=> base_app
66+
67+
base_builder ===> http_builder
68+
http_builder ===> http_app
69+
base_app ===> http_app
70+
71+
base_builder ===> grpc_builder
72+
grpc_builder ===> grpc_app
73+
base_app ===> grpc_app
74+
75+
base_builder ==r=> test
76+
@enduml

0 commit comments

Comments
 (0)