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