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