Skip to content

Use goreleaser and GitHub Actions for image publishing to ghcr.io#11

Merged
cw-sakamoto merged 1 commit intomainfrom
goreleaser
Nov 29, 2023
Merged

Use goreleaser and GitHub Actions for image publishing to ghcr.io#11
cw-sakamoto merged 1 commit intomainfrom
goreleaser

Conversation

@mumoshu
Copy link
Copy Markdown
Collaborator

@mumoshu mumoshu commented Nov 28, 2023

As the title says :)

I think we don't need to set up anything to make this workflow work.
GitHub Actions, along with the permissions specified in the workflow, would give us access to ghcr.io and therefore the image publishing should just work.

The images should be "private" by default. No action should be needed by you to hide the images.

name: Release

on:
push:
Copy link
Copy Markdown
Collaborator Author

@mumoshu mumoshu Nov 28, 2023

Choose a reason for hiding this comment

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

We push versioned binaries and image for semver-tagged commits (like v1 or v1.1 or whatever git tagged commits), AND "canary" binaries(no images) for other commits.

with:
name: kibertas
path: |
dist/kibertas*.tar.gz
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If it is a canary release, we upload the binaries to the actions artifacts, which can be accessed via the Actions workflow run view.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Head to the bottom of https://github.com/chatwork/kibertas/actions/runs/7018953100?pr=11 and you'll be able to grab the archived binaries:

image

with:
distribution: goreleaser
version: latest
args: release --clean ${{ env.flags }}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You can locally test the goreleaser.yaml used by this step by running make goreleaser-snapshot. As long as it works locally, this step should mostly work...

Comment on lines +40 to +42
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Copy link
Copy Markdown
Collaborator Author

@mumoshu mumoshu Nov 28, 2023

Choose a reason for hiding this comment

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

fetch-depth: 0
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Used for arm builds.

uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Used for cross-platform builds

name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We don't need the full history

steps:
-
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "flags=--snapshot" >> $GITHUB_ENV
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

--snapshot in case it's canary builds(=no-semver-tagged commit)- --snapshot skips image publishing and does building only.

Comment thread .gitignore
manifests/credentials.yaml
.bin/
.vscode
dist/
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

make goreleaser-snapshot produces binaries and archives of the binaries under dist/. We don't want to git-commit that so ignore.

Comment thread Dockerfile
ARG TARGETARCH

COPY --from=builder /app/kibertas /usr/local/bin/kibertas
COPY kibertas /usr/local/bin/kibertas
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

goreleaser runs docker-builds in a docker context that the goreleaser-produced kibertas binary exists, hence this simple COPY work.

Copy link
Copy Markdown
Collaborator Author

@mumoshu mumoshu Nov 28, 2023

Choose a reason for hiding this comment

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

@cw-sakamoto
Copy link
Copy Markdown
Contributor

#10

@cw-sakamoto
Copy link
Copy Markdown
Contributor

Awesome work!

@cw-sakamoto cw-sakamoto merged commit e4f937e into main Nov 29, 2023
@cw-sakamoto cw-sakamoto deleted the goreleaser branch November 29, 2023 02:20
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.

2 participants