Skip to content

Commit

Permalink
build: added new rook bundle creation script
Browse files Browse the repository at this point in the history
Added Dockerfile to create rook-ceph-operator-bundle under the rook repo.
Updated the Makefile to have the 'bundle' command, that reference the 'gen-bundle.sh'
script under `build/bundle`

Signed-off-by: Nikhil-Ladha <nikhilladha1999@gmail.com>
  • Loading branch information
Nikhil-Ladha committed Mar 5, 2024
1 parent 7864271 commit 320df87
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Dockerfile.bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM scratch

# Core bundle labels.
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=rook-ceph-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha

# Copy files to locations specified by labels.
COPY build/csv/ceph /manifests/
COPY build/bundle/annotations.yaml /metadata/
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ csv: export NO_OB_OBC_VOL_GEN=true
csv: csv-clean crds ## Generate a CSV file for OLM.
$(MAKE) -C images/ceph csv

bundle:
@echo generate rook bundle
@build/bundle/gen-bundle.sh

csv-clean: ## Remove existing OLM files.
@$(MAKE) -C images/ceph csv-clean

Expand Down
6 changes: 6 additions & 0 deletions build/bundle/annotations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
annotations:
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
operators.operatorframework.io.bundle.manifests.v1: manifests/
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: rook-ceph-operator
operators.operatorframework.io.bundle.channels.v1: alpha
8 changes: 8 additions & 0 deletions build/bundle/gen-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e

source "build/common.sh"

${DOCKERCMD} build --platform="${GOOS}"/"${GOARCH}" --no-cache -t "$BUNDLE_IMAGE" -f Dockerfile.bundle .
echo
echo "Run '${DOCKERCMD} push ${BUNDLE_IMAGE}' to push operator bundle to image registry."
20 changes: 19 additions & 1 deletion build/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,31 @@ set -u
BUILD_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd -P)
SHA256CMD=${SHA256CMD:-shasum -a 256}

DOCKERCMD=${DOCKERCMD:-docker}
DOCKERCMD=""

if [ -z "$DOCKERCMD" ]; then
DOCKERCMD=$(command -v docker || echo "")
fi
if [ -z "$DOCKERCMD" ]; then
DOCKERCMD=$(command -v podman || echo "")
fi

if [ -z "$DOCKERCMD" ]; then
echo -e '\033[1;31m' "podman or docker not found on system" '\033[0m'
exit 1
fi

export scriptdir
scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export OUTPUT_DIR=${BUILD_ROOT}/_output
export WORK_DIR=${BUILD_ROOT}/.work
export CACHE_DIR=${BUILD_ROOT}/.cache
export GOOS
GOOS=$(go env GOOS)
export GOARCH
GOARCH=$(go env GOARCH)
DEFAULT_BUNDLE_IMAGE=rook/rook-ceph-operator-bundle:"${VERSION}"
BUNDLE_IMAGE="${BUNDLE_IMAGE:-${DEFAULT_BUNDLE_IMAGE}}"

function ver() {
local full_ver maj min bug build
Expand Down
7 changes: 3 additions & 4 deletions build/csv/csv-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ YQ_CMD_DELETE=("$yq" delete -i)
YQ_CMD_MERGE_OVERWRITE=("$yq" merge --inplace --overwrite --prettyPrint)
YQ_CMD_MERGE=("$yq" merge --arrays=append --inplace)
YQ_CMD_WRITE=("$yq" write --inplace -P)
CSV_FILE_NAME="../../build/csv/ceph/$PLATFORM/manifests/rook-ceph.clusterserviceversion.yaml"
CSV_FILE_NAME="../../build/csv/ceph/$PLATFORM/manifests/rook-ceph-operator.clusterserviceversion.yaml"
CEPH_EXTERNAL_SCRIPT_FILE="../../deploy/examples/create-external-cluster-resources.py"
ASSEMBLE_FILE_COMMON="../../deploy/olm/assemble/metadata-common.yaml"
ASSEMBLE_FILE_OCP="../../deploy/olm/assemble/metadata-ocp.yaml"
Expand All @@ -23,7 +23,7 @@ ASSEMBLE_FILE_OCP="../../deploy/olm/assemble/metadata-ocp.yaml"
#############

function generate_csv() {
kubectl kustomize ../../deploy/examples/ | "$operator_sdk" generate bundle --package="rook-ceph" --output-dir="../../build/csv/ceph/$PLATFORM" --extra-service-accounts=rook-ceph-system,rook-csi-rbd-provisioner-sa,rook-csi-rbd-plugin-sa,rook-csi-cephfs-provisioner-sa,rook-csi-nfs-provisioner-sa,rook-csi-nfs-plugin-sa,rook-csi-cephfs-plugin-sa,rook-ceph-system,rook-ceph-rgw,rook-ceph-purge-osd,rook-ceph-osd,rook-ceph-mgr,rook-ceph-cmd-reporter
kubectl kustomize ../../deploy/examples/ | "$operator_sdk" generate bundle --package="rook-ceph-operator" --output-dir="../../build/csv/ceph/$PLATFORM" --extra-service-accounts=rook-ceph-system,rook-csi-rbd-provisioner-sa,rook-csi-rbd-plugin-sa,rook-csi-cephfs-provisioner-sa,rook-csi-nfs-provisioner-sa,rook-csi-nfs-plugin-sa,rook-csi-cephfs-plugin-sa,rook-ceph-system,rook-ceph-rgw,rook-ceph-purge-osd,rook-ceph-osd,rook-ceph-mgr,rook-ceph-cmd-reporter

# cleanup to get the expected state before merging the real data from assembles
"${YQ_CMD_DELETE[@]}" "$CSV_FILE_NAME" 'spec.icon[*]'
Expand All @@ -48,10 +48,9 @@ function generate_csv() {
fi

sed -i 's/image: rook\/ceph:.*/image: {{.RookOperatorImage}}/g' "$CSV_FILE_NAME"
sed -i 's/name: rook-ceph.v.*/name: rook-ceph.v{{.RookOperatorCsvVersion}}/g' "$CSV_FILE_NAME"
sed -i 's/name: rook-ceph.v.*/name: rook-ceph-operator.v{{.RookOperatorCsvVersion}}/g' "$CSV_FILE_NAME"
sed -i 's/version: 0.0.0/version: {{.RookOperatorCsvVersion}}/g' "$CSV_FILE_NAME"

mv "$CSV_FILE_NAME" "../../build/csv/"
mv "../../build/csv/ceph/$PLATFORM/manifests/"* "../../build/csv/ceph/"
rm -rf "../../build/csv/ceph/$PLATFORM"
}
Expand Down

0 comments on commit 320df87

Please sign in to comment.