From 41261fc6cef588c520176476974d64871ce1a312 Mon Sep 17 00:00:00 2001 From: Tim Flannagan Date: Fri, 24 Sep 2021 16:46:31 -0400 Subject: [PATCH] Integrate goreleaser to produce draft releases when new tags are pushed (#2365) * Makefile: Avoid hardcoding the quay repository in the release target Update the release target and avoid hardcoding the quay.io/operator-framework/olm quay repository and instead use the existing IMAGE_REPO variable defined further up in the Makefile. Update how the $(ver) variable is handled and avoid hardcoding the 'v' prefix when overriding that 'ver' variable in the environment. Signed-off-by: timflannagan * Integrate goreleaser to automate the building and publishing of multi-arch container images Signed-off-by: timflannagan * .github/workflows: Add a release workflow for creating draft releases Add a GHA release workflow that's triggered on tags that's responsible for building and pushing multi-arch (i.e. manifestlist) OLM container images using goreleaser. Goreleaser will also create a draft release, and generate a changelog since the previous tag. Rendering the release quickstart manifests is done after goreleaser has created this draft release as there's no easy way to hook this functionality into goreleaser after the docker images/manifestlists have been pushed but before release artifacts are generated. Use the 'softprops/action-gh-release' to update the newly created draft release with these quickstart manifests as assets. Signed-off-by: timflannagan * .goreleaser: Add support for ppc64le and s390x architectures * .github/workflows: Avoid using the latest goreleaser action version --- .github/workflows/goreleaser.yaml | 73 ++++++++++++++++ .gitignore | 2 + .goreleaser.yml | 134 ++++++++++++++++++++++++++++++ Dockerfile.goreleaser | 13 +++ Makefile | 7 +- 5 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/goreleaser.yaml create mode 100644 .goreleaser.yml create mode 100644 Dockerfile.goreleaser diff --git a/.github/workflows/goreleaser.yaml b/.github/workflows/goreleaser.yaml new file mode 100644 index 0000000000..ae0f240bb0 --- /dev/null +++ b/.github/workflows/goreleaser.yaml @@ -0,0 +1,73 @@ +name: release +on: + pull_request: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Get the image tag + if: startsWith(github.ref, 'refs/tags') + run: | + # Source: https://github.community/t/how-to-get-just-the-tag-name/16241/32 + if [[ $GITHUB_REF == refs/tags/* ]]; then + echo IMAGE_TAG="${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + fi + + - name: Create a draft release + uses: actions/create-release@v1 + id: release + if: startsWith(github.ref, 'refs/tags') + env: + GITHUB_TOKEN: ${{ github.token }} + with: + draft: true + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + + - name: Docker Login + uses: docker/login-action@v1 + if: startsWith(github.ref, 'refs/tags') + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + if: startsWith(github.ref, 'refs/tags') + with: + version: 0.177.0 + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ github.token }} + IMAGE_REPO: ${{ secrets.QUAY_USERNAME }}/olm + PKG: github.com/operator-framework/operator-lifecycle-manager + + - name: Generate quickstart release manifests + if: startsWith(github.ref, 'refs/tags') + run: make release ver=${{ env.IMAGE_TAG }} IMAGE_REPO=quay.io/${{ secrets.QUAY_USERNAME }}/olm + + - name: Update release artifacts with rendered Kubernetes manifests + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags') + with: + name: ${{ env.IMAGE_TAG }} + files: | + deploy/upstream/quickstart/crds.yaml + deploy/upstream/quickstart/olm.yaml + deploy/upstream/quickstart/install.sh + draft: true + token: ${{ github.token }} diff --git a/.gitignore b/.gitignore index aa73350bb7..4efa7ce90a 100644 --- a/.gitignore +++ b/.gitignore @@ -455,3 +455,5 @@ apiserver.key !vendor/** test/e2e-local.image.tar + +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000000..fa567b1049 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,134 @@ +env: +- GO111MODULE=on +- CGO_ENABLED=0 +before: + hooks: + - go mod tidy + - go mod vendor +builds: + - id: olm + main: ./cmd/olm + binary: olm + goos: + - linux + goarch: + - amd64 + - arm64 + - ppc64le + - s390x + tags: + - json1 + flags: + - -mod=vendor + ldflags: + - -X {{ .Env.PKG }}/pkg/version.GitCommit={{ .FullCommit }} + - -X {{ .Env.PKG }}/pkg/version.OLMVersion={{ .Tag }} + - id: catalog + main: ./cmd/catalog + binary: catalog + goos: + - linux + goarch: + - amd64 + - arm64 + - ppc64le + - s390x + tags: + - json1 + flags: + - -mod=vendor + ldflags: + - -X {{ .Env.PKG }}/pkg/version.GitCommit={{ .FullCommit }} + - -X {{ .Env.PKG }}/pkg/version.OLMVersion={{ .Tag }} + - id: cpb + main: ./util/cpb + binary: cpb + goos: + - linux + goarch: + - amd64 + - arm64 + - ppc64le + - s390x + tags: + - json1 + flags: + - -mod=vendor + ldflags: + - -X {{ .Env.PKG }}/pkg/version.GitCommit={{ .FullCommit }} + - -X {{ .Env.PKG }}/pkg/version.OLMVersion={{ .Tag }} + - id: package-server + main: ./cmd/package-server + binary: package-server + goos: + - linux + goarch: + - amd64 + - arm64 + - ppc64le + - s390x + tags: + - json1 + flags: + - -mod=vendor + ldflags: + - -X {{ .Env.PKG }}/pkg/version.GitCommit={{ .FullCommit }} + - -X {{ .Env.PKG }}/pkg/version.OLMVersion={{ .Tag }} +dockers: +- image_templates: + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-amd64 + dockerfile: Dockerfile.goreleaser + use: buildx + goos: linux + goarch: amd64 + build_flag_templates: + - --platform=linux/amd64 +- image_templates: + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-arm64 + dockerfile: Dockerfile.goreleaser + use: buildx + goos: linux + goarch: arm64 + build_flag_templates: + - --platform=linux/arm64 +- image_templates: + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-ppc64le + dockerfile: Dockerfile.goreleaser + use: buildx + goos: linux + goarch: ppc64le + build_flag_templates: + - --platform=linux/ppc64le +- image_templates: + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-s390x + dockerfile: Dockerfile.goreleaser + use: buildx + goos: linux + goarch: s390x + build_flag_templates: + - --platform=linux/s390x +docker_manifests: +- name_template: quay.io/{{ .Env.IMAGE_REPO }}:v{{ .Major }}.{{ .Minor }} + image_templates: + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-amd64 + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-arm64 + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-ppc64le + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-s390x +- name_template: quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }} + image_templates: + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-amd64 + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-arm64 + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-ppc64le + - quay.io/{{ .Env.IMAGE_REPO }}:{{ .Tag }}-s390x +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}" +changelog: + sort: asc + filters: + exclude: + - '^doc:' + - '^test:' +release: + draft: true diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000000..6a3238d015 --- /dev/null +++ b/Dockerfile.goreleaser @@ -0,0 +1,13 @@ +FROM --platform=$BUILDPLATFORM gcr.io/distroless/static:debug +LABEL stage=olm +WORKDIR / +# bundle unpack Jobs require cp at /bin/cp +RUN ["/busybox/ln", "-s", "/busybox/cp", "/bin/cp"] +# copy goreleaser built binaries +COPY olm /bin/olm +COPY catalog /bin/catalog +COPY package-server /bin/package-server +COPY cpb /bin/cpb +EXPOSE 8080 +EXPOSE 5443 +ENTRYPOINT ["/bin/olm"] diff --git a/Makefile b/Makefile index 703c077a94..f54ec3751a 100644 --- a/Makefile +++ b/Makefile @@ -217,15 +217,16 @@ verify: verify-codegen verify-mockgen verify-manifests # before running release, bump the version in OLM_VERSION and push to master, # then tag those builds in quay with the version in OLM_VERSION -release: ver=$(shell cat OLM_VERSION) +release: ver=v$(shell cat OLM_VERSION) release: manifests - docker pull quay.io/operator-framework/olm:v$(ver) + @echo "Generating the $(ver) release" + docker pull $(IMAGE_REPO):$(ver) $(MAKE) target=upstream ver=$(ver) quickstart=true package verify-release: release $(MAKE) diff -package: olmref=$(shell docker inspect --format='{{index .RepoDigests 0}}' quay.io/operator-framework/olm:v$(ver)) +package: olmref=$(shell docker inspect --format='{{index .RepoDigests 0}}' $(IMAGE_REPO):$(ver)) package: ifndef target $(error target is undefined)