Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add make targets for asset upload #129

Merged
merged 7 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
Expand Down Expand Up @@ -142,6 +157,44 @@ lint: ## Download & Build & Run golangci-lint against code.
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANG_CI_LINT_VERSION)
$(LOCALBIN)/golangci-lint run

.PHONY: configure-git-origin
configure-git-origin:
@git remote | grep '^origin$$' -q || \
git remote add origin https://github.com/kyma-project/template-operator

.PHONY: build-manifests
build-manifests: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default > template-operator.yaml

DEFAULT_CR ?= $(shell pwd)/config/samples/default-sample-cr.yaml
.PHONY: build-module
build-module: kyma build-manifests configure-git-origin ## 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)
echo "running alpha create"
@$(KYMA) alpha create module --path . --output=module-template.yaml --module-config-file=module-config.yaml $(MODULE_CREATION_FLAGS)

########## Kyma CLI ###########
KYMA_STABILITY ?= unstable

# $(call os_error, os-type, os-architecture)
define os_error
$(error Error: unsuported platform OS_TYPE:$1, OS_ARCH:$2; to mitigate this problem set variable KYMA with absolute path to kyma-cli binary compatible with your operating system and architecture)
endef

KYMA_FILE_NAME ?= $(shell ./scripts/local/get_kyma_file_name.sh ${OS_TYPE} ${OS_ARCH})
KYMA ?= $(LOCALBIN)/kyma-$(KYMA_STABILITY)

.PHONY: kyma
kyma: $(LOCALBIN) $(KYMA) ## Download kyma CLI locally if necessary.
$(KYMA):
#################################################################
$(if $(KYMA_FILE_NAME),,$(call os_error, ${OS_TYPE}, ${OS_ARCH}))
## Downloading Kyma CLI: https://storage.googleapis.com/kyma-cli-$(KYMA_STABILITY)/$(KYMA_FILE_NAME)
test -f $@ || curl -s -Lo $(KYMA) https://storage.googleapis.com/kyma-cli-$(KYMA_STABILITY)/$(KYMA_FILE_NAME)
chmod 0100 $(KYMA)
${KYMA} version -c
15 changes: 15 additions & 0 deletions scripts/local/get_kyma_file_name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

function get_kyma_file_name () {

local _OS_TYPE=$1
local _OS_ARCH=$2

[ "$_OS_TYPE" == "Linux" ] && [ "$_OS_ARCH" == "x86_64" ] && echo "kyma-linux" ||
[ "$_OS_TYPE" == "Linux" ] && [ "$_OS_ARCH" == "arm64" ] && echo "kyma-linux-arm" ||
[ "$_OS_TYPE" == "Windows" ] && [ "$_OS_ARCH" == "x86_64" ] && echo "kyma.exe" ||
[ "$_OS_TYPE" == "Windows" ] && [ "$_OS_ARCH" == "arm64" ] && echo "kyma-arm.exe" ||
[ "$_OS_TYPE" == "Darwin" ] && [ "$_OS_ARCH" == "x86_64" ] && echo "kyma-darwin"
}

get_kyma_file_name "$@"
15 changes: 7 additions & 8 deletions scripts/release/upload_assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ uploadFile() {
fi
}

echo "PULL_BASE_REF ${PULL_BASE_REF}"

MODULE_VERSION=${PULL_BASE_REF} make render-manifest
echo "PULL_BASE_REF= ${PULL_BASE_REF}"

MODULE_VERSION=${PULL_BASE_REF} make build-manifests
echo "Generated template-operator.yaml:"
cat template-operator.yaml

MODULE_VERSION=${PULL_BASE_REF} make module-build

echo "Generated moduletemplate.yaml:"
cat moduletemplate.yaml
MODULE_VERSION=${PULL_BASE_REF} make build-module
echo "Generated module-template.yaml:"
cat module-template.yaml

echo "Fetching releases"
CURL_RESPONSE=$(curl -w "%{http_code}" -sL \
Expand All @@ -62,7 +60,8 @@ fi
echo "Adding assets to Github release"
UPLOAD_URL="https://uploads.github.com/repos/kyma-project/template-operator/releases/${RELEASE_ID}/assets"

echo "$UPLOAD_URL"
uploadFile "template-operator.yaml" "${UPLOAD_URL}?name=template-operator.yaml"
uploadFile "moduletemplate.yaml" "${UPLOAD_URL}?name=moduletemplate.yaml"
uploadFile "module-template.yaml" "${UPLOAD_URL}?name=module-template.yaml"
uploadFile "config/samples/default-sample-cr.yaml" "${UPLOAD_URL}?name=default-sample-cr.yaml"
uploadFile "module-config.yaml" "${UPLOAD_URL}?name=module-config.yaml"