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

GitHub Actions and Docker build process improvements #5

Merged
merged 14 commits into from
Feb 26, 2021

Conversation

thijsputman
Copy link
Owner

@thijsputman thijsputman commented Feb 25, 2021

While attempting to auto-tag the Docker images on Docker Hub (which is working at the moment) some minor nuisances came to light.

Apart from that, I think it's better to split the Docker workflow into two: One for building the image and the second for pushing the image to Docker Hub (to prevent building the same image multiple times). Only thing to figure out there is how to use the artifact from one workflow in another...

While I'm at it, also see if it's possible to use buildx to build Docker images for amd64 and armhf architectures too.

Split the Docker workflow into two separate ones: One for CI (do a multi-arch build and store the resulting images as artifacts) and one to publish to Docker Hub (for every commit and the main-branch and for every tag created).

Yes, some of the workflows have copy-pasted elements, but there is no
way around that...
And rename the two steps involved to more accurately represent their
function (as both now tag "latest").
Bit senseless as the tag would always be created from a commit that has
already been linted... Also, the old behaviour leads to the GitHub UI
showing the linter checks twice for commits that have a tag attached.
@thijsputman thijsputman self-assigned this Feb 25, 2021
@thijsputman thijsputman temporarily deployed to ci February 25, 2021 21:10 Inactive
Instead of unconditionally building the Docker image, only build it if
it isn't available on Docker Hub. Images are always tagged with their
Git commitish, which should ensure we only build each image once (and
prevent building/pushing multiple, functionally identical, copies of the
same image).

Additionally, revert my previous change with regards to tagging "stable"
and "latest". The "latest" tag should always (and only) be applied to
commits on the main-branch. It's not unthinkable that a release is not
created from the HEAD of main, but from an older commit. As such, it is
very well possible that when "stable" is created, it is not necessarily
"latest"...
Furthermore, only non-prerelease versions are tagged with "stable". The
others are only tagged with their version itself. Only "clean" semantic
versions (e.g. "1.2.3") are considered stable. If anything is appended
to the version (e.g. "1.2.3-beta2") it's considered prerelease.

Relying heavily on a (creative?) interpretation of the "job.if" feature
to ensure proper flow-control. Proof will be in the pudding...
Instead of failing the "pull"-job when the image isn't available on
Docker Hub, use output to communicate the result.

Also, buildx appears to not support storing multi-arch builds in a
tar-file, so for now we'll forgo storing a copy of the build as an
artifact of the workflow (marginally relevant to begin with).
@thijsputman thijsputman temporarily deployed to production February 26, 2021 00:55 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 00:55 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 00:56 Inactive
First part works, now let's see if it actually wants to push to Docker
Hub...
@thijsputman thijsputman temporarily deployed to production February 26, 2021 01:01 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 01:01 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 01:01 Inactive
@thijsputman thijsputman temporarily deployed to production February 26, 2021 01:07 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 01:07 Inactive
@thijsputman thijsputman temporarily deployed to production February 26, 2021 01:16 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 01:16 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 01:16 Inactive
And it's getting way too late; already messed by removing the artifacts
(which are necessary to transfer the images from one job to the next).
@thijsputman thijsputman temporarily deployed to production February 26, 2021 01:34 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 01:34 Inactive
@thijsputman thijsputman temporarily deployed to ci February 26, 2021 01:34 Inactive
Using buildx to do multi-arch builds and passing around tar-files with
the resulting images doesn't as expected – the regular Docker-client
doesn't cope too well with the multi-arch aspect of it all...

So, it is either using a single step buildx-command to do everything
(building, tagging and pushing), or completely reimplement the
convenience of buildx using the regular build and the manifest-tool.

The latter would have allowed me to stay with a single, multi-step,
workflow with as little duplication in steps as possible. The former
appears much simpler though (even if it requires two workflows with a
lot of overlap).

So, there are now a "docker-ci" and a "docker-push" workflow, with some
overlap, but all-in-all a much clearer approach (and fewer magic
"if"-statements to control a highly dynamic flow).
Has no added value, just causes a lot of clutter in the GitHub
interface...
@thijsputman thijsputman temporarily deployed to docker-hub February 26, 2021 14:34 Inactive
@thijsputman thijsputman merged commit 8628ec5 into main Feb 26, 2021
@thijsputman thijsputman deleted the docker-github-actions branch February 26, 2021 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant