Skip to content

Commit

Permalink
Add tasks for module build in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
muralov committed Oct 5, 2023
1 parent 018011a commit bdc4620
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .version
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# next version to be released
MODULE_VERSION=0.0.1
58 changes: 55 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
ifndef MODULE_VERSION
include .version
endif

# Module Name used for bundling the OCI Image and later on for referencing in the Kyma Modules
MODULE_NAME ?= eventing

# Operating system architecture
OS_ARCH ?= $(shell uname -m)

# Operating system type
OS_TYPE ?= $(shell uname)

# Module Registry used for pushing the image
MODULE_REGISTRY_PORT ?= 8888
MODULE_REGISTRY ?= op-kcp-registry.localhost:$(MODULE_REGISTRY_PORT)/unsigned
# Desired Channel of the Generated Module Template
MODULE_CHANNEL ?= fast

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG_REGISTRY_PORT ?= $(MODULE_REGISTRY_PORT)
IMG_REGISTRY ?= op-skr-registry.localhost:$(IMG_REGISTRY_PORT)/unsigned/manager-images
IMG ?= $(IMG_REGISTRY)/$(MODULE_NAME)-manager:$(MODULE_VERSION)

## Image URL to use all building/pushing image targets
#IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.27.1

Expand All @@ -26,6 +44,21 @@ else
GOBIN=$(shell go env GOBIN)
endif

# Credentials used for authenticating into the module registry
# see `kyma alpha mod create --help for more info`

# This will change the flags of the `kyma alpha module create` command in case we spot credentials
# Otherwise we will assume http-based local registries without authentication (e.g. for k3d)
ifneq (,$(PROW_JOB_ID))
GCP_ACCESS_TOKEN=$(shell gcloud auth application-default print-access-token)
MODULE_CREATION_FLAGS=--registry $(MODULE_REGISTRY) --module-archive-version-overwrite -c oauth2accesstoken:$(GCP_ACCESS_TOKEN)
else ifeq (,$(MODULE_CREDENTIALS))
# when built locally we should not include security content.
MODULE_CREATION_FLAGS=--registry $(MODULE_REGISTRY) --module-archive-version-overwrite --insecure --sec-scanners-config=sec-scanners-config-local.yaml
else
MODULE_CREATION_FLAGS=--registry $(MODULE_REGISTRY) --module-archive-version-overwrite -c $(MODULE_CREDENTIALS)
endif

# 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,6 +183,25 @@ LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

##@ Module

.PHONY: module-image
module-image: docker-build docker-push ## Build the Module Image and push it to a registry defined in IMG_REGISTRY
echo "built and pushed module image $(IMG)"

DEFAULT_CR ?= $(shell pwd)/config/samples/default.yaml
.PHONY: module-build
module-build: kyma kustomize ## Build the Module and push it to a registry defined in MODULE_REGISTRY
#################################################################
## Building module with:
# - image: ${IMG}
# - channel: ${MODULE_CHANNEL}
# - name: kyma-project.io/module/$(MODULE_NAME)
# - version: $(MODULE_VERSION)
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
@$(KYMA) alpha create module --kubebuilder-project --channel=${MODULE_CHANNEL} --name kyma-project.io/module/$(MODULE_NAME) --version $(MODULE_VERSION) --path . $(MODULE_CREATION_FLAGS) --output=template.yaml --default-cr=$(DEFAULT_CR)


## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
Expand Down Expand Up @@ -186,10 +238,10 @@ lint-thoroughly:
go-gen:
go generate ./...

fmt-local: ## Reformat files using `go fmt`
fmt: ## Reformat files using `go fmt`
go fmt $$($(DIRS_TO_CHECK))

imports-local: ## Optimize imports
imports: ## Optimize imports
goimports -w -l $$($(FILES_TO_CHECK))

########## Kyma CLI ###########
Expand Down
57 changes: 54 additions & 3 deletions hack/ci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,61 @@ KYMA_CLI ?= "${PROJECT_ROOT}/${KYMA}"
CLUSTER_NAME ?= kyma
REGISTRY_PORT ?= 5001

.PHONY: install-k3d-tools
install-k3d-tools: ## Create k3d with kyma CRDs.
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | TAG=${K3D_VERSION} bash
ifndef MODULE_VERSION
include ${PROJECT_ROOT}/.version
endif

ifndef MODULE_SHA
MODULE_SHA = ${shell git rev-parse --short HEAD}
endif

.PHONY: module-build
module-build: ## Build the Module, push it to a registry and print it based on the commit hash.
@make -C ${PROJECT_ROOT} module-build \
IMG=${IMG} \
MODULE_REGISTRY=${MODULE_REGISTRY} \
MODULE_VERSION=${MODULE_VERSION}-${MODULE_SHA}
cp -f ${PROJECT_ROOT}/template.yaml ${ARTIFACTS}/module-template.yaml
@echo "Added template to job artifacts: ${ARTIFACTS}/module-template.yaml"
@echo "\n~~~~~~~~~~~~BEGINNING OF MODULE TEMPLATE~~~~~~~~~~~~~~"
@cat ${ARTIFACTS}/module-template.yaml
@echo "\n~~~~~~~~~~~~~~~END OF MODULE TEMPLATE~~~~~~~~~~~~~~~~"

.PHONY: download-module-template
download-module-template: ## Downloads the module-template from the module-build prow job.
export PROJECT_ROOT="${PROJECT_ROOT}" \
&& ../get_module_template_from_build_job.sh

.PHONY: install-latest-module-template-fast
install-latest-module-template-fast: ## Downloads and applies the latest released module-template from fast channel.
kubectl apply -f https://github.com/kyma-project/eventing-manager/releases/latest/download/module-template.yaml

.PHONY: create-kyma-system-ns
create-kyma-system-ns: ## Create kyma-system namespace.
kubectl create ns kyma-system

.PHONY: install-module-template
install-module-template: ## Apply Eventing moduletemplate.
kubectl apply -f ${PROJECT_ROOT}/module-template.yaml

.PHONY: enable-module-without-default-cr
enable-module-without-default-cr: ## Enable Eventing module without creating default Eventing CR.
"${KYMA_CLI}" alpha enable module eventing -c fast -n kyma-system -p Ignore

.PHONY: install-lifecycle-manager
install-lifecycle-manager: ## Deploys lifecycle-manager.
"${KYMA_CLI}" alpha deploy \
--ci \
--force-conflicts

.PHONY: create-k3d
create-k3d: ## Create k3d with kyma CRDs.
"${KYMA_CLI}" provision k3d -p 8081:80@loadbalancer -p 8443:443@loadbalancer --registry-port ${REGISTRY_PORT} --name ${CLUSTER_NAME} --ci

.PHONY: verify-kyma
verify-kyma: ## Wait for Kyma CR to be in Ready state.
../verify_kyma_status.sh

.PHONY: install-k3d-tools
install-k3d-tools: ## Create k3d with kyma CRDs.
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | TAG=${K3D_VERSION} bash

0 comments on commit bdc4620

Please sign in to comment.