blob: 0e5fc5f4cd9dd62d8a405dd146bc567010b992cd [file] [log] [blame] [view]
Giorgi Lekveishvili4ec4c022024-08-17 15:09:24 +04001# Developer Guide
2
3[TOC]
4
5## Code Review
6
7This project uses Gerrit for code review:
8https://gerrit-review.googlesource.com/
9which uses the ["git push" workflow][1] with server
10https://gerrit.googlesource.com/k8s-gerrit. You will need a
11[generated cookie][2].
12
13Gerrit depends on "Change-Id" annotations in your commit message.
14If you try to push a commit without one, it will explain how to
15install the proper git-hook:
16
17```
18curl -Lo `git rev-parse --git-dir`/hooks/commit-msg \
19 https://gerrit-review.googlesource.com/tools/hooks/commit-msg
20chmod +x `git rev-parse --git-dir`/hooks/commit-msg
21```
22
23Before you create your local commit (which you'll push to Gerrit)
24you will need to set your email to match your Gerrit account:
25
26```
27git config --local --add user.email foo@bar.com
28```
29
30Normally you will create code reviews by pushing for master:
31
32```
33git push origin HEAD:refs/for/master
34```
35
36## Developing container images
37
38When changing or creating container images, keep the image size as small as
39possible. This reduces storage space needed for images, the upload time and most
40importantly the download time, which improves startup time of pods.
41
42Some good practices are listed here:
43
44- **Chain commands:** Each `RUN`-command creates a new layer in the docker image.
45Each layer increases the total image size. Thus, reducing the number of layers,
46can also reduce the image size.
47
48- **Clean up after package installation:** The package installation creates a
49number of cache files, which should be removed after installation. In Ubuntu/Debian-
50based images use the following snippet (This requires `apt-get update` before
51each package installation!):
52
53```docker
54RUN apt-get update && \
55 apt get install -y <packages> && \
56 apt-get clean && \
57 rm -rf /var/lib/apt/lists/*
58```
59
60In Alpine based images use the `--no-cache`-flag of `apk`.
61
62- **Clean up temporary files immediately:** If temporary files are created by a
63command remove them in the same command chain.
64
65- **Use multi stage builds:** If some complicated build processes are needed for
66building parts of the container image, of which only the final product is needed,
67use [multi stage builds][3]
68
69
70[1]: https://gerrit-review.googlesource.com/Documentation/user-upload.html#_git_push
71[2]: https://gerrit.googlesource.com/new-password
72[3]: https://docs.docker.com/develop/develop-images/multistage-build/
73
74## Writing clean python code
75
76When writing python code, either for tests or for scripts, use `black` and `pylint`
77to ensure a clean code style. They can be run by the following commands:
78
79```sh
80pipenv install --dev
81pipenv run black $(find . -name '*.py')
82pipenv run pylint $(find . -name '*.py')
83```