Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.3] Update OKD community bundle PR automation #144

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9e1f358
Makefile target to revert all version or build date related changes
clobrano Jan 25, 2024
cfb8c2f
Trigger bundle-reset automatically as part of verify-no-changes target
clobrano Jan 29, 2024
dd64d73
Make complete bundle community via Makefile
clobrano Feb 1, 2024
86b4c51
Merge pull request #118 from clobrano/makefile-cleanup-bundle-0
openshift-merge-bot[bot] Feb 1, 2024
aaf0614
Github workflow to commit Red Hat Community bundle in CI
clobrano Feb 1, 2024
d734241
Make OCP_VERSION configurable
clobrano Feb 7, 2024
9bdae17
Replace OKD with RH Community
clobrano Feb 13, 2024
131b32f
Merge pull request #122 from clobrano/automate-community-release-0
openshift-merge-bot[bot] Feb 13, 2024
95eb835
Allow to create a test bundle for development
clobrano Feb 16, 2024
8c77b38
Remove catalog creation from Makefile
clobrano Feb 16, 2024
5ef777e
Merge pull request #127 from clobrano/remove-build-catalog-target-0
openshift-merge-bot[bot] Feb 19, 2024
9955b60
Merge pull request #126 from clobrano/allow-bundle-creation-with-chan…
openshift-merge-bot[bot] Feb 19, 2024
bda4d9b
Fix typo in replaces field variable
clobrano Feb 20, 2024
557cbec
Adopt reusable workflow to release RH community bundle
clobrano Feb 20, 2024
8e3e24b
Merge pull request #128 from clobrano/automate-rh-community-bundle-1
openshift-merge-bot[bot] Feb 22, 2024
1ba63fd
Add Makefile recipe to build a file-based catalog
clobrano Feb 8, 2024
84e63f8
Merge pull request #123 from clobrano/build-file-based-catalog-0
clobrano Mar 5, 2024
db21101
Fix verify-previous-version Makefile target
clobrano Mar 11, 2024
efbdc73
Merge pull request #131 from clobrano/fix-makefile-previous-version-c…
clobrano Mar 11, 2024
07aba94
Fix Go install in Dockerfile
clobrano Mar 14, 2024
8d23e21
Merge pull request #133 from clobrano/dockerfile-golang-install-0
openshift-merge-bot[bot] Mar 15, 2024
508bdab
Update OKD Community bundle PR automation
clobrano May 2, 2024
85bd965
Update release workflow
clobrano Aug 6, 2024
cb97a29
Let the CI set OCP_VERSION
clobrano Aug 7, 2024
a7b21a5
Update OKD Community bundle PR automation
clobrano Aug 9, 2024
9bc63e2
Add missing BLUE_ICON_PATH variable definition
clobrano Aug 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 5 additions & 43 deletions .github/workflows/post-submit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,26 @@ permissions:

jobs:
push_to_registry:
name: Build and push images to quay.io/medik8s
name: Build and push unversioned images to quay.io/medik8s
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'

- name: Log in to Quay.io
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io

- name: Build and push CSV 0.0.1 + latest images, for pushes
if: ${{ github.ref_type != 'tag' }}
- name: Build and push CSV version v0.0.1 with latest images
run: make bundle container-build container-push

- name: Build and push versioned based on tag
if: ${{ github.ref_type == 'tag' }}
# remove leading 'v' from tag!
run: export VERSION=$(echo $GITHUB_REF_NAME | sed 's/v//') && make bundle container-build container-push

- name: Create release with manifests
if: ${{ github.ref_type == 'tag' }}
# https://github.com/marketplace/actions/github-release-create-update-and-upload-assets
uses: meeDamian/github-release@2.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
body: |
# Machine Deletion Remediation operator ${{ github.ref_name }}

## Notable Changes

* TODO

## Release Artifacts

### Images

* Operator: quay.io/medik8s/machine-deletion-remediation-operator:${{ github.ref_name }}
* Bundle: quay.io/medik8s/machine-deletion-remediation-operator-bundle:${{ github.ref_name }}
* Catalog aka Index: quay.io/medik8s/machine-deletion-remediation-operator-catalog:${{ github.ref_name }}

### Source code and OLM manifests

Please find the source code and the OLM manifests in the `Assets` section below.

gzip: folders
files: >
Manifests:bundle/


100 changes: 100 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Release
on:
workflow_dispatch:
inputs:
operation:
description: "The operation to perform."
required: true
type: choice
default: "build_and_push_images"
options:
- build_and_push_images
- create_okd_release_pr
version:
description: "The version to release, without the leading `v`"
required: true
previous_version:
description: "The previous version, used for the CVS's `replaces` field, without the leading `v`"
required: true
ocp_version:
description: "The target OCP version for the release (mandatory for create_okd_release_pr option)"
required: true

permissions:
contents: write

jobs:
push_to_registry:
if: ${{ inputs.operation == 'build_and_push_images' }}
name: Build and push versioned images to quay.io/medik8s
runs-on: ubuntu-22.04
env:
VERSION: ${{ inputs.version }}
PREVIOUS_VERSION: ${{ inputs.previous_version }}
OCP_VERSION: ${{ inputs.ocp_version }}
steps:
- name: Log inputs
run: |
echo "Building version: ${VERSION},"
echo "which replaces version: ${PREVIOUS_VERSION}."

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Log in to Quay.io
uses: docker/login-action@v3
with:
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io

- name: Build and push versioned CSV and images
run: VERSION=$VERSION PREVIOUS_VERSION=$PREVIOUS_VERSION make container-build container-push

- name: Create release with manifests
# https://github.com/marketplace/actions/github-release-create-update-and-upload-assets
uses: meeDamian/github-release@2.0
with:
tag: v${{ inputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
body: |
# Machine Deletion Remediation operator v${{ inputs.version }}

## Notable Changes

* TODO

## Release Artifacts

### Images

* Operator: quay.io/medik8s/machine-deletion-remediation-operator:${{ inputs.version }}
* Bundle: quay.io/medik8s/machine-deletion-remediation-operator-bundle:${{ inputs.version }}
* Catalog aka Index: quay.io/medik8s/machine-deletion-remediation-operator-catalog:${{ inputs.version }}

### Source code and OLM manifests

Please find the source code and the OLM manifests in the `Assets` section below.

gzip: folders
files: >
Manifests:bundle/

create_okd_release_pr:
if: inputs.operation == 'create_okd_release_pr'
uses: medik8s/.github/.github/workflows/release_community_bundle_parametric.yaml@main
secrets: inherit
with:
version: ${{ inputs.version }}
previous_version: ${{ inputs.previous_version }}
ocp_version: ${{ inputs.ocp_version }}
community: 'OKD'
make_targets: "bundle-community-okd"
78 changes: 51 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ GOIMPORTS_VERSION ?= v0.17.0
# Sort-imports versions at https://github.com/slintes/sort-imports/releases
SORT_IMPORTS_VERSION = v0.2.1

# OCP Version: for OKD bundle community
OCP_VERSION = 4.12

# update for major version updates to YQ_VERSION! see https://github.com/mikefarah/yq
YQ_API_VERSION = v4
YQ_VERSION = v4.44.2

BLUE_ICON_PATH = "./config/assets/medik8s_blue_icon.png"
# VERSION defines the project version for the bundle.
# Update this value when you upgrade the version of your project.
# To re-generate a bundle for another specific version without changing the standard setup, you can:
Expand Down Expand Up @@ -69,7 +67,7 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# IMAGE_REGISTRY used to indicate the registery/group for the operator, bundle and catalog
# IMAGE_REGISTRY used to indicate the registery/group for the operator and bundle
IMAGE_REGISTRY ?= quay.io/medik8s
export IMAGE_REGISTRY

Expand All @@ -82,9 +80,9 @@ endif
export IMAGE_TAG

# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
# This variable is used to construct full image tags for bundle and catalog images.
# This variable is used to construct full image tags for bundle images.
#
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
# For example, running 'make bundle-build bundle-push' will build and push the bundle image
# medik8s/machine-deletion-remediation-bundle:$(IMAGE_TAG) and medik8s/machine-deletion-remediation-catalog:$(IMAGE_TAG).
IMAGE_TAG_BASE ?= $(IMAGE_REGISTRY)/$(OPERATOR_NAME)

Expand Down Expand Up @@ -164,7 +162,7 @@ fix-imports: sort-imports ## Sort imports
$(SORT_IMPORTS) -w .

.PHONY: verify-no-changes
verify-no-changes: ## verify no there are no un-staged changes
verify-no-changes: bundle-reset ## verify no there are no un-staged changes and remove unwanted changes to bundle
./hack/verify-diff.sh

# Run tests
Expand Down Expand Up @@ -305,7 +303,7 @@ bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metada
$(MAKE) bundle-validate

## Some addition to bundle creation in the bundle
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ./config/assets/medik8s_blue_icon.png)
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ${BLUE_ICON_PATH})
export ICON_BASE64 ?= ${DEFAULT_ICON_BASE64}
export CSV="./bundle/manifests/$(OPERATOR_NAME).clusterserviceversion.yaml"

Expand All @@ -317,6 +315,14 @@ bundle-update: verify-previous-version ## Update CSV fields and validate the bun
sed -r -i "s|replaces: .*|replaces: machine-deletion-remediation.v${PREVIOUS_VERSION}|;" ${CSV}
$(MAKE) bundle-validate

.PHONY: bundle-reset
bundle-reset: ## Revert all version or build date related changes
VERSION=${DEFAULT_VERSION} IMG=$(IMAGE_TAG_BASE)-operator:latest; $(MAKE) manifests bundle
sed -r -i "s|containerImage: .*|containerImage: \"\"|;" ${CSV}
sed -r -i "s|createdAt: .*|createdAt: \"\"|;" ${CSV}
sed -r -i "s|base64data:.*|base64data: base64EncodedIcon|;" ${CSV}
sed -r -i "s|replaces: .*|replaces: machine-deletion-remediation.v${DEFAULT_VERSION}|;" ${CSV}

.PHONY: verify-previous-version
verify-previous-version: ## Verifies that PREVIOUS_VERSION variable is set
@if [ $(VERSION) != $(DEFAULT_VERSION) ] && \
Expand All @@ -325,8 +331,8 @@ verify-previous-version: ## Verifies that PREVIOUS_VERSION variable is set
exit 1; \
fi

.PHONY: bundle-community
bundle-community: ## Update displayName field in the bundle's CSV
.PHONY: bundle-community-okd
bundle-community-okd: bundle ## Update displayName field in the bundle's CSV
sed -r -i "s|displayName: Machine Deletion Remediation operator.*|displayName: Machine Deletion Remediation Operator - Community Edition|;" ${CSV}
$(MAKE) add-ocp-annotations
echo -e "\n # Annotations for OCP\n com.redhat.openshift.versions: \"v${OCP_VERSION}\"" >> bundle/metadata/annotations.yaml
Expand Down Expand Up @@ -367,22 +373,40 @@ bundle-run: operator-sdk ## Run bundle image
bundle-cleanup: operator-sdk ## Remove bundle installed via bundle-run
$(OPERATOR_SDK) -n $(BUNDLE_RUN_NAMESPACE) cleanup $(OPERATOR_NAME)

# Build a file-based catalog image
# https://docs.openshift.com/container-platform/4.14/operators/admin/olm-managing-custom-catalogs.html#olm-managing-custom-catalogs-fb
# NOTE: CATALOG_DIR and CATALOG_DOCKERFILE items won't be deleted in case of recipe's failure
CATALOG_DIR := catalog
CATALOG_DOCKERFILE := ${CATALOG_DIR}.Dockerfile
CATALOG_INDEX := $(CATALOG_DIR)/index.yaml

.PHONY: add_channel_entry_for_the_bundle
add_channel_entry_for_the_bundle:
@echo "---" >> ${CATALOG_INDEX}
@echo "schema: olm.channel" >> ${CATALOG_INDEX}
@echo "package: ${OPERATOR_NAME}" >> ${CATALOG_INDEX}
@echo "name: ${CHANNELS}" >> ${CATALOG_INDEX}
@echo "entries:" >> ${CATALOG_INDEX}
@echo " - name: ${OPERATOR_NAME}.v${VERSION}" >> ${CATALOG_INDEX}

# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
# These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG)

# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
endif

# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
.PHONY: catalog-build
catalog-build: opm ## Build a catalog image.
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
catalog-build: opm ## Build a file-based catalog image.
# Remove the catalog directory and Dockerfile if they exist
-rm -r ${CATALOG_DIR} ${CATALOG_DOCKERFILE}
@mkdir -p ${CATALOG_DIR}
$(OPM) generate dockerfile ${CATALOG_DIR}
$(OPM) init ${OPERATOR_NAME} \
--default-channel=${CHANNELS} \
--description=./README.md \
--icon=${BLUE_ICON_PATH} \
--output yaml \
> ${CATALOG_INDEX}
$(OPM) render ${BUNDLE_IMG} --output yaml >> ${CATALOG_INDEX}
$(MAKE) add_channel_entry_for_the_bundle
$(OPM) validate ${CATALOG_DIR}
docker build . -f ${CATALOG_DOCKERFILE} -t ${CATALOG_IMG}
# Clean up the catalog directory and Dockerfile
rm -r ${CATALOG_DIR} ${CATALOG_DOCKERFILE}

.PHONY: catalog-push
catalog-push: ## Push a catalog image.
Expand All @@ -392,8 +416,8 @@ catalog-push: ## Push a catalog image.

.PHONY: container-build
container-build: ## Build containers
make docker-build bundle-build
make docker-build bundle-build catalog-build catalog-push

.PHONY: container-push
container-push: ## Push containers (NOTE: catalog can't be build before bundle was pushed)
make docker-push bundle-push catalog-build catalog-push
container-push: ## Push containers
make docker-push bundle-push
Loading