Skip to content

Commit 2b77660

Browse files
Shiva Kumarshivakunv
authored andcommitted
Tag git commit sha with bundle image
Signed-off-by: Shiva Kumar (SW-CLOUD) <[email protected]>
1 parent e0ba4ab commit 2b77660

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,17 @@ jobs:
438438
registry: ghcr.io
439439
username: ${{ github.actor }}
440440
password: ${{ secrets.GITHUB_TOKEN }}
441+
- name: Set environment variables
442+
id: vars
443+
run: |
444+
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
441445
- name: Build bundle-image
442446
env:
443-
BUNDLE_IMAGE: "ghcr.io/nvidia/gpu-operator/gpu-operator-bundle:${{ github.ref_name }}-latest"
447+
BUNDLE_IMAGE_NAME: "ghcr.io/nvidia/gpu-operator/gpu-operator-bundle"
448+
BUNDLE_VERSION: "bundlecommitsha-latest"
449+
BUNDLE_GIT_TAG: "${{ env.COMMIT_SHORT_SHA }}"
450+
OPERATOR_IMAGE_NAME: "ghcr.io/nvidia/gpu-operator"
451+
OPERATOR_VERSION: "${{ env.COMMIT_SHORT_SHA }}"
444452
VERSION: ""
445453
DEFAULT_CHANNEL: "stable"
446454
CHANNELS: "stable"

Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
5959

6060
# BUNDLE_IMAGE defines the image:tag used for the bundle.
6161
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMAGE=<some-registry>/<project-name-bundle>:<tag>)
62-
BUNDLE_IMAGE ?= gpu-operator-bundle:$(VERSION)
62+
BUNDLE_IMAGE_NAME ?= gpu-operator-bundle
63+
BUNDLE_VERSION ?= $(VERSION)
64+
BUNDLE_GIT_TAG ?= $(GIT_COMMIT)
65+
OPERATOR_IMAGE_NAME ?= gpu-operator
66+
OPERATOR_VERSION ?= $(VERSION)
67+
BUNDLE_CSV_FILE ?= bundle/manifests/gpu-operator-certified.clusterserviceversion.yaml
68+
69+
BUNDLE_IMAGE := $(BUNDLE_IMAGE_NAME):$(BUNDLE_VERSION)
70+
BUNDLE_IMAGE_GIT := $(if $(BUNDLE_GIT_TAG),$(BUNDLE_IMAGE_NAME):$(BUNDLE_GIT_TAG))
6371

6472
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6573
ifeq (,$(shell go env GOBIN))
@@ -126,16 +134,26 @@ bundle: manifests install-tools
126134
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
127135
operator-sdk bundle validate ./bundle
128136

137+
# Update the bundle CSV file with operator image tag
138+
update-bundle-csv:
139+
@echo "Updating GPU operator image in $(BUNDLE_CSV_FILE) to $(OPERATOR_IMAGE_NAME):$(OPERATOR_VERSION)"
140+
@sed -i'' -e 's|ghcr.io/nvidia/gpu-operator:[^ "]*|$(OPERATOR_IMAGE_NAME):$(OPERATOR_VERSION)|g' $(BUNDLE_CSV_FILE)
141+
@echo "Bundle CSV updated successfully"
142+
129143
# Build the bundle image.
130-
build-bundle-image:
144+
build-bundle-image: update-bundle-csv
131145
$(DOCKER) build \
132146
--build-arg DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) \
133147
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
134-
-f docker/bundle.Dockerfile -t $(BUNDLE_IMAGE) .
148+
-f docker/bundle.Dockerfile \
149+
-t $(BUNDLE_IMAGE) \
150+
$(if $(BUNDLE_IMAGE_GIT),-t $(BUNDLE_IMAGE_GIT)) \
151+
.
135152

136153
# Push the bundle image.
137154
push-bundle-image: build-bundle-image
138155
$(DOCKER) push $(BUNDLE_IMAGE)
156+
$(if $(BUNDLE_IMAGE_GIT),$(DOCKER) push $(BUNDLE_IMAGE_GIT))
139157

140158
# Define local and dockerized golang targets
141159

0 commit comments

Comments
 (0)