Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance readme #30

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 114 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,143 @@
# The Process
# Table of Contents

This repository contains the source code for docker images that are used in [citus testing](https://github.com/citusdata/citus/blob/master/.circleci/config.yml).
* [Introduction](#Introduction)
* [1. Images](#1-images)
* [1.1 How circleci uses our images in testing](#11-How-circleci-uses-our-images-in-testing)
* [2. How to update images](#2-How-to-update-images)
* [2.1 How to update a postgres minor version in images](#2.1-How-to-update-postgres-minor-version-in-images)
* [2.2 How to add a major postgres major](#2.2-How-to-add-a-major-postgres-major)
* [3. How to publish a change](#3-How-to-publish-a-change)

## Introduction

This repository contains the source code for docker images that are used in [citus testing](https://github.com/citusdata/citus/blob/master/.circleci/config.yml). The images are pushed to [docker hub](https://hub.docker.com/u/citus). There is no hooking logic between this repository and the docker hub account. It is used purely for the storage of our images source code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make an issue to track a task to automate the image creation from a CI job? Running upgrades on developer machines have proven to be troublesome, as we had to create a new docker hub account due to access restrictions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#33.


## 1. Images

The [extbuilder](https://github.com/citusdata/the-process/tree/master/circleci/images/extbuilder) image is the core image that other jobs depend on in our tests. The [extbuilder](https://github.com/citusdata/the-process/tree/master/circleci/images/extbuilder):

- Installs postgres 10 and 11 `pg_config`. We only need `pg_config` to generate citus artifacts.
- Installs and tars the checked out citus version for the postgres versions. This is done so that the other jobs can install citus easily by untarring without the need to do `make install`.
- Creates `build-{pg_version}` folders with citus configured, so these folders have the necessary `Makefile.global` to run the tests. These folders are generated for each postgres version. For example, at the time of writing there are 2 folders with `build-10` and `build-11`.
While building the image:

* Installs postgres majors' `pg_config`. We only need `pg_config` to generate citus artifacts.

While running the container:

* Installs and tars the checked out citus version for the postgres versions. This is done so that the other jobs can install citus easily by untarring without the need to do `make install`. We need to do this step in the running container, not while building the image, so that the built citus version is the checked out citus code.
* Creates `build-{pg_version}` folders with citus configured, so these folders have the necessary `Makefile.global` to run the tests. These folders are generated for each postgres version. For example, at the time of writing there are 3 folders with `build-10`, `build-11` and `build-12`.

The general process for other images are similar, which is:

- Untar the citus tar to install citus for the postgres version that the image will use. For example, if postgres 11 is used, the tar is named `install-11.tar`.
- The script (`install-and-test-ext`) takes the target name as an argument, and the following command is used to run the test:
While building the image:

* Install postgres major which is taken as an argument `PG_MAJOR`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most images would and should be taken from the original postgres releases, I think this line does not reflect that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if we install pg12 from the postgres base image, when we try to install libcurl, it installs libcurl4 and citus does not want libcurl4 but libcurl3. We can add libcurl3 package source to our apt/source.list but in the future another package can cause a problem too. And in the extbuilder image we also dont install from pg base image as we have multiple pg majors. So installing the same way as extbuilder seemed okay to me, what do you think?


While running the container:

* Untar the citus tar to install citus for the postgres version that the image will use. For example, if postgres 11 is used, the tar is named `install-11.tar`.
* The script (`install-and-test-ext`) takes the target name as an argument, and the following command is used to run the test:

```bash
gosu circleci make -C "${CIRCLE_WORKING_DIRECTORY}/build-${PG_MAJOR}/src/test/regress" "${@}"
```

- Finally `regression.diffs` is printed if it exists, which indicates that there was a problem during the tests.
* Finally `regression.diffs` is printed if it exists, which indicates that there was a problem during the tests.

Because of the specific logic that we have to run tests faster, we have a docker image `debbuilder` that generates a debian package for `postgresql-server-dev-{pg-major}`. The generated package is in the built docker image, specifically in `{container-name}/home/circleci/debs`. The package is pushed to [the-process](https://packagecloud.io/citus-bot/the-process). This package place is added to apt source list and pinned with with the highest priority so that it is chosen over the standard `postgresql-server-dev-{pg-major}` package.

The installation of postgres packages is at the time of building the image to reduce testing time. However this means that once the image is built the postgres version is fixed. You will need to rebuild the image if you want to upgrade the image, upgrading the image for a minor version is easier compared to upgrading a major version.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't changing the major version for most containers entail to rebuild with a different PG_MAJOR build arg? I think only for pg upgrade tests, where we need multiple postgres versions, and the extbuilder, where we also need multiple postgres versions, the build is slightly harder as we need to change some of the scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For many images yes. What should be done is explained for each image, is there something that you think is redundant or can be simplified?


### 1.1. How circleci uses our images in testing

Our [dockerhub account](https://hub.docker.com/u/citus) has all the images here except the `debbuilder`. When a change is committed, circleci:

* Pulls the `https://hub.docker.com/r/citus/extbuilder` image, generates the citus artifacts which other images will use for testing.
* All of our test jobs wait for `extbuilder` to be completed. Once that is done, all of the jobs are run in parallel without any specific order(It is possible that some jobs are waiting because of parallelism limit in our circleci).
* All the test jobs use the artifacts that are generated with `extbuilder`.

Refer to [images](#1-images) for more details.

## 2. How to update images

While updating images, if the image uses python such as `failtester`, you will need to update the `requirements.txt` as well. We are using `pipenv` for development in [citus](https://github.com/citusdata/citus) but we generate `requirements.txt` file with `pipenv` to install our python dependencies. Running something like the following should generate `requirements.txt`:

```bash
pipenv lock --requirements > requirements.txt
```

Make sure that you include the commit id of citus at the beginning of the generated `requirements.txt`. If you are adding a new python dependency you will need to repeat this process for images to be updated and have the correct dependencies.

### 2.1 How to update postgres minor version in images

To update a postgres minor version, you will need to generate a `debian` package:

* Generate `postgresql-server-dev-{pg-major}` package with `debbuilder` image.
* The generated package will be in `{container-name}/home/circleci/debs`. One way of getting the package from the docker image is:
* Run the container with `docker run -it {tag-name} bash`
* Find the name of your container with `docker ps`
* Copy the `debs` folder from docker container to your local `docker cp {container-name}:/home/circleci/debs .`
* Upload the package to [the-process](https://packagecloud.io/citus-bot/the-process). Make sure that you choose `debian stretch` while uploading. In order to upload you can:
* Upload the package file from the UI by clicking to `Upload image`
* Or you can use the [package cloud cli](https://packagecloud.io/l/cli).

After adding the package to `package cloud`:

And for all images follow the instructions on [how to publish a change](#4-How-to-publish-a-change)

### 2.2. How to add a postgres major

If you want to add support for a major postgres major, like `pg-13` you will need to do the steps that are not limited to:

* Generate `postgresql-server-dev-{pg-major}` package with `debbuilder` image. Make sure to add the package index for `pg-major` in `/etc/apt/sources.list.d/pgdg.list`. You can see find the related part [here](https://github.com/citusdata/the-process/blob/master/circleci/images/debbuilder/files/install-builddeps).
* The generated package will be in `{container-name}/home/circleci/debs`. One way of getting the package from the docker image is:
* Run the container with `docker run -it {tag-name} bash`
* Find the name of your container with `docker ps`
* Copy the `debs` folder from docker container to your local `docker cp {container-name}:/home/circleci/debs .`
* Upload the package to [the-process](https://packagecloud.io/citus-bot/the-process). Make sure that you choose `debian stretch` while uploading. In order to upload you can:
* Upload the package file from the UI by clicking to `Upload image`
* Or you can use the [package cloud cli](https://packagecloud.io/l/cli).

* Add `pg-major` to `extbuilder` in its script so that citus artifacts are generated for that `pg_major` too.
* Add new `pg-major` package index to `sources.list`:

```bash
# add pgdg repo to sources
echo "Writing /etc/apt/sources.list.d/pgdg.list..." >&2
echo "deb http://apt.postgresql.org/pub/repos/apt/ ${codename}-pgdg main ${PG-MAJOR}" > \
/etc/apt/sources.list.d/postgresql.list
```

* Build `exttester` with `pg-major`:

```bash
cd exttester
docker build --tag=citus/exttester-{pg-major} . --build-arg PG_MAJOR={pg-major}
```

* Build `failtester` with `pg-major`:

```bash
cd failtester
docker build --tag=citus/failtester-{pg-major} . --build-arg PG_MAJOR={pg-major}
```

## How to publish a change
## 3. How to publish a change

If you want to make a change and push it to docker hub, you should do:

- Clone the repository and make the necessary changes
- Build the image
* Clone the repository and make the necessary changes
* Build the image

```bash
docker build --tag={repositoryName}/{imageName} .
```

- Login to your account
* Login to your account

```bash
docker login # enter your crendentials
```

- Push the image
* Push the image

```bash
docker push {repositoryName}/{imageName}
Expand Down