Skip to content

Commit

Permalink
Merge pull request #55 from ArangoGutierrez/bundle
Browse files Browse the repository at this point in the history
Build bundle image
  • Loading branch information
ArangoGutierrez authored Aug 16, 2024
2 parents 6c7b993 + 618fd4a commit 8a01783
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 19 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ jobs:
fi
echo "PUSH_ON_BUILD=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
echo "BUILD_MULTI_ARCH_IMAGES=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
- name: Extract branch name for push events
if: github.event_name == 'push'
id: extract_branch
run: |
BRANCH=${GITHUB_REF#refs/heads/}
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand All @@ -70,3 +76,52 @@ jobs:
run: |
echo "${VERSION}"
make -f deployments/container/Makefile build
build-bundle:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
name: Check out code
- name: Calculate build vars
id: vars
run: |
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
echo "LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}')" >> $GITHUB_ENV
REPO_FULL_NAME="${{ github.event.pull_request.head.repo.full_name }}"
echo "${REPO_FULL_NAME}"
echo "LABEL_IMAGE_SOURCE=https://github.com/${REPO_FULL_NAME}" >> $GITHUB_ENV
GENERATE_ARTIFACTS="false"
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
GENERATE_ARTIFACTS="false"
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then
GENERATE_ARTIFACTS="true"
elif [[ "${{ github.event_name }}" == "push" ]]; then
GENERATE_ARTIFACTS="true"
fi
echo "PUSH_ON_BUILD=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
echo "BUILD_MULTI_ARCH_IMAGES=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
- name: Extract branch name for push events
if: github.event_name == 'push'
id: extract_branch
run: |
BRANCH=${GITHUB_REF#refs/heads/}
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
env:
BUNDLE_IMAGE: ghcr.io/${LOWERCASE_REPO_OWNER}/k8s-nim-operator:bundle-lastest-${{ github.ref }}
VERSION: '' # Until we cut a release, Version will be null
run: |
echo "${VERSION}"
sed -i "s|nvcr.io/nvidia/cloud-native/k8s-nim-operator:v0.1.0|${BUNDLE_IMAGE}|g" bundle/manifests/k8s-nim-operator.clusterserviceversion.yaml
make -f deployments/container/Makefile build-bundle
22 changes: 5 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# BUNDLE_IMAGE defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMAGE=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMAGE ?= nvcr.io/nvidia/cloud-native/nim-operator-bundle:$(VERSION)

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
Expand Down Expand Up @@ -150,22 +146,14 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi
$(KUSTOMIZE) build config/default > dist/install.yaml

# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
.PHONY: bundle bundle-validate
bundle: manifests install-tools
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(vVERSION) $(BUNDLE_METADATA_OPTS)

bundle-validate:
operator-sdk bundle validate ./bundle

# Build the bundle image.
build-bundle-image:
$(CONTAINER_TOOL) build \
--build-arg VERSION="" \
--build-arg DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
-f bundle.Dockerfile -t $(BUNDLE_IMAGE) .

# Push the bundle image.
push-bundle-image: build-bundle-image
$(CONTAINER_TOOL) push $(BUNDLE_IMAGE)

##@ Deployment

ifndef ignore-not-found
Expand Down
40 changes: 38 additions & 2 deletions deployments/container/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,30 @@ IMAGE_TAG ?= $(IMAGE_VERSION)
IMAGE = $(IMAGE_NAME):$(IMAGE_TAG)
DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile

# BUNDLE_IMAGE defines the image:tag used for the bundle.
BUNDLE_IMAGE_NAME ?= nvcr.io/nvidia/cloud-native/nim-operator-bundle
BUNDLE_DOCKERFILE = $(CURDIR)/deployments/container/bundle.Dockerfile

IMAGE_EXTRA_TAG_NAMES ?= ${BRANCH} $(VERSION)
BUNDLE_EXTRA_TAG_NAMES ?= bundle-latest-${BRANCH} $(VERSION)
IMAGE_EXTRA_TAGS := $(foreach tag,$(IMAGE_EXTRA_TAG_NAMES),$(IMAGE_NAME):$(tag))
BUNDLE_EXTRA_TAGS := $(foreach tag,$(BUNDLE_EXTRA_TAG_NAMES),$(BUNDLE_IMAGE_NAME):$(tag))

OUT_IMAGE_NAME ?= $(IMAGE_NAME)
OUT_IMAGE_VERSION ?= $(IMAGE_VERSION)
OUT_IMAGE_TAG = $(OUT_IMAGE_VERSION)
OUT_IMAGE = $(OUT_IMAGE_NAME):$(OUT_IMAGE_TAG)

# DEFAULT_CHANNEL defines the default channel used in the bundle.
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
# To re-generate a bundle for any other default channel without changing the default setup, you can:
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
ifneq ($(origin DEFAULT_CHANNEL), alpha)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

ifneq ($(BUILD_MULTI_ARCH_IMAGES),true)
include $(CURDIR)/deployments/container/native-only.mk
else
Expand All @@ -56,13 +75,13 @@ push-$(DEFAULT_PUSH_TARGET): push-short
endif

# Use a generic build target to build the relevant images
.PHONY: build
.PHONY: build build-bundle
build:
DOCKER_BUILDKIT=1 \
$(DOCKER) $(BUILDX) build --pull \
$(DOCKER_BUILD_OPTIONS) \
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
--tag $(IMAGE) \
$(foreach tag,$(IMAGE_EXTRA_TAGS),-t $(tag)) \
--build-arg VERSION="$(VERSION)" \
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
-f $(DOCKERFILE) \
Expand All @@ -78,3 +97,20 @@ push-short:
$(REGCTL) \
image copy \
$(IMAGE) $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)
build-bundle:
DOCKER_BUILDKIT=1 \
$(DOCKER) $(BUILDX) build --pull \
$(DOCKER_BUILD_OPTIONS) \
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
$(foreach tag,$(BUNDLE_EXTRA_TAGS),-t $(tag)) \
--build-arg VERSION="$(VERSION)" \
--build-arg DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) \
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
-f $(BUNDLE_DOCKERFILE) \
$(CURDIR)

# Push the bundle image.
push-bundle: build-bundle-image
$(REGCTL) \
image copy \
$(BUNDLE_IMAGE) $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)
File renamed without changes.

0 comments on commit 8a01783

Please sign in to comment.