From 32d3eb466b13c8518d58567c9707a0998d55acb5 Mon Sep 17 00:00:00 2001 From: Enrique Belarte Luque Date: Thu, 25 Jan 2024 05:13:46 -0600 Subject: [PATCH] OCM-2620 | build: Add files for building releases from Konflux Added Dockerfile to be used from pipeline builds for release generations using Red Hat keys. Also added some needed modifications and removed old files related to previous release workflow. Signed-off-by: Enrique Belarte Luque --- .github/workflows/publish-release.yaml | 63 -------------------------- .goreleaser.yaml | 59 ------------------------ Dockerfile | 17 +++++++ Makefile | 5 ++ build/build_multiarch | 31 +++++++++++++ 5 files changed, 53 insertions(+), 122 deletions(-) delete mode 100644 .github/workflows/publish-release.yaml delete mode 100644 .goreleaser.yaml create mode 100644 Dockerfile create mode 100644 build/build_multiarch diff --git a/.github/workflows/publish-release.yaml b/.github/workflows/publish-release.yaml deleted file mode 100644 index f58d8e36..00000000 --- a/.github/workflows/publish-release.yaml +++ /dev/null @@ -1,63 +0,0 @@ -# -# Copyright (c) 2021 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -name: Publish release - -on: - push: - tags: - - 'v*' - -permissions: - contents: write - -jobs: - - release: - name: Publish release - runs-on: ubuntu-latest - container: redhat/ubi8 - steps: - - name: Install git - run: | - dnf -y install git - - - name: Checkout the source - uses: actions/checkout@v2 - - - name: Workaround to fix git dir - run: git config --system --add safe.directory /__w/terraform-provider-rhcs/terraform-provider-rhcs - - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: 1.21 - - - name: Import GPG key - id: import_gpg_key - uses: crazy-max/ghaction-import-gpg@v5.0.0 - with: - gpg_private_key: ${{ secrets.RELEASER_GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.RELEASER_GPG_PASSPHRASE }} - - - name: Run releaser - uses: goreleaser/goreleaser-action@v2.8.0 - with: - version: latest - args: release --rm-dist - env: - GPG_FINGERPRINT: ${{ steps.import_gpg_key.outputs.fingerprint }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml deleted file mode 100644 index 1f4e3d5d..00000000 --- a/.goreleaser.yaml +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright (c) 2021 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -builds: -- env: - - CGO_ENABLED=0 - mod_timestamp: '{{ .CommitTimestamp }}' - flags: - - -trimpath - goos: - - darwin - - linux - - windows - goarch: - - amd64 - - arm64 - binary: '{{ .ProjectName }}_v{{ .Version }}' - ldflags: - - -X github.com/terraform-redhat/terraform-provider-rhcs/build.Version={{.Version}} - - -X github.com/terraform-redhat/terraform-provider-rhcs/build.Commit={{.Commit}} -archives: -- format: zip - name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' -checksum: - extra_files: - - glob: 'terraform-registry-manifest.json' - name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json' - name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' - algorithm: sha256 -signs: -- artifacts: checksum - args: - - '--batch' - - '--local-user' - - '{{ .Env.GPG_FINGERPRINT }}' - - '--output' - - '${signature}' - - '--detach-sign' - - '${artifact}' -release: - extra_files: - - glob: 'terraform-registry-manifest.json' - name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json' - name_template: 'Release {{ .Version }}' -changelog: - skip: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..6e4d33e3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM registry.access.redhat.com/ubi9/go-toolset:latest AS builder +COPY . . + +ENV GOFLAGS=-buildvcs=false +RUN git config --global --add safe.directory /opt/app-root/src && \ + make prepare_release + +FROM registry.access.redhat.com/ubi9/ubi-micro:latest +LABEL description="Terraform Provider RHCS" +LABEL io.k8s.description="Terraform Provider RHCS" +LABEL com.redhat.component="terraform-provider-rhcs" +LABEL distribution-scope="release" +LABEL name="terraform-provider-rhcs" release="X.Y" url="https://github.com/terraform-redhat/terraform-provider-rhcs" +LABEL vendor="Red Hat, Inc." +LABEL version="X.Y" + +COPY --from=builder /opt/app-root/src/releases /releases diff --git a/Makefile b/Makefile index fa31c5c2..4360d1f3 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ import_path:=github.com/terraform-redhat/terraform-provider-rhcs version=$(shell git describe --abbrev=0 | sed 's/^v//' | sed 's/-prerelease\.[0-9]*//') commit:=$(shell git rev-parse --short HEAD) git_status:=$(shell git status --porcelain) +REL_VER=$(version) # Set the linker flags so that the version will be included in the binaries: ldflags:=\ @@ -140,3 +141,7 @@ e2e_test: tools install .PHONY: check-gen check-gen: generate scripts/assert_no_diff.sh "generate" + +.PHONY: prepare_release +prepare_release: + import_path=${import_path} ldflags="${ldflags}" bash ./build/build_multiarch diff --git a/build/build_multiarch b/build/build_multiarch new file mode 100644 index 00000000..b7bc5fed --- /dev/null +++ b/build/build_multiarch @@ -0,0 +1,31 @@ +#!/bin/bash +archs=(amd64 arm64) +oses=(linux darwin windows) + +REL_VER=$(git describe --tags --abbrev=0 | sed "s/v//") +if [[ -z "$REL_VER" ]]; then + echo "Must provide version to prepare release" 1>&2 + exit 1 +fi +mkdir -p releases + +# Manual build release based on Terraform docs. +prepare_release() { +for os in ${oses[@]} +do + for arch in ${archs[@]} + do + if [[ $os == "windows" ]]; then + extension=".exe" + fi + GOOS=${os} GOARCH=${arch} go build -ldflags="${ldflags}" -o /tmp/terraform-provider-rhcs_${os}_${arch} + mv /tmp/terraform-provider-rhcs_${os}_${arch} terraform-provider-rhcs_v${REL_VER}${extension} + zip releases/terraform-provider-rhcs_${REL_VER}_${os}_${arch}.zip CHANGELOG.md LICENSE README.md terraform-provider-rhcs_v${REL_VER}${extension} + rm terraform-provider-rhcs_v${REL_VER}${extension} + cp terraform-registry-manifest.json releases/terraform-provider-rhcs_${REL_VER}_manifest.json + done +done +sha256sum releases/*zip releases/terraform-provider-rhcs_${REL_VER}_manifest.json > releases/terraform-provider-rhcs_${REL_VER}_SHA256SUMS +} + +prepare_release