Skip to content

Commit

Permalink
Merge pull request #32 from mikenairn/add_image_builds
Browse files Browse the repository at this point in the history
Add build images CI job
  • Loading branch information
mikenairn authored Feb 21, 2022
2 parents d61c7b2 + 381c217 commit 5ada185
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 683 deletions.
142 changes: 142 additions & 0 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Build Images

on:
push:
branches: [ '*' ]
tags: [ '*' ]

env:
IMG_TAGS: ${{ github.ref_name }}
IMG_REGISTRY_HOST: quay.io
IMG_REGISTRY_ORG: kuadrant
MAIN_BRANCH_NAME: main
OPERATOR_NAME: authorino-operator

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Add latest tag
if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }}
id: add-latest-tag
run: |
echo "IMG_TAGS=latest ${{ env.IMG_TAGS }}" >> $GITHUB_ENV
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.OPERATOR_NAME }}
tags: ${{ env.IMG_TAGS }}
dockerfiles: |
./Dockerfile
- name: Push Image
if: ${{ !env.ACT }}
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

build-bundle:
needs: build
name: Build Bundle
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16.x
uses: actions/setup-go@v2
with:
go-version: 1.16.x
id: go
- name: Check out code
uses: actions/checkout@v2
- name: Add latest tag
if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }}
id: add-latest-tag
run: |
echo "IMG_TAGS=latest ${{ env.IMG_TAGS }}" >> $GITHUB_ENV
- name: Run make bundle
if: ${{ github.ref_name != env.MAIN_BRANCH_NAME }}
run: make bundle REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} IMAGE_TAG=${{ github.ref_name }}
- name: Run make bundle (main)
if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }}
run: make bundle REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} IMAGE_TAG=latest VERSION=0.0.0
- name: Git diff
run: git diff
# Uncomment this when ORG in the Makefile to be updated to "kuadrant"
# - name: Verify manifests and bundle
# if: startsWith(github.ref, 'refs/tags/v') || github.ref_name == env.MAIN_BRANCH_NAME
# run: make verify-manifests verify-bundle
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.OPERATOR_NAME }}-bundle
tags: ${{ env.IMG_TAGS }}
dockerfiles: |
./bundle.Dockerfile
- name: Push Image
if: ${{ !env.ACT }}
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

build-catalog:
name: Build Catalog
needs: [build, build-bundle]
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16.x
uses: actions/setup-go@v2
with:
go-version: 1.16.x
id: go
- name: Check out code
uses: actions/checkout@v2
- name: Add latest tag
if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }}
id: add-latest-tag
run: |
echo "IMG_TAGS=latest ${{ env.IMG_TAGS }}" >> $GITHUB_ENV
- name: Run make catalog-generate
if: ${{ github.ref_name != env.MAIN_BRANCH_NAME }}
run: make catalog-generate REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} IMAGE_TAG=${{ github.ref_name }}
- name: Run make catalog-generate (main)
if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }}
run: make catalog-generate REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} IMAGE_TAG=latest VERSION=0.0.0
- name: Git diff
run: git diff
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.OPERATOR_NAME }}-catalog
tags: ${{ env.IMG_TAGS }}
dockerfiles: |
./index.Dockerfile
- name: Push Image
if: ${{ !env.ACT }}
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
72 changes: 35 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# VERSION defines the project version for the bundle.
OPERATOR_VERSION ?= latest

ifeq (latest,$(OPERATOR_VERSION))
OPERATOR_TAG = latest
else
OPERATOR_TAG = v$(OPERATOR_VERSION)
endif
VERSION ?= 0.0.0

# Address of the container registry
REGISTRY = quay.io
Expand All @@ -16,13 +10,19 @@ ORG ?= 3scale
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
IMAGE_TAG_BASE ?= $(REGISTRY)/$(ORG)/authorino-operator

ifeq (0.0.0,$(VERSION))
IMAGE_TAG ?= latest
else
IMAGE_TAG ?= v$(VERSION)
endif

# Image URL to use all building/pushing image targets
DEFAULT_OPERATOR_IMAGE = $(IMAGE_TAG_BASE):$(OPERATOR_TAG)
DEFAULT_OPERATOR_IMAGE = $(IMAGE_TAG_BASE):$(IMAGE_TAG)
OPERATOR_IMAGE ?= $(DEFAULT_OPERATOR_IMAGE)

# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:$(OPERATOR_TAG)
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:$(IMAGE_TAG)

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down Expand Up @@ -59,6 +59,13 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

AUTHORINO_VERSION ?= latest
ifeq (latest,$(AUTHORINO_VERSION))
AUTHORINO_BRANCH = main
else
AUTHORINO_BRANCH = v$(AUTHORINO_VERSION)
endif

all: build

##@ General
Expand All @@ -68,10 +75,17 @@ help: ## Display this help.

##@ Development

manifests: controller-gen kustomize ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
manifests: controller-gen kustomize authorino-manifests ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases && $(KUSTOMIZE) build config/install > $(OPERATOR_MANIFESTS)
$(MAKE) deploy-manifest OPERATOR_IMAGE=$(OPERATOR_IMAGE)

.PHONY: authorino-manifests
authorino-manifests: export AUTHORINO_GITREF := $(AUTHORINO_BRANCH)
authorino-manifests: ## Update authorino manifests.
envsubst \
< config/authorino/kustomization.template.yaml \
> config/authorino/kustomization.yaml

generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

Expand Down Expand Up @@ -123,19 +137,11 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
# rollback kustomize edit
cd config/manager && $(KUSTOMIZE) edit set image controller=${DEFAULT_OPERATOR_IMAGE}


undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -

AUTHORINO_VERSION ?= latest
ifeq (latest,$(AUTHORINO_VERSION))
AUTHORINO_BRANCH = main
else
AUTHORINO_BRANCH = v$(AUTHORINO_VERSION)
endif
AUTHORINO_MANIFESTS ?= https://raw.githubusercontent.com/Kuadrant/authorino/$(AUTHORINO_BRANCH)/install/manifests.yaml
install-authorino: ## install RBAC and CRD for authorino
kubectl apply -f $(AUTHORINO_MANIFESTS)
$(KUSTOMIZE) build config/authorino | kubectl apply -f -

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
Expand All @@ -160,13 +166,12 @@ rm -rf $$TMP_DIR ;\
endef

DEPLOYMENT_DIR = $(PROJECT_DIR)/config/deploy
DEPLOYMENT_FILE = $(DEPLOYMENT_DIR)/$(shell basename $(AUTHORINO_MANIFESTS))
DEPLOYMENT_FILE = $(DEPLOYMENT_DIR)/manifests.yaml
.PHONY: deploy-manifest
deploy-manifest:
mkdir -p $(DEPLOYMENT_DIR)
curl -sSf $(AUTHORINO_MANIFESTS) > $(DEPLOYMENT_FILE) && sed -i '$${/^$$/d;}' $(DEPLOYMENT_FILE) && echo '---' >> $(DEPLOYMENT_FILE)
cd $(PROJECT_DIR)/config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE) ;\
cd $(PROJECT_DIR) && $(KUSTOMIZE) build config/default >> $(DEPLOYMENT_FILE)
cd $(PROJECT_DIR) && $(KUSTOMIZE) build config/deploy > $(DEPLOYMENT_FILE)
# clean up
cd $(PROJECT_DIR)/config/manager && $(KUSTOMIZE) edit set image controller=${DEFAULT_OPERATOR_IMAGE}

Expand All @@ -175,29 +180,18 @@ OPERATOR_SDK_VERSION = v1.15.0
operator-sdk: ## Download operator-sdk locally if necessary.
./utils/install-operator-sdk.sh $(OPERATOR_SDK) $(OPERATOR_SDK_VERSION)

ifeq (latest,$(OPERATOR_VERSION))
OPERATOR_BUNDLE_VERSION = 0.0.0
else
OPERATOR_BUNDLE_VERSION = $(OPERATOR_VERSION)
endif
TMP_BUNDLE_DIR = $(PROJECT_DIR)/tmp/bundles
.PHONY: bundle
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
rm -rf $(TMP_BUNDLE_DIR)
$(OPERATOR_SDK) generate kustomize manifests -q
mkdir -p $(TMP_BUNDLE_DIR)
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE)
$(KUSTOMIZE) build $(PROJECT_DIR)/config/manifests > $(TMP_BUNDLE_DIR)/authorino-operator-manifests.yaml
curl $(AUTHORINO_MANIFESTS) > $(TMP_BUNDLE_DIR)/authorino-manifests.yaml
$(OPERATOR_SDK) generate bundle -q --overwrite --version $(OPERATOR_BUNDLE_VERSION) $(BUNDLE_METADATA_OPTS) --package authorino-operator --input-dir $(TMP_BUNDLE_DIR)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) --package authorino-operator
$(OPERATOR_SDK) bundle validate ./bundle
# Roll back edit
cd config/manager && $(KUSTOMIZE) edit set image controller=${DEFAULT_OPERATOR_IMAGE}

.PHONY: bundle-build
bundle-build: bundle ## Build the bundle image.
cd $(TMP_BUNDLE_DIR) && docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
rm -rf $(TMP_BUNDLE_DIR)
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: bundle-push
bundle-push: ## Push the bundle image.
Expand Down Expand Up @@ -225,7 +219,7 @@ endif
BUNDLE_IMGS ?= $(BUNDLE_IMG)

# 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:$(OPERATOR_TAG)
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:$(IMAGE_TAG)

# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
Expand All @@ -239,6 +233,10 @@ endif
catalog-build: opm ## Build a catalog image.
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)

.PHONY: catalog-generate
catalog-generate: opm ## Generate a catalog/index Dockerfile.
$(OPM) index add --generate --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)

# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
Expand Down
2 changes: 2 additions & 0 deletions config/authorino/kustomization.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- github.com/Kuadrant/authorino/install?ref=${AUTHORINO_GITREF}
2 changes: 2 additions & 0 deletions config/authorino/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- github.com/Kuadrant/authorino/install?ref=main
3 changes: 3 additions & 0 deletions config/deploy/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
- ../authorino
- ../default
Loading

0 comments on commit 5ada185

Please sign in to comment.