Add workflow to build and publish images (DO THIS after 1240) #1245
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.
@jpmckinney This PR has a GitHub Action to build an publish a Docker image. If it's merged, it should be merged after #1240 (it depends on the Dockerfile to build it).
What happens first
If this PR is merged before #1240, it'll fail because #1240 has the Dockerfile that describes how to build the image. No Dockerfile == failed build.
If this PR is merged without doing any of the below configuration, it'll fail straight away because it'll look to build
/Dockerfile
when, in #1240, the Dockerfile lives at/docker/Dockerfile
. So, theCONTEXT
secret / variable will need to be set (see below). NoCONTEXT
== failed build.Secrets and Variables
A couple of secrets will need to be set for this to work:
CONTEXT
will need to be set todocker
GHCR_USERNAME
will need to be set to something, possiblyjpmckinney
GHCR_PAT
will need to be set to a Personal Access Token scoped to the wireservice/csvkit repo; it should haverepo:status
,read:packages
,write:packages
, anddelete:packages
permissionsghcr_image
should probably be set to something likewireservice/csvkit
so it's published under thewireservice
organization rather than thejpmckinney
user accountI hear you say, "but Wes! Why not use environment variables instead?! Sure, that would work just fine. The primary distinction between environment variables and secrets are that secrets are typically redacted in log outputs and are made less visible to folks who have administrative access to the repository. So, if you use all secrets, it'll work just fine.. if you just use a secret for the PAT and environment variables for the rest, that's fine, too.. better safe than sorry
Another question may be, "why
delete:packages
?" That's a good question. Off the top of my head, I don't know if thewrite:packages
scope allows sufficient permission to overwrite a tagged image. For example, version v2.0.0 is pushed (yay!), the workflow will addv2.0.0
andv2.0
andv2
to the image. Cool. What happens when v2.0.1 is released? It would add tags forv2.0.1
andv2.0
andv2
and I don't happen to know off the top of my shiny head if that requires just write or if delete is required as well.By default, the image's visibility / access control is set to
private
; to make it accessible by the public, it'll need to be set topublic
(docs)Notes on the build action
The action itself (
.github/workflows/publish.yml
) has about 100 lines of notes, instructions, etc. that describe how to use and configure it. The TL;DR is that it can publish images to a bunch of places on a variety of platforms (architectures) and those behaviors can be configured through the use of environment variables (or secrets). The environment variables and secrets mentioned above are defined there, too.GitHub Documentation
Action Secrets: https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
Action Environment Variables: https://docs.github.com/en/actions/learn-github-actions/variables
OATH / PAT Scopes: https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes
Publishing to GHCR: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry
GHCR access control / visibility: https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility