Skip to content

Commit

Permalink
OperatorHub Release CLI / Moving OperatorHub release to Buildkite (#6281
Browse files Browse the repository at this point in the history
)

* Adds operatorhub release CLI
* Moves operatorhub release to Buildkite
---------
Signed-off-by: Michael Montgomery <[email protected]>
  • Loading branch information
naemono authored Feb 27, 2023
1 parent 8bfeaa9 commit 6e5d6e1
Show file tree
Hide file tree
Showing 22 changed files with 3,826 additions and 661 deletions.
50 changes: 50 additions & 0 deletions .buildkite/pipeline-release-operatorhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

agents:
image: docker.elastic.co/ci-agent-images/cloud-k8s-operator/buildkite-agent:latest
cpu: "4"
memory: "2G"

steps:

- group: redhat-release

steps:

- label: "build operatorhub tool"
key: "build-operatorhub-tool"
commands:
- cd hack/operatorhub
- make build
- chmod u+x bin/operatorhub
- buildkite-agent artifact upload "bin/operator*"

- label: "Generate CRDs"
key: "generate-crds"
depends_on:
- "build-operatorhub-tool"
commands:
- make generate-crds-v1
artifact_paths:
- "config/*.yaml"

- label: "run container push"
key: "redhat-container-push"
depends_on:
- "generate-crds"
commands:
- buildkite-agent artifact download "bin/operator*" /usr/local/
- /usr/local/bin/operatorhub container push --dry-run=false

- label: "run container preflight"
key: "redhat-preflight"
depends_on:
- "redhat-container-push"
commands:
- .buildkite/scripts/operatorhub/operations.sh preflight

- label: "run remaining release"
key: "redhat-release"
depends_on:
- "redhat-preflight"
commands:
- .buildkite/scripts/operatorhub/operations.sh release
9 changes: 9 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@ steps:
if: build.message == "release all helm charts"
commands:
- buildkite-agent pipeline upload .buildkite/pipeline-helm-release-all.yml

- group: redhat-release

steps:

- label: "redhat operatorhub"
if: build.message == "run operatorhub release"
commands:
- buildkite-agent pipeline upload .buildkite/pipeline-release-operatorhub.yml
74 changes: 74 additions & 0 deletions .buildkite/scripts/operatorhub/operations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License 2.0;
# you may not use this file except in compliance with the Elastic License 2.0.

# Required environment variables:
# For 'preflight' command:
# OHUB_TAG

set -euo pipefail

preflight() {
if [[ -z ${OHUB_TAG} ]]; then
echo "OHUB_TAG environment variable is required"
exit 1
fi

OHUB_API_KEY="$(vault read -field=api-key secret/ci/elastic-cloud-on-k8s/operatorhub-release-redhat)"
export OHUB_API_KEY
OHUB_PROJECT_ID="$(vault read -field=project-id secret/ci/elastic-cloud-on-k8s/operatorhub-release-redhat)"
export OHUB_PROJECT_ID

curl -s -G "https://catalog.redhat.com/api/containers/v1/projects/certification/id/$OHUB_PROJECT_ID/images?filter=repositories.tags.name==$OHUB_TAG" -H "X-API-KEY: $OHUB_API_KEY" > /tmp/redhat.json

# The following command will fail if no data was returned, so preflight will not run if it's already run
jq -e '.data[0]' /tmp/redhat.json && exit 0

# Install known working version of preflight tool.
curl -sL -o /tmp/preflight https://github.com/redhat-openshift-ecosystem/openshift-preflight/releases/download/1.2.1/preflight-linux-amd64
chmod u+x /tmp/preflight

# Pull authentication information for quay.io from vault
vault read -format=json -field=data secret/ci/elastic-cloud-on-k8s/operatorhub-release-preflight > /tmp/auth.json

/tmp/preflight check container "quay.io/redhat-isv-containers/$OHUB_PROJECT_ID:$OHUB_TAG" --pyxis-api-token="$OHUB_API_KEY" --certification-project-id="$OHUB_PROJECT_ID" --submit -d /tmp/auth.json
}

release() {
buildkite-agent artifact download "bin/operator*" /usr/local/
buildkite-agent artifact download "config/*.yaml" .
cd hack/operatorhub
/usr/local/bin/operatorhub container publish --dry-run=false
/usr/local/bin/operatorhub generate-manifests --yaml-manifest=../../config/crds.yaml --yaml-manifest=../../config/operator.yaml
/usr/local/bin/operatorhub bundle generate --dir="$(pwd)"
/usr/local/bin/operatorhub bundle create-pr --dir="$(pwd)"
}

usage() {
echo "Usage: $0 preflight|release"
echo "preflight: Runs the operatorhub preflight operations in buildkite"
echo "release: Runs the last steps of the operatorhub release steps in buildkite"
exit 2
}

if [[ "$#" -ne 1 ]]; then
usage
fi

case "$1" in
preflight)
preflight
;;
release)
release
;;
help)
usage
;;
*)
echo "Unknown action '$1'"
usage
;;
esac
6 changes: 6 additions & 0 deletions hack/operatorhub/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License 2.0;
# you may not use this file except in compliance with the Elastic License 2.0.

build:
go build -o bin/operatorhub main.go
Loading

0 comments on commit 6e5d6e1

Please sign in to comment.