From 24cfe0bddf3f0d18c7bcbbbacca8248bee8f32a4 Mon Sep 17 00:00:00 2001 From: Julien Pinsonneau Date: Mon, 24 Apr 2023 12:20:36 +0200 Subject: [PATCH] multi arch builds --- .github/workflows/push_image.yml | 22 ++- .github/workflows/push_image_pr.yml | 22 ++- .github/workflows/release.yml | 27 ++-- .mk/local.mk | 2 +- .mk/shortcuts.mk | 42 +++++ DEVELOPMENT.md | 20 +-- Dockerfile | 11 +- Makefile | 152 ++++++++++++------ ...observ-operator.clusterserviceversion.yaml | 5 + ...observ-operator.clusterserviceversion.yaml | 5 + config/samples/catalog/catalog.yaml | 2 +- hack/test-workflow.sh | 2 +- 12 files changed, 208 insertions(+), 104 deletions(-) create mode 100644 .mk/shortcuts.mk diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml index c0bf2db4b..b95ea8369 100644 --- a/.github/workflows/push_image.yml +++ b/.github/workflows/push_image.yml @@ -4,6 +4,7 @@ on: branches: [ main ] env: + ORG: netobserv REGISTRY_USER: netobserv+github_ci REGISTRY_PASSWORD: ${{ secrets.QUAY_SECRET }} REGISTRY: quay.io/netobserv @@ -25,27 +26,22 @@ jobs: go-version: ${{ matrix.go }} - name: checkout uses: actions/checkout@v3 - - name: build images - run: IMG=${{ env.REGISTRY }}/${{ env.IMAGE }}:main make ci-images-build - - name: podman login to quay.io - uses: redhat-actions/podman-login@v1 + - name: docker login to quay.io + uses: docker/login-action@v2 with: username: ${{ env.REGISTRY_USER }} password: ${{ env.REGISTRY_PASSWORD }} registry: quay.io - name: get short sha run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - name: push to quay.io - id: push-to-quay - uses: redhat-actions/push-to-registry@v2 - with: - image: ${{ env.IMAGE }} - tags: main ${{ env.short_sha }} - registry: ${{ env.REGISTRY }} + - name: build images + run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:main make ci-images-build + - name: push images + run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:main make ci-images-push - name: print image url run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}" - name: build bundle - run: VERSION=main PLG_VERSION=main FLP_VERSION=main BPF_VERSION=main BUNDLE_VERSION=0.0.0-main make bundle bundle-build + run: IMAGE_ORG=${{ env.ORG }} VERSION=main PLG_VERSION=main FLP_VERSION=main BPF_VERSION=main BUNDLE_VERSION=0.0.0-main make bundle bundle-build - name: push bundle to quay.io id: push-bundle uses: redhat-actions/push-to-registry@v2 @@ -54,7 +50,7 @@ jobs: tags: v0.0.0-main registry: ${{ env.REGISTRY }} - name: build catalog - run: BUNDLE_VERSION=0.0.0-main make catalog-build + run: IMAGE_ORG=${{ env.ORG }} BUNDLE_VERSION=0.0.0-main make catalog-build - name: push catalog to quay.io id: push-catalog uses: redhat-actions/push-to-registry@v2 diff --git a/.github/workflows/push_image_pr.yml b/.github/workflows/push_image_pr.yml index 27ad8d828..78e9887d1 100644 --- a/.github/workflows/push_image_pr.yml +++ b/.github/workflows/push_image_pr.yml @@ -4,6 +4,7 @@ on: types: [labeled] env: + ORG: netobserv REGISTRY_USER: netobserv+github_ci REGISTRY: quay.io/netobserv IMAGE: network-observability-operator @@ -27,25 +28,20 @@ jobs: uses: actions/checkout@v3 with: ref: "refs/pull/${{ github.event.number }}/merge" - - name: build images - run: IMG=${{ env.REGISTRY }}/${{ env.IMAGE }}:temp make ci-images-build - - name: podman login to quay.io - uses: redhat-actions/podman-login@v1 + - name: docker login to quay.io + uses: docker/login-action@v2 with: username: ${{ env.REGISTRY_USER }} password: ${{ secrets.QUAY_SECRET }} registry: quay.io - name: get short sha run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - name: push to quay.io - id: push-to-quay - uses: redhat-actions/push-to-registry@v2 - with: - image: ${{ env.IMAGE }} - tags: ${{ env.short_sha }} - registry: ${{ env.REGISTRY }} + - name: build images + run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:temp make ci-images-build + - name: push images + run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:temp make ci-images-push - name: build bundle - run: VERSION=${{ env.short_sha }} PLG_VERSION=main FLP_VERSION=main BPF_VERSION=main BUNDLE_VERSION=0.0.0-${{ env.short_sha }} make bundle shortlived-bundle-build + run: IMAGE_ORG=${{ env.ORG }} VERSION=${{ env.short_sha }} PLG_VERSION=main FLP_VERSION=main BPF_VERSION=main BUNDLE_VERSION=0.0.0-${{ env.short_sha }} make bundle shortlived-bundle-build - name: push bundle to quay.io id: push-bundle uses: redhat-actions/push-to-registry@v2 @@ -54,7 +50,7 @@ jobs: tags: v0.0.0-${{ env.short_sha }} registry: ${{ env.REGISTRY }} - name: build catalog - run: BUNDLE_VERSION=0.0.0-${{ env.short_sha }} make shortlived-catalog-build + run: IMAGE_ORG=${{ env.ORG }} BUNDLE_VERSION=0.0.0-${{ env.short_sha }} make shortlived-catalog-build - name: push catalog to quay.io id: push-catalog uses: redhat-actions/push-to-registry@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d46f208f4..665abb049 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,12 @@ jobs: steps: - name: checkout uses: actions/checkout@v3 + - name: docker login to quay.io + uses: docker/login-action@v2 + with: + username: ${{ env.REGISTRY_USER }} + password: ${{ env.REGISTRY_PASSWORD }} + registry: quay.io - name: validate tag run: | tag=`git describe --exact-match --tags 2> /dev/null` @@ -37,20 +43,13 @@ jobs: with: go-version: ${{ matrix.go }} - name: build operator - run: IMG=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.tag }} make image-build - - name: podman login to quay.io - uses: redhat-actions/podman-login@v1 - with: - username: ${{ env.REGISTRY_USER }} - password: ${{ env.REGISTRY_PASSWORD }} - registry: quay.io - - name: push operator to quay.io - id: push-operator - uses: redhat-actions/push-to-registry@v2 - with: - image: ${{ env.IMAGE }} - tags: ${{ env.tag }} - registry: ${{ env.REGISTRY }} + run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.tag }} make image-build + - name: push operator + run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.tag }} make image-push + - name: build manifest + run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.tag }} make manifest-build + - name: push manifest + run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.tag }} make manifest-push - name: build bundle run: BUNDLE_VERSION=${{ env.tag }} IMAGE_TAG_BASE=${{ env.REGISTRY }}/${{ env.IMAGE }} make bundle-build - name: push bundle to quay.io diff --git a/.mk/local.mk b/.mk/local.mk index 38d64e2f4..479f1278d 100644 --- a/.mk/local.mk +++ b/.mk/local.mk @@ -54,7 +54,7 @@ local-deploy-operator: .PHONY: deploy-kind deploy-kind: generate kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. - cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE} $(SED) -i -r 's~ebpf-agent:.+~ebpf-agent:main~' ./config/manager/manager.yaml $(SED) -i -r 's~flowlogs-pipeline:.+~flowlogs-pipeline:main~' ./config/manager/manager.yaml $(SED) -i -r 's~console-plugin:.+~console-plugin:main~' ./config/manager/manager.yaml diff --git a/.mk/shortcuts.mk b/.mk/shortcuts.mk new file mode 100644 index 000000000..d7898ed62 --- /dev/null +++ b/.mk/shortcuts.mk @@ -0,0 +1,42 @@ +##@ shortcuts helpers +.PHONY: build-image +build-image: image-build ## Build MULTIARCH_TARGETS images + +.PHONY: push-image +push-image: image-push ## Push MULTIARCH_TARGETS images + +.PHONY: build-manifest +build-manifest: manifest-build ## Build MULTIARCH_TARGETS manifest + +.PHONY: push-manifest +push-manifest: manifest-push ## Push MULTIARCH_TARGETS manifest + +.PHONY: images +images: image-build image-push manifest-build manifest-push ## Build and push MULTIARCH_TARGETS images and related manifest + +.PHONY: build-ci-images +build-ci-images: ci-images-build ## Build CI images + +.PHONY: push-ci-images +push-ci-images: ci-images-push ## Push CI images + +.PHONY: ci-images +ci-images: ci-images-build ci-images-push ## Build and push CI images + +.PHONY: build-catalog +build-catalog: catalog-build ## Build a catalog image + +.PHONY: push-catalog +push-catalog: catalog-push ## Push a catalog image + +.PHONY: catalog +catalog: catalog-build catalog-push ## Build and push a catalog image + +.PHONY: build-bundle +build-bundle: bundle-build ## Build the bundle image + +.PHONY: push-bundle +push-bundle: bundle-push ## Push the bundle image + +.PHONY: bundle-all +bundle-all: bundle bundle-build bundle-push ## Build and push the bundle image \ No newline at end of file diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index af445d776..5fc42747b 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -10,10 +10,10 @@ make build test ## Build and deploy a Docker image -A way to test code changes is to build a Docker image from local sources, push it to your own Docker repository, and deploy it to an existing cluster. Do the following, but replace IMG value with your own registry and account: +A way to test code changes is to build a Docker image from local sources, push it to your own Docker repository, and deploy it to an existing cluster. Do the following, but replace IMAGE value with your own registry and account: ```bash -IMG="quay.io/youraccount/network-observability-operator:test" make image-build image-push deploy +IMAGE="quay.io/youraccount/network-observability-operator:test" make image-build image-push deploy ``` After the operator is deployed, set up Loki, which is used to store flows, install a `FlowCollector` custom resource to collect network flows, and optionally install Grafana to provide a user interface and dashboards. @@ -55,7 +55,7 @@ It is recommended to switch to the corresponding release Git tag before deployin When `VERSION` is not provided, it defaults to the latest build on `main` branch. -You can also provide any custom `IMG` to `make deploy`. +You can also provide any custom `IMAGE` to `make deploy`. ## Before commiting, make sure bundle is correct @@ -106,18 +106,18 @@ bundle for local testing, you should execute the following commands: ```bash export USER= -export IMG=quay.io/$USER/network-observability-operator:v0.0.1 -export BUNDLE_IMG=quay.io/$USER/network-observability-operator-bundle:v0.0.1 +export IMAGE=quay.io/$USER/network-observability-operator:v0.0.1 +export BUNDLE_IMAGE=quay.io/$USER/network-observability-operator-bundle:v0.0.1 make image-build image-push -make bundle bundle-build bundle-push +make bundle-push ``` Optionally, you might validate the bundle: ```bash -bin/operator-sdk bundle validate $BUNDLE_IMG +bin/operator-sdk bundle validate $BUNDLE_IMAGE # or for podman -bin/operator-sdk bundle validate -b podman $BUNDLE_IMG +bin/operator-sdk bundle validate -b podman $BUNDLE_IMAGE ``` > Note: the base64 logo can be generated with: `base64 -w 0 `, then manually pasted in the [CSV manifest file](./config/manifests/bases/netobserv-operator.clusterserviceversion.yaml) under `spec.icon`. @@ -127,7 +127,7 @@ bin/operator-sdk bundle validate -b podman $BUNDLE_IMG This mode is recommended to quickly test the operator during its development: ```bash -bin/operator-sdk run bundle $BUNDLE_IMG +bin/operator-sdk run bundle $BUNDLE_IMAGE ``` To cleanup: @@ -144,7 +144,7 @@ operators' catalog and installing/configuring it manually through the UI. First, create and push a catalog image: ```bash -export CATALOG_IMG=quay.io/$USER/network-observability-operator-catalog:v$VERSION +export CATALOG_IMAGE=quay.io/$USER/network-observability-operator-catalog:v$VERSION make catalog-build catalog-push catalog-deploy ``` diff --git a/Dockerfile b/Dockerfile index 810456506..49d2fc4fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,12 @@ +# We do not use --platform feature to auto fill this ARG because of incompatibility between podman and docker +ARG TARGETPLATFORM=linux/amd64 +ARG BUILDPLATFORM=linux/amd64 # Build the manager binary -FROM docker.io/library/golang:1.19 as builder +FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.19 as builder ARG BUILD_VERSION="unknown" +ARG TARGETPLATFORM +ARG TARGETARCH=amd64 WORKDIR /opt/app-root # Copy the go manifests and source @@ -14,10 +19,10 @@ COPY controllers/ controllers/ COPY pkg/ pkg/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags "-X 'main.buildVersion=$BUILD_VERSION' -X 'main.buildDate=`date +%Y-%m-%d\ %H:%M`'" -mod vendor -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags "-X 'main.buildVersion=$BUILD_VERSION' -X 'main.buildDate=`date +%Y-%m-%d\ %H:%M`'" -mod vendor -a -o manager main.go # Create final image from minimal + built binary -FROM registry.access.redhat.com/ubi9/ubi-minimal:9.1 +FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/ubi-minimal:9.1 WORKDIR / COPY --from=builder /opt/app-root/manager . USER 65532:65532 diff --git a/Makefile b/Makefile index 74fbc431e..cfeb98edb 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,28 @@ # VERSION defines the project version for the deploy scripts, not for bundles VERSION ?= main -BUILD_VERSION := $(shell git describe --long HEAD) BUILD_DATE := $(shell date +%Y-%m-%d\ %H:%M) +TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1) +TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true) BUILD_SHA := $(shell git rev-parse --short HEAD) +BUILD_VERSION := $(TAG:v%=%) +ifneq ($(COMMIT), $(TAG_COMMIT)) + BUILD_VERSION := $(BUILD_VERSION)-$(BUILD_SHA) +endif +ifneq ($(shell git status --porcelain),) + BUILD_VERSION := $(BUILD_VERSION)-dirty +endif + +# Go architecture and targets images to build +GOARCH ?= amd64 +MULTIARCH_TARGETS := amd64 arm64 ppc64le + +# In CI, to be replaced by `netobserv` +IMAGE_ORG ?= $(USER) +FORCED_CI_ORG ?= netobserv + # Default image repo -REPO ?= quay.io/netobserv +REPO ?= quay.io/$(IMAGE_ORG) + # Component versions to use in bundle / release (do not use $VERSION for that) PREVIOUS_VERSION ?= v1.0.1 BUNDLE_VERSION ?= 1.0.2 @@ -49,17 +67,17 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) # IMAGE_TAG_BASE defines the namespace and part of the image name for remote images. # This variable is used to construct full image tags for bundle and catalog images. # -# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both +# For example, running 'make bundle-push catalog-push' will build and push both # netobserv/network-observability-operator-bundle:$BUNDLE_VERSION and netobserv/network-observability-operator-catalog:$BUNDLE_VERSION. IMAGE_TAG_BASE ?= $(REPO)/network-observability-operator -# BUNDLE_IMG defines the image:tag used for the bundle. -# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=/:) -BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(BUNDLE_VERSION) +# BUNDLE_IMAGE defines the image:tag used for the bundle. +# You can use it as an arg. (E.g make bundle-build BUNDLE_IMAGE=/:) +BUNDLE_IMAGE ?= $(IMAGE_TAG_BASE)-bundle:v$(BUNDLE_VERSION) # Image URL to use all building/pushing image targets -IMG ?= $(IMAGE_TAG_BASE):$(VERSION) -IMG_SHA = $(IMAGE_TAG_BASE):$(BUILD_SHA) +IMAGE ?= $(IMAGE_TAG_BASE):$(VERSION) +IMAGE_SHA = $(IMAGE_TAG_BASE):$(BUILD_SHA) # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. @@ -74,13 +92,8 @@ GOBIN=$(shell go env GOBIN) endif # Image building tool (docker / podman) -ifndef OCI_BIN -ifeq (,$(shell which podman 2>/dev/null)) -OCI_BIN=docker -else -OCI_BIN=podman -endif -endif +OCI_BIN_PATH = $(shell which podman || which docker) +OCI_BIN ?= $(shell v='$(OCI_BIN_PATH)'; echo "$${v##*/}") DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") @@ -96,6 +109,18 @@ all: help include .bingo/Variables.mk +# build a single arch target provided as argument +define build_target + echo 'building image for arch $(1)'; \ + DOCKER_BUILDKIT=1 $(OCI_BIN) buildx build --load --build-arg TARGETPLATFORM=linux/$(1) --build-arg TARGETARCH=$(1) --build-arg BUILDPLATFORM=linux/amd64 -t ${IMAGE}-$(1) -f Dockerfile .; +endef + +# push a single arch target image +define push_target + echo 'pushing image ${IMAGE}-$(1)'; \ + DOCKER_BUILDKIT=1 $(OCI_BIN) push ${IMAGE}-$(1); +endef + ##@ General # The help target prints out all targets with their descriptions organized @@ -248,28 +273,57 @@ lint: prereqs ## Run linter (golangci-lint). test: envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverpkg=./... -coverprofile cover.out -coverage-report: +coverage-report: ## Generate coverage report go tool cover --func=./cover.out -coverage-report-html: +coverage-report-html: ## Generate HTML coverage report go tool cover --html=./cover.out build: fmt lint ## Build manager binary. - go build -ldflags "-X 'main.buildVersion=${BUILD_VERSION}' -X 'main.buildDate=${BUILD_DATE}'" -mod vendor -o bin/manager main.go - -image-build: ## Build operator OCI image. - $(OCI_BIN) build --build-arg BUILD_VERSION="${BUILD_VERSION}" -t ${IMG} . - -ci-images-build: image-build - $(OCI_BIN) build --build-arg BASE_IMAGE=$(IMG) -t $(IMG_SHA) -f ./shortlived.Dockerfile . - -image-push: ## Push OCI image with the manager. -ifneq (,$(findstring quay.io/netobserv/,$(IMG))) - $(error Do not push to quay.io/netobserv) + GOARCH=${GOARCH} go build -ldflags "-X 'main.buildVersion=${BUILD_VERSION}' -X 'main.buildDate=${BUILD_DATE}'" -mod vendor -o bin/manager main.go + +##@ Images + +# note: to build and push custom image tag use: IMAGE_ORG=myuser VERSION=dev make images +.PHONY: image-build +image-build: ## Build MULTIARCH_TARGETS images + trap 'exit' INT; \ + $(foreach target,$(MULTIARCH_TARGETS),$(call build_target,$(target))) + +.PHONY: image-push +image-push: ## Push MULTIARCH_TARGETS images + trap 'exit' INT; \ + $(foreach target,$(MULTIARCH_TARGETS),$(call push_target,$(target))) + +.PHONY: manifest-build +manifest-build: ## Build MULTIARCH_TARGETS manifest + @echo 'building manifest $(IMAGE)' + DOCKER_BUILDKIT=1 $(OCI_BIN) manifest create ${IMAGE} $(foreach target,$(MULTIARCH_TARGETS),--amend ${IMAGE}-$(target)); + +.PHONY: manifest-push +manifest-push: ## Push MULTIARCH_TARGETS manifest + @echo 'publish manifest $(IMAGE)' +ifeq (${OCI_BIN}, docker) + DOCKER_BUILDKIT=1 $(OCI_BIN) manifest push ${IMAGE}; else - $(OCI_BIN) push ${IMG} + DOCKER_BUILDKIT=1 $(OCI_BIN) manifest push ${IMAGE} docker://${IMAGE}; endif +.PHONY: ci-images-build +ci-images-build: IMAGE_ORG=$(FORCED_CI_ORG) +ci-images-build: image-build ## Build OCI image with the manager. + $(OCI_BIN) build --build-arg BASE_IMAGE=$(IMAGE) -t $(IMAGE_SHA) -f ./shortlived.Dockerfile . + +.PHONY: ci-images-push +ci-images-push: IMAGE_ORG=$(FORCED_CI_ORG) +ci-images-push: ## Push OCI image with the manager. + DOCKER_BUILDKIT=1 $(OCI_BIN) push $(IMAGE_SHA) + ifeq ($(VERSION), main) + # Also tag "latest" only for branch "main" + DOCKER_BUILDKIT=1 $(OCI_BIN) push ${IMAGE} + DOCKER_BUILDKIT=1 $(OCI_BIN) push $(IMAGE_TAG_BASE):latest + endif + ##@ Deployment install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. @@ -279,7 +333,7 @@ uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube $(KUSTOMIZE) build config/crd | kubectl --ignore-not-found=true delete -f - || true deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. - cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE} $(SED) -i -r 's~ebpf-agent:.+~ebpf-agent:main~' ./config/manager/manager.yaml $(SED) -i -r 's~flowlogs-pipeline:.+~flowlogs-pipeline:main~' ./config/manager/manager.yaml $(SED) -i -r 's~console-plugin:.+~console-plugin:main~' ./config/manager/manager.yaml @@ -296,7 +350,7 @@ run: fmt lint ## Run a controller from your host. .PHONY: bundle-prepare bundle-prepare: OPSDK generate kustomize ## Generate bundle manifests and metadata, then validate generated files. $(OPSDK) generate kustomize manifests -q - cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE) $(SED) -i -r 's~ebpf-agent:.+~ebpf-agent:$(BPF_VERSION)~' ./config/manager/manager.yaml $(SED) -i -r 's~flowlogs-pipeline:.+~flowlogs-pipeline:$(FLP_VERSION)~' ./config/manager/manager.yaml $(SED) -i -r 's~console-plugin:.+~console-plugin:$(PLG_VERSION)~' ./config/manager/manager.yaml @@ -309,7 +363,7 @@ bundle-prepare: OPSDK generate kustomize ## Generate bundle manifests and metada bundle: bundle-prepare ## Generate final bundle files. $(SED) -e 's/^/ /' config/manifests/bases/description-upstream.md > tmp-desc $(KUSTOMIZE) build config/manifests \ - | $(SED) -e 's~:container-image:~$(IMG)~' \ + | $(SED) -e 's~:container-image:~$(IMAGE)~' \ | $(SED) -e "/':full-description:'/r tmp-desc" \ | $(SED) -e "s/':full-description:'/|\-/" \ | $(OPSDK) generate bundle -q --overwrite --version $(BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS) @@ -322,33 +376,34 @@ bundle: bundle-prepare ## Generate final bundle files. .PHONY: update-bundle update-bundle: VERSION=$(BUNDLE_VERSION) +update-bundle: IMAGE_ORG=$(FORCED_CI_ORG) update-bundle: bundle ## Prepare a clean bundle to be commited .PHONY: bundle-build bundle-build: ## Build the bundle image. cp ./bundle/manifests/netobserv-operator.clusterserviceversion.yaml tmp-bundle $(SED) -i -r 's~:created-at:~$(DATE)~' ./bundle/manifests/netobserv-operator.clusterserviceversion.yaml - -$(OCI_BIN) build -f bundle.Dockerfile -t $(BUNDLE_IMG) . + -$(OCI_BIN) build -f bundle.Dockerfile -t $(BUNDLE_IMAGE) . mv tmp-bundle ./bundle/manifests/netobserv-operator.clusterserviceversion.yaml shortlived-bundle-build: ## Build a temporary bundle image, expiring after 2 weeks on quay - $(MAKE) bundle-build BUNDLE_IMG=$(IMAGE_TAG_BASE)-bundle:tmp - $(OCI_BIN) build --build-arg BASE_IMAGE=$(IMAGE_TAG_BASE)-bundle:tmp -t $(BUNDLE_IMG) -f ./shortlived.Dockerfile . + $(MAKE) bundle-build BUNDLE_IMAGE=$(IMAGE_TAG_BASE)-bundle:tmp + $(OCI_BIN) build --build-arg BASE_IMAGE=$(IMAGE_TAG_BASE)-bundle:tmp -t $(BUNDLE_IMAGE) -f ./shortlived.Dockerfile . .PHONY: bundle-push bundle-push: ## Push the bundle image. - $(MAKE) image-push IMG=$(BUNDLE_IMG) + $(MAKE) image-push IMAGE=$(BUNDLE_IMAGE) -# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0). +# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMAGES=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0). # These images MUST exist in a registry and be pull-able. -BUNDLE_IMGS ?= $(BUNDLE_IMG) +BUNDLE_IMAGES ?= $(BUNDLE_IMAGE) -# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). -CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(BUNDLE_VERSION) +# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMAGE=example.com/operator-catalog:v0.2.0). +CATALOG_IMAGE ?= $(IMAGE_TAG_BASE)-catalog:v$(BUNDLE_VERSION) -# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. -ifneq ($(origin CATALOG_BASE_IMG), undefined) -FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) +# Set CATALOG_BASE_IMAGE to an existing catalog image tag to add $BUNDLE_IMAGES to that image. +ifneq ($(origin CATALOG_BASE_IMAGE), undefined) +FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMAGE) endif # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. @@ -356,21 +411,21 @@ endif # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator .PHONY: catalog-build catalog-build: opm ## Build a catalog image. - $(OPM) index add --container-tool ${OCI_BIN} --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) $(OPM_OPTS) + $(OPM) index add --container-tool ${OCI_BIN} --mode semver --tag $(CATALOG_IMAGE) --bundles $(BUNDLE_IMAGES) $(FROM_INDEX_OPT) $(OPM_OPTS) shortlived-catalog-build: ## Build a temporary catalog image, expiring after 2 weeks on quay - $(MAKE) catalog-build CATALOG_IMG=$(IMAGE_TAG_BASE)-catalog:tmp - $(OCI_BIN) build --build-arg BASE_IMAGE=$(IMAGE_TAG_BASE)-catalog:tmp -t $(CATALOG_IMG) -f ./shortlived.Dockerfile . + $(MAKE) catalog-build CATALOG_IMAGE=$(IMAGE_TAG_BASE)-catalog:tmp + $(OCI_BIN) build --build-arg BASE_IMAGE=$(IMAGE_TAG_BASE)-catalog:tmp -t $(CATALOG_IMAGE) -f ./shortlived.Dockerfile . # Push the catalog image. .PHONY: catalog-push catalog-push: ## Push a catalog image. - $(MAKE) image-push IMG=$(CATALOG_IMG) + $(MAKE) image-push IMAGE=$(CATALOG_IMAGE) # Deploy the catalog. .PHONY: catalog-deploy catalog-deploy: ## Deploy a catalog image. - $(SED) -e 's~~$(CATALOG_IMG)~' ./config/samples/catalog/catalog.yaml | kubectl apply -f - + $(SED) -e 's~~$(CATALOG_IMAGE)~' ./config/samples/catalog/catalog.yaml | kubectl apply -f - # Undeploy the catalog. .PHONY: catalog-undeploy @@ -400,3 +455,4 @@ include .mk/sample.mk include .mk/development.mk include .mk/local.mk include .mk/ocp.mk +include .mk/shortcuts.mk diff --git a/bundle/manifests/netobserv-operator.clusterserviceversion.yaml b/bundle/manifests/netobserv-operator.clusterserviceversion.yaml index 59e8339b4..64ec2bdd9 100644 --- a/bundle/manifests/netobserv-operator.clusterserviceversion.yaml +++ b/bundle/manifests/netobserv-operator.clusterserviceversion.yaml @@ -356,6 +356,11 @@ metadata: operators.operatorframework.io/builder: operator-sdk-v1.25.3 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/netobserv/network-observability-operator + labels: + operatorframework.io/arch.amd64: supported + operatorframework.io/arch.arm64: supported + operatorframework.io/arch.ppc64le: supported + operatorframework.io/os.linux: supported name: netobserv-operator.v1.0.2 namespace: placeholder spec: diff --git a/config/manifests/bases/netobserv-operator.clusterserviceversion.yaml b/config/manifests/bases/netobserv-operator.clusterserviceversion.yaml index 48aa2d584..20cce495e 100644 --- a/config/manifests/bases/netobserv-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/netobserv-operator.clusterserviceversion.yaml @@ -11,6 +11,11 @@ metadata: description: Network flows collector and monitoring solution operatorframework.io/suggested-namespace: openshift-netobserv-operator repository: https://github.com/netobserv/network-observability-operator + labels: + operatorframework.io/arch.amd64: supported + operatorframework.io/arch.arm64: supported + operatorframework.io/arch.ppc64le: supported + operatorframework.io/os.linux: supported name: netobserv-operator.v0.0.0 namespace: placeholder spec: diff --git a/config/samples/catalog/catalog.yaml b/config/samples/catalog/catalog.yaml index eb14fd5da..af0a917b5 100644 --- a/config/samples/catalog/catalog.yaml +++ b/config/samples/catalog/catalog.yaml @@ -5,7 +5,7 @@ metadata: namespace: openshift-marketplace spec: sourceType: grpc - image: + image: displayName: Network observability development catalog publisher: Me updateStrategy: diff --git a/hack/test-workflow.sh b/hack/test-workflow.sh index 452ac6448..98b4c1da7 100755 --- a/hack/test-workflow.sh +++ b/hack/test-workflow.sh @@ -19,7 +19,7 @@ run_step() { opts=$4 step=$(cat .github/workflows/$file | yq ".jobs.$job.steps[] | select(.name==\"$name\").run") - step=$(echo $step | sed -r "s~\\$\{\{ env\.REGISTRY \}\}~quay.io/netobserv~g" | sed -r "s~\\$\{\{ env\.IMAGE \}\}~network-observability-operator~g" | sed -r "s~\\$\{\{ env\.short_sha \}\}~$short_sha~g" | sed -r "s~\\$\{\{ env\.tag \}\}~$fake_tag~g") + step=$(echo $step | sed -r "s~\\$\{\{ env\.ORG \}\}~netobserv~g" | sed -r "s~\\$\{\{ env\.REGISTRY \}\}~quay.io/netobserv~g" | sed -r "s~\\$\{\{ env\.IMAGE \}\}~network-observability-operator~g" | sed -r "s~\\$\{\{ env\.short_sha \}\}~$short_sha~g" | sed -r "s~\\$\{\{ env\.tag \}\}~$fake_tag~g") step="$opts $step" echo "↘️ Running step '$name' ($file)"