blob: 5c16b2edddafa9995c7db27a7ba68b78f244b311 [file] [log] [blame] [view]
Giorgi Lekveishvili285ab622023-11-22 13:50:45 +04001# Gerrit Deployment on Kubernetes
2
3Container images, configurations, [helm charts](https://helm.sh/) and a Kubernetes
4Operator for installing [Gerrit](https://www.gerritcodereview.com/) on
5[Kubernetes](https://kubernetes.io/).
6
7# Deploying Gerrit on Kubernetes
8
9This project provides helm-charts to install Gerrit either as a primary instance
10or a replica on Kubernetes.
11
12The helm-charts are located in the `./helm-charts`-directory. Currently, the
13charts are not published in a registry and have to be deployed from local sources.
14
15For a detailed guide of how to install the helm-charts refer to the respective
16READMEs in the helm-charts directories:
17
18- [gerrit](helm-charts/gerrit/README.md)
19- [gerrit-replica](helm-charts/gerrit-replica/README.md)
20
21These READMEs detail the prerequisites required by the charts as well as all
22configuration options currently provided by the charts.
23
24To evaluate and test the helm-charts, they can be installed on a local machine
25running Minikube. Follow this [guide](Documentation/minikube.md) to get a detailed
26description how to set up the Minikube cluster and install the charts.
27
28Alternatively, a Gerrit Operator can be used to install and operate Gerrit in a
29Kubernetes cluster. The [documentation](./Documentation/operator.md) describes
30how to build and deploy the Gerrit Operator and how to use it to install Gerrit.
31
32# Docker images
33
34This project provides the sources for docker images used by the helm-charts.
35The images are also provided on [Dockerhub](https://hub.docker.com/u/k8sgerrit).
36
37The project also provides scripts to build and publish the images so that custom
38versions can be used by the helm-charts. This requires however a docker registry
39that can be accessed from the Kubernetes cluster, on which Gerrit will be
40deployed. The functionality of the scripts is described in the following sub-
41sections.
42
43## Building images
44
45To build all images, the `build`-script in the root directory of the project can
46be used:
47
48```
49./build
50```
51
52If a specific image should be built, the image name can be specified as an argument.
53Multiple images can be specified at once:
54
55```
56./build gerrit git-gc
57```
58
59The build-script usually uses the `latest`-tag to tag the images. By using the
60`--tag TAG`-option, a custom tag can be defined:
61
62```
63./build --tag test
64```
65
66The version of Gerrit built into the images can be changed by providing a download
67URL for a `.war`-file containing Gerrit:
68
69```
70./build --gerrit-url https://example.com/gerrit.war
71```
72
73The version of a health-check plugin built into the images can be changed by
74providing a download URL for a `.jar`-file containing the plugin:
75
76```
77./build --healthcheck-jar-url https://example.com/healthcheck.jar
78```
79
80The build script will in addition tag the image with the output of
81`git describe --dirty`.
82
83The single component images inherit a base image. The `Dockerfile` for the base
84image can be found in the `./base`-directory. It will be
85automatically built by the `./build`-script. If the component images are built
86manually, the base image has to be built first with the target
87`base:latest`, since it is not available in a registry and thus has
88to exist locally.
89
90## Publishing images
91
92The publish script in the root directory of the project can be used to push the
93built images to the configured registry. To do so, log in first, before executing
94the script.
95
96```
97docker login <registry>
98```
99
100To configure the registry and image version, the respective values can be
101configured via env variables `REGISTRY` and `TAG`. In addition, these values can
102also be passed as command line options named `--registry` and `--tag` in which
103case they override the values from env variables:
104
105```
106./publish <component-name>
107```
108
109The `<component-name>` is one of: `apache-git-http-backend`, `git-gc`, `gerrit`
110or `gerrit-init`.
111
112Adding the `--update-latest`-flag will also update the images tagged `latest` in
113the repository:
114
115```
116./publish --update-latest <component-name>
117```
118
119## Running images in Docker
120
121The container images are meant to be used by the helm-charts provided in this
122project. The images are thus not designed to be used in a standalone setup. To
123run Gerrit on Docker use the
124[docker-gerrit](https://gerrit-review.googlesource.com/admin/repos/docker-gerrit)
125project.
126
127# Running tests
128
129The tests are implemented using Python and `pytest`. To ensure a well-defined
130test-environment, `pipenv` is meant to be used to install packages and provide a
131virtual environment in which to run the tests. To install pipenv, use `brew`:
132
133```sh
134brew install pipenv
135```
136
137More detailed information can be found in the
138[pipenv GitHub repo](https://github.com/pypa/pipenv).
139
140To create the virtual environment with all required packages, run:
141
142```sh
143pipenv install
144```
145
146To run all tests, execute:
147
148```sh
149pipenv run pytest -m "not smoke"
150```
151
152***note
153The `-m "not smoke"`-option excludes the smoke tests, which will fail, since
154no Gerrit-instance will be running, when they are executed.
155***
156
157Some tests will need to create files in a temporary directory. Some of these
158files will be mounted into docker containers by tests. For this to work make
159either sure that the system temporary directory is accessible by the Docker
160daemon or set the base temporary directory to a directory accessible by Docker
161by executing:
162
163```sh
164pipenv run pytest --basetemp=/tmp/k8sgerrit -m "not smoke"
165```
166
167By default the tests will build all images from scratch. This will greatly
168increase the time needed for testing. To use already existing container images,
169a tag can be provided as follows:
170
171```sh
172pipenv run pytest --tag=v0.1 -m "not smoke"
173```
174
175The tests will then use the existing images with the provided tag. If an image
176does not exist, it will still be built by the tests.
177
178By default the build of the container images will not use the build cache
179created by docker. To enable the cache, execute:
180
181```sh
182pipenv run pytest --build-cache -m "not smoke"
183```
184
185Slow tests may be marked with the decorator `@pytest.mark.slow`. These tests
186may then be skipped as follows:
187
188```sh
189pipenv run pytest --skip-slow -m "not smoke"
190```
191
192There are also other marks, allowing to select tests (refer to
193[this section](#test-marks)).
194
195To run specific tests, execute one of the following:
196
197```sh
198# Run all tests in a directory (including subdirectories)
199pipenv run pytest tests/container-images/base
200
201# Run all tests in a file
202pipenv run pytest tests/container-images/base/test_container_build_base.py
203
204# Run a specific test
205pipenv run \
206 pytest tests/container-images/base/test_container_build_base.py::test_build_base
207
208# Run tests with a specific marker
209pipenv run pytest -m "docker"
210```
211
212For a more detailed description of how to use `pytest`, refer to the
213[official documentation](https://docs.pytest.org/en/latest/contents.html).
214
215## Test marks
216
217### docker
218
219Marks tests which start up docker containers. These tests will interact with
220the containers by either using `docker exec` or sending HTTP-requests. Make
221sure that your system supports this kind of interaction.
222
223### incremental
224
225Marks test classes in which the contained test functions have to run
226incrementally.
227
228### integration
229
230Marks integration tests. These tests test interactions between containers,
231between outside clients and containers and between the components installed
232by a helm chart.
233
234### kubernetes
235
236Marks tests that require a Kubernetes cluster. These tests are used to test the
237functionality of the helm charts in this project and the interaction of the
238components installed by them. The cluster should not be used for other purposes
239to minimize unforeseen interactions.
240
241These tests require a storage class with ReadWriteMany access mode within the
242cluster. The name of the storage class has to be provided with the
243`--rwm-storageclass`-option (default: `shared-storage`).
244
245### slow
246
247Marks tests that need an above average time to run.
248
249### structure
250
251Marks structure tests. These tests are meant to test, whether certain components
252exist in a container. These tests ensure that components expected by the users
253of the container, e.g. the helm charts, are present in the containers.
254
255## Running smoke tests
256
257To run smoke tests, use the following command:
258
259```sh
260pipenv run pytest \
261 -m "smoke" \
262 --basetemp="<tmp-dir for tests>" \
263 --ingress-url="<Gerrit URL>" \
264 --gerrit-user="<Gerrit user>" \
265 --gerrit-pwd
266```
267
268The smoke tests require a Gerrit user that is allowed to create and delete
269projects. The username has to be given by `--gerit-user`. Setting the
270`--gerrit-pwd`-flag will cause a password prompt to enter the password of the
271Gerrit-user.
272
273# Contributing
274
275Contributions to this project are welcome. If you are new to the Gerrit workflow,
276refer to the [Gerrit-documentation](https://gerrit-review.googlesource.com/Documentation/intro-gerrit-walkthrough.html)
277for guidance on how to contribute changes.
278
279The contribution guidelines for this project can be found
280[here](Documentation/developer-guide.md).
281
282# Roadmap
283
284The roadmap of this project can be found [here](Documentation/roadmap.md).
285
286Feature requests can be made by pushing a change for the roadmap. This can also
287be done to announce/discuss features that you would like to provide.
288
289# Contact
290
291The [Gerrit Mailing List](https://groups.google.com/forum/#!forum/repo-discuss)
292can be used to post questions and comments on this project or Gerrit in general.