Skip to content

Commit a2d3451

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 a2d3451

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +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: "${{ github.ref_name }}-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: ""
445-
DEFAULT_CHANNEL: "stable"
446-
CHANNELS: "stable"
447453
run: |
448454
make push-bundle-image

Makefile

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ 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+
70+
BUNDLE_IMAGE = $(BUNDLE_IMAGE_NAME):$(BUNDLE_VERSION)
71+
BUNDLE_IMAGE_GIT := $(if $(BUNDLE_GIT_TAG),$(BUNDLE_IMAGE_NAME):$(BUNDLE_GIT_TAG))
6372

6473
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6574
ifeq (,$(shell go env GOBIN))
@@ -126,16 +135,27 @@ bundle: manifests install-tools
126135
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
127136
operator-sdk bundle validate ./bundle
128137

138+
# Update the bundle CSV file with operator image tag
139+
update-bundle-csv:
140+
@echo "Updating GPU operator image in $(BUNDLE_CSV_FILE) to $(OPERATOR_IMAGE_NAME):$(OPERATOR_VERSION)"
141+
@sed -i.bak -e 's|ghcr.io/nvidia/gpu-operator:[^ "]*|$(OPERATOR_IMAGE_NAME):$(OPERATOR_VERSION)|g' $(BUNDLE_CSV_FILE)
142+
@rm -f $(BUNDLE_CSV_FILE).bak
143+
@echo "Bundle CSV updated successfully"
144+
129145
# Build the bundle image.
130-
build-bundle-image:
146+
build-bundle-image: update-bundle-csv
131147
$(DOCKER) build \
132148
--build-arg DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) \
133149
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
134-
-f docker/bundle.Dockerfile -t $(BUNDLE_IMAGE) .
150+
-f docker/bundle.Dockerfile \
151+
-t $(BUNDLE_IMAGE) \
152+
$(if $(BUNDLE_IMAGE_GIT),-t $(BUNDLE_IMAGE_GIT)) \
153+
.
135154

136155
# Push the bundle image.
137156
push-bundle-image: build-bundle-image
138157
$(DOCKER) push $(BUNDLE_IMAGE)
158+
$(if $(BUNDLE_IMAGE_GIT),$(DOCKER) push $(BUNDLE_IMAGE_GIT))
139159

140160
# Define local and dockerized golang targets
141161

0 commit comments

Comments
 (0)