Add GitHub Actions workflow to build, test and push Docker images. #96
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a first fully working GitHub Actions workflow to build, test and upload Docker images for Eliot.
The workflow is triggered when a pull request against the main branch is opened, updated or merged, or when a new tag is created.
The workflow consists of two jobs. The
build
job builds, tests and stores an image as an GitHub Actions artifact. This job is always run. Thepush
job is only run when themain
branch is updated (pushing thelatest
tag) or when a new tag has been created (using the tag as the Docker image tag).I tested this workflow on a private fork of Eliot. I temporarily gave that fork permission to push to the Eliot GAR repository in the new GCP project. The workflow appears to work fine, and does not leak any GCP project ids in case we want to avoid that.
We could avoid uploading and downloading the Docker image if we would merge the two jobs into a single one. However, this would have the following downsides:
The
push
job has access to the "secrets". While none of the secrets are particularly sensitive, we still don't want to make them available to fork builds. Thebuild
job does not have access to any sensitive information, and we could run it on fork PRs.We would need to repeat the
if
condition for thepush
job for every single step if we merge the workflows. We could work around this problem by factoring this job out into a reusable action (which we probably want to do anyway, see below).Problems with the current approach:
Artifact storage to store Docker images is slow and feels artificial. It may also be subject to race conditions, since concurrent workflows could overwrite the Docker image before it is used by the
push
job. We could look into using GitHub Packages to store the Docker image, but that doesn't support any retention policies as far as I can tell, so we'd need to come up with an automated clean-up mechanism.The
push
job should be made generic, so we (and others) can use it in other repositories.Overall, I'm leaning towards factoring out the
push
job into a reusable action and then merging the two jobs into a single one.