From f557fffcc7ea4007d70c5eb59bae193bf7abf8ff Mon Sep 17 00:00:00 2001 From: Matthias Baur Date: Fri, 6 Dec 2024 10:32:30 +0100 Subject: [PATCH] Implement OCI distribution --- .github/workflows/release.yml | 14 ++++++++++--- .gitignore | 3 +++ .goreleaser.yml | 6 +++--- ci/release-oci-artifacts.sh | 39 +++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 ci/release-oci-artifacts.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cbf34fd..f64631d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,12 +1,16 @@ -name: goreleaser +name: release + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} on: push: tags: - - '*' + - "*" jobs: - goreleaser: + release: runs-on: ubuntu-latest steps: - name: Checkout code @@ -24,3 +28,7 @@ jobs: args: release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build OCI artifacts + run: ci/release-oci-artifacts.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 2262520..2382647 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ # Go workspace file go.work fleeting-plugin-openstack + +# goreleaser build directory +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml index 5ff2b53..9a446ae 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,6 @@ +version: 2 builds: - - # First Build + - # First Build env: - CGO_ENABLED=0 main: ./cmd/fleeting-plugin-openstack @@ -11,8 +12,7 @@ builds: -X github.com/sardinasystems/fleeting-plugin-openstack.BuildUser=goreleaser@github-actions -X github.com/sardinasystems/fleeting-plugin-openstack.BuildDate={{time "20060102-15:04:05"}} - # Set the binary output location to bin/ so archive will comply with Sensu Go Asset structure - binary: bin/{{ .ProjectName }} + binary: "{{ .ProjectName }}" goos: - linux goarch: diff --git a/ci/release-oci-artifacts.sh b/ci/release-oci-artifacts.sh new file mode 100644 index 0000000..185a517 --- /dev/null +++ b/ci/release-oci-artifacts.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -eo pipefail + +# convert 'dist/fleeting-plugin-{name}_{os}_{arch}_{arch_verson}/fleeting-plugin-openstack' to 'dist/{os}/{arch}/plugin' +for path in ./dist/fleeting-plugin-*/*; do + dirname=$(dirname $(echo ${path#dist/})) + IFS='_' read -ra parts <<<"${dirname}" + + os=${parts[1]} + arch=${parts[2]%.exe} + + if [ "$arch" = "arm" ]; then + arch="armv${parts[3]}" + fi + + ext="" + if [ "$os" = "windows" ]; then + ext=".exe" + fi + + mkdir -p "dist/${os}/${arch}/" + mv "${path}" "dist/${os}/${arch}/plugin${ext}" +done + +find ./dist + +go install gitlab.com/gitlab-org/fleeting/fleeting-artifact/cmd/fleeting-artifact@latest + +VERSION=${GITHUB_REF_NAME:=0.0.0-bleeding} + +# login to registry +fleeting-artifact login -username "${GITHUB_ACTOR}" -password "${GITHUB_TOKEN}" "${REGISTRY}" + +# releast artifact +IMAGE_DIGEST="$(fleeting-artifact release "${REGISTRY}/${IMAGE_NAME}:${VERSION#v}")" + +# keyless sign +cosign sign "${IMAGE_DIGEST}"