Skip to content

Migrate to GitHub Actions and GitHub Container Registry#79

Merged
lemonsaurus merged 7 commits into
masterfrom
sebastiaan/backend/migrate-ci-to-github-actions
Nov 18, 2020
Merged

Migrate to GitHub Actions and GitHub Container Registry#79
lemonsaurus merged 7 commits into
masterfrom
sebastiaan/backend/migrate-ci-to-github-actions

Conversation

@SebastiaanZ
Copy link
Copy Markdown
Contributor

I've migrated the build pipeline to GitHub Actions and changed the container registry to GitHub Container Registry. In the process, I've also made some changes to our docker setup and caching.

  • Note: This PR does not yet take Add pep8-naming and more pre-commit hooks #64 into account. I will update that PR later.

  • Note II: We need to get to a mergeable state sooner rather than later, as this is currently blocking our migration to the Kubernetes cluster.

Most notable aspects of this PR:

We are now using a single multi-stage Dockerfile

Instead of three separate dockerfiles, we are now using a single multi-stage Dockerfile that can be used to build the three images
we want using build targets.

In part, this is because we're now using the docker buildx build action currently recommended by docker. This new engine runs in a sandboxed mode, meaning that while it can export built images to docker running in the host, it cannot import local images from it to base builds on. Building truly separate images, from different dockerfiles, would mean we'd have to push and pull the intermediate images.

By having a single multi-stage Dockerfile, we can still build the intermediate containers and cache their layers, but we don't have to reference other image tags in the Dockerfile.

This new builder back-end comes with some interesting additional options in terms of caching that should work similar to the custom caching script @MarkKoz wrote for Azure (see below).

Docker builds are now cached within GitHub Actions

The builds are now cached using the GitHub Actions cache of the build cache directory. The cache keys try to match a cache generated by a build that matches the current build as closely as possible. In case of a cache miss, we fall back to caching from the latest image pushed to the container repository.

The base and venv images now have an inline cache manifest

In order to fall back intelligently to caching from the repository, the final build and push action for the base and venv images now includes an "inline" cache manifest with the image. This means that the build process can inspect, without pulling the entire image, if it makes sense to pull layers to speed up the build.

The other options, pushing a cache manifest separately (not inline), is currently not supported by GHCR.

The custom caching script has been removed.

Linting errors are now added as GitHub Actions annotations

Just like for some of our other pipelines, linting now generates annotations if linting errors are observed.

Coverage is pushed to coveralls.io

A coverage summary is now pushed to coveralls.io. Each CI run will get a unique job that's linked in the CI output. If the run is attached to a PR, coveralls.io will automatically add a check link with the coverage result to the PR as well.

The README.md, Pipfile, docker-compose, and scripts have been updated

As we now need to pull from and link to the GHCR, I've updated the other files to reflect these changes, including Pipfile run commands. I've also changed the CI badge and added a coveralls.io badge.

I've migrated the build pipeline to GitHub Actions and changed the
container registry to GitHub Container Registry. In the process, I've
made some changes to our docker setup and caching:

- We are now using a single multi-stage Dockerfile

Instead of three separate dockerfiles, we are now using a
single multi-stage Dockerfile that can be used to build the three images
we want using build targets.

In part, this is because we're now using the docker buildx build action
currently recommended by docker. This new engine runs in a sandboxed
mode, meaning that while it can export built images to `docker` running
in the host, it cannot import local images from it to base builds on.

- Docker builds are now cached within GitHub Actions

The builds are now cached using the GitHub Actions cache of the build
cache directory. The cache keys try to match a cache generated by a
build that matches the current build as closely as possible. In case of
a cache miss, we fall back to caching from the latest image pushed to
the container repository.

- The `base` and `venv` images now have an inline cache manifest

In order to fall back intelligently to caching from the repository, the
final build and push action for the `base` and `venv` images includes an
"inline" cache manifest. This means that the build process can inspect,
without pulling, if it makes sense to pull layers to speed up the build.

The other options, pushing a cache manifest separately (not inline), is
currently not supported by GHCR.

The custom caching script has been removed.

- Linting errors are now added as GitHub Actions annotations

Just like for some of our other pipelines, linting now generates
annotations if linting errors are observed.

- Coverage is pushed to coveralls.io

A coverage summary is now pushed to coveralls.io. Each CI run will get a
unique job that's linked in the CI output. If the run is attached to a
PR, coveralls.io will automatically add a check link with the coverage
result to the PR as well.

- The README.md, Pipfile, docker-compose, and scripts have been updated

As we now need to pull from and link to the GHCR, I've updated the other
files to reflect these changes, including Pipfile run commands. I've
also changed the CI badge and added a coveralls.io badge.
Now we've migrated to GitHub Actions, we don't need have XML reports of
our unit tests as we're no longer using the Azure test result
application.
@SebastiaanZ SebastiaanZ added area: CI Related to continuous intergration and deployment priority: 0 - critical Needs to be addressed ASAP labels Nov 18, 2020
@SebastiaanZ SebastiaanZ requested a review from a team as a code owner November 18, 2020 14:29
Comment thread .github/workflows/lint-test-build-push.yaml Outdated
Comment thread .github/workflows/lint-test-build-push.yaml Outdated
I accidentally escaped a single quote in a run command; I've removed it
now. I also changed the job name to `lint-test-build-push` to better
reflect the contents of the job.
Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

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

Since there's only one Dockerfile now, it's redundant to keep it within the Docker subdirectory.

Comment thread .github/workflows/lint-test-build-push.yaml Outdated
Comment thread .github/workflows/lint-test-build-push.yaml
Comment thread .github/workflows/lint-test-build-push.yaml Outdated
Comment thread .github/workflows/lint-test-build-push.yaml Outdated
Comment thread .github/workflows/lint-test-build-push.yaml
Comment thread .github/workflows/lint-test-build-push.yaml Outdated
Comment thread .github/workflows/lint-test-build-push.yaml Outdated
Comment thread .github/workflows/lint-test-build-push.yaml Outdated
Comment thread Pipfile Outdated
One problem that our master builds may have is that they retain more and
more layers of old builds, as there is no easy way of purging them from
the cache. As such master cache would not have benefits over using
repository-based caching, I've removed persistent local caching for
non-PR builds.
I've removed the redundant intermediate image build commands from the
Pipfile. Since everything is now contained in one Dockerfile, we can
simply build the final image in one go.
Comment thread Dockerfile Outdated
Comment thread scripts/dev.sh Outdated
I've fixed paths still pointing to the old Dockerfile location. I've
also reverted an error that somehow got committed to the Dockerfile.
@SebastiaanZ SebastiaanZ force-pushed the sebastiaan/backend/migrate-ci-to-github-actions branch from 0ca42be to 8135eee Compare November 18, 2020 23:11
@lemonsaurus lemonsaurus merged commit 2c17c3d into master Nov 18, 2020
@lemonsaurus lemonsaurus deleted the sebastiaan/backend/migrate-ci-to-github-actions branch November 18, 2020 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: CI Related to continuous intergration and deployment priority: 0 - critical Needs to be addressed ASAP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants