Skip to content

Commit

Permalink
feat: Add make targets for asset upload (#129)
Browse files Browse the repository at this point in the history
<!-- Thank you for your contribution. Before you submit the pull
request:
1. Follow contributing guidelines, templates, the recommended Git
workflow, and any related documentation.
2. Read and submit the required Contributor Licence Agreements
(https://github.com/kyma-project/community/blob/main/CONTRIBUTING.md#agreements-and-licenses).
3. Test your changes and attach their results to the pull request.
4. Update the relevant documentation.

If the pull request requires a decision, follow the [decision-making
process](https://github.com/kyma-project/community/blob/main/governance.md)
and replace the PR template with the [decision record
template](https://github.com/kyma-project/community/blob/main/.github/ISSUE_TEMPLATE/decision-record.md).
-->

**Description**

Changes proposed in this pull request:

- add usage of kyma cli to create module and upload it
- fix module-template name and usage of registry

**Related issue(s)**
* #52
<!-- If you refer to a particular issue, provide its number. For
example, `Resolves #123`, `Fixes #43`, or `See also #33`. -->
  • Loading branch information
lindnerby authored Nov 29, 2023
1 parent be19819 commit 14e1bbb
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
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"

0 comments on commit 14e1bbb

Please sign in to comment.