From 91df729f1cfd636355fc8338f47aefa4ab8b3b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sun, 4 May 2025 02:23:20 +0200 Subject: [PATCH] feat: publish container image (#82) Use `goreleaser` and `ko` to automatically build and publish container images in the release workflow. The images are published to `ghcr.io/apricote/hcloud-upload-image`. Co-authored-by: Ilja Malachowski --- .github/workflows/release.yaml | 11 +++++++++++ .goreleaser.yaml | 23 +++++++++++++++++++---- README.md | 8 ++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d842a96..568ad36 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,11 +7,22 @@ on: jobs: release: + permissions: + contents: read + packages: write + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5bba2d1..474362f 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -7,7 +7,8 @@ before: - ./scripts/completions.sh builds: - - env: + - id: default + env: - CGO_ENABLED=0 goos: - linux @@ -21,7 +22,7 @@ builds: - -X {{ .ModulePath }}/internal/version.versionPrerelease= archives: - - format: tar.gz + - formats: [ "tar.gz" ] # this name template makes the OS and Arch compatible with the results of `uname`. name_template: >- {{ .ProjectName }}_ @@ -33,7 +34,7 @@ archives: # use zip for windows archives format_overrides: - goos: windows - format: zip + formats: [ "zip" ] files: - README.md @@ -104,9 +105,23 @@ aurs: install -Dm644 "./completions/hcloud-upload-image.zsh" "${pkgdir}/usr/share/zsh/site-functions/_hcloud-upload-image" install -Dm644 "./completions/hcloud-upload-image.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/hcloud-upload-image.fish" +kos: + - id: container-images + build: default + repositories: + - ghcr.io/apricote + platforms: + - linux/amd64 + - linux/arm64 + base_import_paths: true + labels: + org.opencontainers.image.source: https://github.com/apricote/hcloud-upload-image + tags: + - latest + - "{{.Tag}}" snapshot: - name_template: "{{ .Version }}-dev+{{ .ShortCommit }}" + version_template: "{{ .Version }}-dev+{{ .ShortCommit }}" changelog: # Generated by release-please diff --git a/README.md b/README.md index 4383aa0..ae42c59 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,14 @@ If you already have a recent Go toolchain installed, you can build & install the go install github.com/apricote/hcloud-upload-image@latest ``` +#### Docker + +There is a docker image published at `ghcr.io/apricote/hcloud-upload-image`. + +```shell +docker run --rm -e HCLOUD_TOKEN="" ghcr.io/apricote/hcloud-upload-image:latest +``` + #### Usage ```shell