diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dd5a886..8eaab65 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,19 +15,26 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + submodules: recursive - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod - - name: make tidy + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: 3.x + + - name: task generate run: | - make tidy + task generate git diff --exit-code - - name: make verify - run: make verify + - name: task validate + run: task validate - - name: make test - run: make test \ No newline at end of file + - name: task test + run: task test diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 3c03222..349d9aa 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -23,11 +23,17 @@ jobs: ssh-key: ${{ secrets.PUSH_KEY }} fetch-tags: true fetch-depth: 0 + submodules: recursive + + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: 3.x - name: Read and validate VERSION id: version run: | - VERSION=$(cat VERSION) + VERSION=$(task version) if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then echo "Invalid version format in VERSION file: $VERSION" exit 1 @@ -68,24 +74,14 @@ jobs: with: go-version-file: go.mod - - name: Build the ${{ github.repository }} + - name: Build and Push Images run: | - make prepare-release - make build - - - name: Build Images - run: | - IMAGE_REGISTRY=ghcr.io/openmcp-project make image-build - - - name: setup OCM - uses: open-component-model/ocm-setup-action@main + task build:img:all - - name: Create OCM CTF + - name: Package and Push Helm Charts run: | - ocm add componentversions --create \ - --file ctf component-constructor.yaml \ - --settings settings.yaml -- VERSION=${{ env.version }} + task build:helm:all - - name: Push CTF + - name: Build and Push OCM Component run: | - ocm transfer ctf --overwrite ./ctf ${{ env.OCI_URL }} + task build:ocm:all diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8e043a5..f21a4c3 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,11 +19,17 @@ jobs: ssh-key: ${{ secrets.PUSH_KEY }} fetch-tags: true fetch-depth: 0 + submodules: recursive + + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: 3.x - name: Read and validate VERSION id: version run: | - VERSION=$(cat VERSION) + VERSION=$(task version) if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then echo "Invalid version format in VERSION file: $VERSION" exit 1 @@ -64,6 +70,22 @@ jobs: git tag -a "${{ env.version }}" -m "Release ${{ env.version }}" git push origin "${{ env.version }}" + - name: Create Git tag for api submodule + if: ${{ env.SKIP != 'true' }} + run: | + AUTHOR_NAME=$(git log -1 --pretty=format:'%an') + AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae') + echo "Tagging as $AUTHOR_NAME <$AUTHOR_EMAIL>" + + echo "AUTHOR_NAME=$AUTHOR_NAME" >> $GITHUB_ENV + echo "AUTHOR_EMAIL=$AUTHOR_EMAIL" >> $GITHUB_ENV + + git config user.name "$AUTHOR_NAME" + git config user.email "$AUTHOR_EMAIL" + + git tag -a "api/${{ env.version }}" -m "Release ${{ env.version }}" + git push origin "api/${{ env.version }}" + - name: Create GitHub release if: ${{ env.SKIP != 'true' }} uses: softprops/action-gh-release@v2 @@ -79,7 +101,7 @@ jobs: - name: Push dev VERSION if: ${{ env.SKIP != 'true' }} run: | - echo "${{ env.version }}-dev" > VERSION + task release:set-version -- "${{ env.version }}-dev" git config user.name "${{ env.AUTHOR_NAME }}" git config user.email "${{ env.AUTHOR_EMAIL }}" git add VERSION diff --git a/.gitignore b/.gitignore index e56bb46..dc4e830 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ components/ /**/cover.*.html *.tmp +.task/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c0425ec --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hack/common"] + path = hack/common + url = https://github.com/openmcp-project/build diff --git a/Makefile b/Makefile deleted file mode 100644 index 68b3803..0000000 --- a/Makefile +++ /dev/null @@ -1,165 +0,0 @@ -PROJECT_FULL_NAME := mcp-operator -REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -EFFECTIVE_VERSION := $(shell $(REPO_ROOT)/hack/common/get-version.sh) - -COMMON_MAKEFILE ?= $(REPO_ROOT)/hack/common/Makefile -ifneq (,$(wildcard $(COMMON_MAKEFILE))) -include $(COMMON_MAKEFILE) -endif - -# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) -ifeq (,$(shell go env GOBIN)) -GOBIN=$(shell go env GOPATH)/bin -else -GOBIN=$(shell go env GOBIN) -endif - -# CONTAINER_TOOL defines the container tool to be used for building images. -# Be aware that the target commands are only tested with Docker which is -# scaffolded by default. However, you might want to replace it to use other -# tools. (i.e. podman) -CONTAINER_TOOL ?= docker - -# 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 -.SHELLFLAGS = -ec - -COMPONENTS ?= mcp-operator -API_CODE_DIRS := $(REPO_ROOT)/api/constants/... $(REPO_ROOT)/api/errors/... $(REPO_ROOT)/api/install/... $(REPO_ROOT)/api/v1alpha1/... $(REPO_ROOT)/api/core/v1alpha1/... -ROOT_CODE_DIRS := $(REPO_ROOT)/cmd/... $(REPO_ROOT)/internal/... $(REPO_ROOT)/test/... - -##@ General - -ifndef HELP_TARGET -.PHONY: help -help: ## Display this help. - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) -endif - -##@ Development - -.PHONY: manifests -manifests: controller-gen ## Generate CustomResourceDefinition objects. - @echo "> Remove existing CRD manifests" - rm -rf config/crd/bases/ - rm -rf config/webhook/manifests/ - rm -rf api/crds/manifests/ - @echo "> Generating CRD Manifests" - @$(CONTROLLER_GEN) crd paths="$(REPO_ROOT)/api/core/v1alpha1/..." output:crd:artifacts:config=config/crd/bases - @$(CONTROLLER_GEN) crd paths="$(REPO_ROOT)/api/core/v1alpha1/..." output:crd:artifacts:config=api/crds/manifests - @$(CONTROLLER_GEN) webhook paths="$(REPO_ROOT)/api/..." - -.PHONY: generate -generate: generate-code manifests generate-docs format ## Generates code (DeepCopy stuff, CRDs), documentation index, and runs formatter. - -.PHONY: generate-code -generate-code: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. Also fetches external APIs. - @echo "> Fetching External APIs" - @go run $(REPO_ROOT)/hack/external-apis/main.go - @echo "> Generating DeepCopy Methods" - @$(CONTROLLER_GEN) object paths="$(REPO_ROOT)/api/core/v1alpha1/..." - -.PHONY: format -format: goimports ## Formats the imports. - @FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/common/format.sh $(API_CODE_DIRS) $(ROOT_CODE_DIRS) - -.PHONY: verify -verify: golangci-lint jq goimports ## Runs linter, 'go vet', and checks if the formatter has been run. - @test "$(SKIP_DOCS_INDEX_CHECK)" = "true" || \ - ( echo "> Verify documentation index ..." && \ - JQ=$(JQ) $(REPO_ROOT)/hack/common/verify-docs-index.sh ) - @( echo "> Verifying api module ..." && \ - pushd $(REPO_ROOT)/api &>/dev/null && \ - go vet $(API_CODE_DIRS) && \ - $(LINTER) run -c $(REPO_ROOT)/.golangci.yaml $(API_CODE_DIRS) && \ - popd &>/dev/null ) - @( echo "> Verifying root module ..." && \ - pushd $(REPO_ROOT) &>/dev/null && \ - go vet $(ROOT_CODE_DIRS) && \ - $(LINTER) run -c $(REPO_ROOT)/.golangci.yaml $(ROOT_CODE_DIRS) && \ - popd &>/dev/null ) - @test "$(SKIP_FORMATTING_CHECK)" = "true" || \ - ( echo "> Checking for unformatted files ..." && \ - FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/common/format.sh --verify $(API_CODE_DIRS) $(ROOT_CODE_DIRS) ) - -.PHONY: test -test: #envtest ## Run tests. -# KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(ROOT_CODE_DIRS) -coverprofile cover.out - @( echo "> Test root module ..." && \ - pushd $(REPO_ROOT) &>/dev/null && \ - go test $(ROOT_CODE_DIRS) -coverprofile cover.root.out && \ - go tool cover --html=cover.root.out -o cover.root.html && \ - go tool cover -func cover.root.out | tail -n 1 && \ - popd &>/dev/null ) - - @( echo "> Test api module ..." && \ - pushd $(REPO_ROOT)/api &>/dev/null && \ - go test $(API_CODE_DIRS) -coverprofile cover.api.out && \ - go tool cover --html=cover.api.out -o cover.api.html && \ - go tool cover -func cover.api.out | tail -n 1 && \ - popd &>/dev/null ) - -##@ Build Dependencies - -## Location to install dependencies to -LOCALBIN ?= $(REPO_ROOT)/bin - -# Tool Binaries -ENVTEST ?= $(LOCALBIN)/setup-envtest - -# Tool Versions -SETUP_ENVTEST_VERSION ?= release-0.16 - -ifndef LOCALBIN_TARGET -.PHONY: localbin -localbin: - @test -d $(LOCALBIN) || mkdir -p $(LOCALBIN) -endif - -.PHONY: envtest -envtest: localbin ## Download envtest-setup locally if necessary. - @test -s $(LOCALBIN)/setup-envtest && test -s $(LOCALBIN)/setup-envtest_version && cat $(LOCALBIN)/setup-envtest_version | grep -q $(SETUP_ENVTEST_VERSION) || \ - ( echo "Installing setup-envtest $(SETUP_ENVTEST_VERSION) ..."; \ - GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION) && \ - echo $(SETUP_ENVTEST_VERSION) > $(LOCALBIN)/setup-envtest_version ) - -##@ Local Setup - -DISABLE_AUTHENTICATION ?= true -DISABLE_AUTHORIZATION ?= true -DISABLE_CLOUDORCHESTRATOR ?= true -DISABLE_MANAGEDCONTROLPLANE ?= false -DISABLE_APISERVER ?= true -DISABLE_LANDSCAPER ?= true -LOCAL_GOARCH ?= $(shell go env GOARCH) - -.PHONY: dev-local -dev-local: dev-clean image-build-local dev-cluster load-image helm-install-local ## All-in-one command for creating a fresh local setup. - -.PHONY: dev-clean -dev-clean: ## Removes the kind cluster for local setup. - $(KIND) delete cluster --name=$(PROJECT_FULL_NAME)-dev - -.PHONY: dev-cluster -dev-cluster: ## Creates a kind cluster for running a local setup. - $(KIND) create cluster --name=$(PROJECT_FULL_NAME)-dev - -.PHONY: load-image -load-image: ## Loads the image into the local setup kind cluster. - $(KIND) load docker-image local/mcp-operator:${EFFECTIVE_VERSION}-linux-$(LOCAL_GOARCH) --name=$(PROJECT_FULL_NAME)-dev - -.PHONY: helm-install-local -helm-install-local: ## Installs the MCP Operator into the local setup kind cluster by using its helm chart. - helm upgrade --install $(PROJECT_FULL_NAME) charts/$(PROJECT_FULL_NAME)/ --set image.repository=local/mcp-operator --set image.tag=${EFFECTIVE_VERSION}-linux-$(LOCAL_GOARCH) --set image.pullPolicy=Never \ - --set authentication.disabled=$(DISABLE_AUTHENTICATION) \ - --set authorization.disabled=$(DISABLE_AUTHORIZATION) \ - --set cloudOrchestrator.disabled=$(DISABLE_CLOUDORCHESTRATOR) \ - --set managedcontrolplane.disabled=$(DISABLE_MANAGEDCONTROLPLANE) \ - --set apiserver.disabled=$(DISABLE_APISERVER) \ - --set landscaper.disabled=$(DISABLE_LANDSCAPER) - -.PHONY: install -install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config (or $KUBECONFIG). Usually not required, as the MCP Operator installs the CRDs on its own. - $(KUBECTL) apply -f config/crd/bases - diff --git a/Makefile b/Makefile new file mode 120000 index 0000000..c21893a --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +./hack/common/Makefile \ No newline at end of file diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..98b650e --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,71 @@ +version: 3 + +# vars: # cannot be specified here due to https://github.com/go-task/task/issues/2108 +# NESTED_MODULES: api +# API_DIRS: '{{.ROOT_DIR}}/api/core/v1alpha1/...' +# MANIFEST_OUT: '{{.ROOT_DIR}}/api/crds/manifests' +# CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/test/... {{.ROOT_DIR}}/api/constants/... {{.ROOT_DIR}}/api/errors/... {{.ROOT_DIR}}/api/install/... {{.ROOT_DIR}}/api/v1alpha1/... {{.ROOT_DIR}}/api/core/v1alpha1/...' +# COMPONENTS: 'mcp-operator' +# REPO_URL: 'https://github.com/openmcp-project/mcp-operator' +# GENERATE_DOCS_INDEX: "true" + +includes: + shared: + taskfile: hack/common/Taskfile_controller.yaml + flatten: true + excludes: # put task names in here which are overwritten in this file + - generate:code + - validate:test + vars: + NESTED_MODULES: api + API_DIRS: '{{.ROOT_DIR}}/api/core/v1alpha1/...' + MANIFEST_OUT: '{{.ROOT_DIR}}/api/crds/manifests' + CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/test/... {{.ROOT_DIR}}/api/constants/... {{.ROOT_DIR}}/api/errors/... {{.ROOT_DIR}}/api/install/... {{.ROOT_DIR}}/api/v1alpha1/... {{.ROOT_DIR}}/api/core/v1alpha1/...' + COMPONENTS: 'mcp-operator' + REPO_URL: 'https://github.com/openmcp-project/mcp-operator' + GENERATE_DOCS_INDEX: "true" + common: # imported a second time so that overwriting task definitions can call the overwritten task with a 'c:' prefix + taskfile: hack/common/Taskfile_controller.yaml + internal: true + aliases: + - c + vars: + NESTED_MODULES: api + API_DIRS: '{{.ROOT_DIR}}/api/core/v1alpha1/...' + MANIFEST_OUT: '{{.ROOT_DIR}}/api/crds/manifests' + CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/test/... {{.ROOT_DIR}}/api/constants/... {{.ROOT_DIR}}/api/errors/... {{.ROOT_DIR}}/api/install/... {{.ROOT_DIR}}/api/v1alpha1/... {{.ROOT_DIR}}/api/core/v1alpha1/...' + COMPONENTS: 'mcp-operator' + REPO_URL: 'https://github.com/openmcp-project/mcp-operator' + GENERATE_DOCS_INDEX: "true" + +tasks: + generate:code: # overwrites shared code task to add external API fetching + desc: " Generate code (mainly DeepCopy functions) and fetches external APIs." + aliases: + - gen:code + - g:code + run: once + cmds: + - task: external-apis + - task: c:generate:code + + external-apis: + desc: " Fetch external APIs." + run: once + method: checksum + sources: + - hack/external-apis/* + cmds: + - 'go run {{.ROOT_DIR}}/hack/external-apis/main.go' + internal: true + + validate:test: # overwrites the test task to add a dependency towards envtest + desc: " Run all tests." + aliases: + - val:test + - v:test + run: once + deps: + - tools:envtest + cmds: + - task: c:validate:test diff --git a/api/go.mod b/api/go.mod index 6514354..38d0021 100644 --- a/api/go.mod +++ b/api/go.mod @@ -1,8 +1,6 @@ module github.com/openmcp-project/mcp-operator/api -go 1.23.0 - -toolchain go1.23.6 +go 1.23.5 require ( github.com/onsi/ginkgo/v2 v2.22.2 diff --git a/component-constructor.yaml b/component-constructor.yaml deleted file mode 100644 index a00e629..0000000 --- a/component-constructor.yaml +++ /dev/null @@ -1,21 +0,0 @@ -components: -- name: ${COMPONENT_NAME_PREFIX}/${COMPONENT_NAME} - version: ${VERSION} - provider: - name: ${PROVIDER} - resources: - - name: ${COMPONENT_NAME}-chart - type: helmChart - input: - type: helm - path: ./charts/${COMPONENT_NAME} - repository: charts/${COMPONENT_NAME} - - - name: ${COMPONENT_NAME}-image - type: ociImage - input: - type: dockermulti - repository: images/${COMPONENT_NAME} - variants: - - "${COMPONENT_REPO_PREFIX}:${VERSION}-linux-amd64" - - "${COMPONENT_REPO_PREFIX}:${VERSION}-linux-arm64" diff --git a/go.mod b/go.mod index ba723ef..1b031ce 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/openmcp-project/mcp-operator go 1.23.5 -toolchain go1.24.0 - replace github.com/openmcp-project/mcp-operator/api => ./api replace github.com/imdario/mergo v1.0.0 => github.com/imdario/mergo v0.3.16 diff --git a/hack/common b/hack/common new file mode 160000 index 0000000..34a6c9e --- /dev/null +++ b/hack/common @@ -0,0 +1 @@ +Subproject commit 34a6c9e820b732eec1f3b06f39f658d65224a774 diff --git a/hack/common/Dockerfile b/hack/common/Dockerfile deleted file mode 100644 index c6783d8..0000000 --- a/hack/common/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -# Use distroless as minimal base image to package the component binary -# Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot -ARG TARGETOS -ARG TARGETARCH -ARG COMPONENT -WORKDIR / -COPY bin/$COMPONENT-$TARGETOS.$TARGETARCH / -USER 65532:65532 - -# docker doesn't substitue args in ENTRYPOINT, so we replace this during the build script -ENTRYPOINT ["/"] diff --git a/hack/common/Makefile b/hack/common/Makefile deleted file mode 100644 index 9df0d3c..0000000 --- a/hack/common/Makefile +++ /dev/null @@ -1,273 +0,0 @@ -# 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 -.SHELLFLAGS = -ec - -############################################################################################################ -# This Makefile is meant to be included in the Makefile of the repository including this one as submodule. # -# Currently, this repository has to be included at 'hack/common' path in the parent repository. # -# Also, the parent Makefile has to set the following variables: # -# - REPO_ROOT: The root directory of the repository. # -# - COMPONENTS: The list of components to build (usually just one, e.g. 'mcp-operator'). # -############################################################################################################ - -##@ Common - General - -# The help target prints out all targets with their descriptions organized -# beneath their categories. The categories are represented by '##@' and the -# target descriptions by '##'. The awk commands is responsible for reading the -# entire set of makefiles included in this invocation, looking for lines of the -# file as xyz: ## something, and then pretty-format the target and help. Then, -# if there's a line with ##@ something, that gets pretty-printed as a category. -# More info on the usage of ANSI control characters for terminal formatting: -# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters -# More info on the awk command: -# http://linuxcommand.org/lc3_adv_awk.php - -ifndef HELP_TARGET -HELP_TARGET := true -.PHONY: help -help: ## Display this help. - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) -endif - -##@ Common - Development - -ifndef TIDY_TARGET -TIDY_TARGET := true -.PHONY: tidy -tidy: ## Runs 'go mod tidy' for all modules in this repo. - @$(REPO_ROOT)/hack/common/tidy.sh -endif - -ifndef GENERATE_DOCS_TARGET -GENERATE_DOCS_TARGET := true -.PHONY: generate-docs -generate-docs: jq ## Generates the documentation index. - @JQ=$(JQ) $(REPO_ROOT)/hack/common/generate-docs-index.sh -endif - -ifndef VERIFY_DOCS_TARGET -VERIFY_DOCS_TARGET := true -.PHONY: verify-docs -verify-docs: jq ## Verifies that the documentation index is up-to-date. - @test "$(SKIP_DOCS_INDEX_CHECK)" = "true" || \ - ( echo "> Verify documentation index ..." && \ - JQ=$(JQ) $(REPO_ROOT)/hack/common/verify-docs-index.sh ) -endif - -##@ Common - Release - -ifndef PREPARE_RELEASE_TARGET -PREPARE_RELEASE_TARGET := true -.PHONY: prepare-release -prepare-release: tidy generate verify test -endif - -ifndef RELEASE_MAJOR_TARGET -RELEASE_MAJOR_TARGET := true -.PHONY: release-major -release-major: prepare-release ## Creates a major release commit. - @COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/release.sh major -endif - -ifndef RELEASE_MINOR_TARGET -RELEASE_MINOR_TARGET := true -.PHONY: release-minor -release-minor: prepare-release ## Creates a minor release commit. - @COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/release.sh minor -endif - -ifndef RELEASE_PATCH_TARGET -RELEASE_PATCH_TARGET := true -.PHONY: release-patch -release-patch: prepare-release ## Creates a patch release commit. - @COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/release.sh patch -endif - -##@ Common - Build - -PLATFORMS ?= linux/arm64,linux/amd64 - -ifndef ALL_TARGET -ALL_TARGET := true -.PHONY: all -all: build image chart component ## Complete build and push for all components/platforms specified in COMPONENTS/PLATFORMS. Alias for 'make build image chart component'. -endif - -ifndef BUILD_TARGET -BUILD_TARGET := true -.PHONY: build -build: generate ## Builds binaries for all components specified in COMPONENTS and all platforms specified in PLATFORMS. - @PLATFORMS=$(PLATFORMS) COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/build-binary.sh -endif - -ifndef IMAGE_TARGET -IMAGE_TARGET := true -.PHONY: image -image: build image-build image-push ## Builds and pushes docker images for all components specified in COMPONENTS and all platforms specified in PLATFORMS. -endif - -ifndef IMAGE_BUILD_TARGET -IMAGE_BUILD_TARGET := true -.PHONY: image-build -image-build: ## Builds the docker images for all components specified in COMPONENTS and all platforms specified in PLATFORMS. Requires 'make build' to have run before. - @PLATFORMS=$(PLATFORMS) COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/build-image.sh -endif - -ifndef IMAGE_BUILD_LOCAL_TARGET -IMAGE_BUILD_LOCAL_TARGET := true -.PHONY: image-build-local -image-build-local: ## Builds the docker images for all components specified in COMPONENTS and all platforms specified in PLATFORMS. Requires 'make build' to have run before. - @PLATFORMS=$(PLATFORMS) COMPONENTS=$(COMPONENTS) BASE_REGISTRY=local $(REPO_ROOT)/hack/common/build-image.sh -endif - -ifndef IMAGE_PUSH_TARGET -IMAGE_PUSH_TARGET := true -.PHONY: image-push -image-push: ## Pushes the docker images for all components specified in COMPONENTS and all platforms specified in PLATFORMS. Requires 'make image-build' to have run before. - @PLATFORMS=$(PLATFORMS) COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/push-image.sh -endif - -ifndef CHART_TARGET -CHART_TARGET := true -.PHONY: chart -chart: chart-build chart-push ## Packs and pushes the helm charts for all components specified in COMPONENTS into the OCI registry. -endif - -ifndef CHART_BUILD_TARGET -CHART_BUILD_TARGET := true -.PHONY: chart-build -chart-build: helm ## Packs the helm charts for all components specified in COMPONENTS to prepare them for upload into the OCI registry. - @HELM=$(HELM) COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/build-chart.sh -endif - -ifndef CHART_PUSH_TARGET -CHART_PUSH_TARGET := true -.PHONY: chart-push -chart-push: helm jq yaml2json ## Pushes helm charts for all components specified in COMPONENTS into the OCI registry. Requires 'make chart-build' to have run before. - @HELM=$(HELM) COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/push-chart.sh -endif - -ifndef COMPONENT_TARGET -COMPONENT_TARGET := true -.PHONY: component -component: component-build component-push ## Builds and pushes the component descriptor into the registry. Requires charts and images to be already pushed into the registry. -endif - -ifndef COMPONENT_BUILD_TARGET -COMPONENT_BUILD_TARGET := true -.PHONY: component-build -component-build: ocm ## Builds the component descriptor for the mcp-operator. Several env variables can be used to control the result, see components/components.yaml for details. Requires charts and images to be already pushed into the registry. - @OCM=$(OCM) COMPONENTS=$(COMPONENTS) $(REPO_ROOT)/hack/common/build-component.sh -endif - -ifndef COMPONENT_PUSH_TARGET -COMPONENT_PUSH_TARGET := true -.PHONY: component-push -component-push: ocm ## Pushes the component descriptor into the registry. Requires 'make component-build' to have run before. - @OCM=$(OCM) $(REPO_ROOT)/hack/common/push-component.sh -endif - -##@ Common - Build Dependencies - -## Location to install dependencies to -LOCALBIN ?= $(REPO_ROOT)/bin - -## Tool Binaries -KUBECTL ?= kubectl -KIND ?= kind -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -FORMATTER ?= $(LOCALBIN)/goimports -LINTER ?= $(LOCALBIN)/golangci-lint -OCM ?= $(LOCALBIN)/ocm -HELM ?= $(LOCALBIN)/helm -JQ ?= $(LOCALBIN)/jq -YAML2JSON ?= $(LOCALBIN)/yaml2json - -## Tool Versions -# renovate: datasource=github-releases depName=kubernetes-sigs/controller-tools -CONTROLLER_TOOLS_VERSION ?= v0.16.4 -# renovate: datasource=github-tags depName=golang/tools -FORMATTER_VERSION ?= v0.26.0 -# renovate: datasource=github-releases depName=golangci/golangci-lint -LINTER_VERSION ?= v1.64.4 -# renovate: datasource=github-releases depName=jqlang/jq -JQ_VERSION ?= 1.7.1 -# renovate: datasource=github-releases depName=open-component-model/ocm -OCM_VERSION ?= 0.16.2 -HELM_VERSION ?= v3.13.2 -# renovate: datasource=github-releases depName=bronze1man/yaml2json -YAML2JSON_VERSION ?= v1.3.3 - -ifndef LOCALBIN_TARGET -LOCALBIN_TARGET := true -.PHONY: localbin -localbin: - @test -d $(LOCALBIN) || mkdir -p $(LOCALBIN) -endif - -ifndef CONTROLLER_GEN_TARGET -CONTROLLER_GEN_TARGET := true -.PHONY: controller-gen -controller-gen: localbin ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten. - @test -s $(CONTROLLER_GEN) && $(CONTROLLER_GEN) --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ - ( echo "Installing controller-gen $(CONTROLLER_TOOLS_VERSION) ..."; \ - GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) ) -endif - -ifndef GOIMPORTS_TARGET -GOIMPORTS_TARGET := true -.PHONY: goimports -goimports: localbin ## Download goimports locally if necessary. If wrong version is installed, it will be overwritten. - @test -s $(FORMATTER) && test -s $(LOCALBIN)/goimports_version && cat $(LOCALBIN)/goimports_version | grep -q $(FORMATTER_VERSION) || \ - ( echo "Installing goimports $(FORMATTER_VERSION) ..."; \ - GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@$(FORMATTER_VERSION) && \ - echo $(FORMATTER_VERSION) > $(LOCALBIN)/goimports_version ) -endif - -ifndef GOLANGCI_LINT_TARGET -GOLANGCI_LINT_TARGET := true -.PHONY: golangci-lint -golangci-lint: localbin ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten. - @test -s $(LINTER) && $(LINTER) --version | grep -q $(subst v,,$(LINTER_VERSION)) || \ - ( echo "Installing golangci-lint $(LINTER_VERSION) ..."; \ - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) $(LINTER_VERSION) ) -endif - -ifndef OCM_TARGET -OCM_TARGET := true -.PHONY: ocm -ocm: localbin ## Install OCM CLI if necessary. - @test -s $(OCM) && $(OCM) --version | grep -q $(OCM_VERSION) || \ - ( echo "Installing ocm $(OCM_VERSION) ..."; \ - curl -sSfL https://ocm.software/install.sh | OCM_VERSION=$(OCM_VERSION) bash -s $(LOCALBIN) ) -endif - -ifndef HELM_TARGET -HELM_TARGET := true -.PHONY: helm -helm: localbin ## Download helm locally if necessary. - @test -s $(HELM) && $(HELM) version --short | grep -q $(HELM_VERSION) || \ - ( echo "Installing helm $(HELM_VERSION) ..."; \ - HELM=$(HELM) LOCALBIN=$(LOCALBIN) $(REPO_ROOT)/hack/common/install/helm.sh $(HELM_VERSION) ) -endif - -ifndef JQ_TARGET -JQ_TARGET := true -.PHONY: jq -jq: localbin ## Download jq locally if necessary. If wrong version is installed, it will be overwritten. - @test -s $(JQ) && $(JQ) --version | grep -q $(subst v,,$(JQ_VERSION)) || \ - ( echo "Installing jq $(JQ_VERSION) ..."; \ - JQ=$(JQ) LOCALBIN=$(LOCALBIN) $(REPO_ROOT)/hack/common/install/jq.sh $(JQ_VERSION) ) -endif - -ifndef YAML2JSON_TARGET -YAML2JSON_TARGET := true -.PHONY: yaml2json -# yaml2json 1.3.3 incorrectly reports its version as 1.3.2, thus the workaround below -yaml2json: localbin ## Download yaml2json locally if necessary. If wrong version is installed, it will be overwritten. - @test -s $(YAML2JSON) && ($(YAML2JSON) --version || true) | grep -q $(subst 1.3.3,1.3.2,$(subst v,,$(YAML2JSON_VERSION))) || \ - ( echo "Installing yaml2json $(YAML2JSON_VERSION) ..."; \ - YAML2JSON=$(YAML2JSON) LOCALBIN=$(LOCALBIN) $(REPO_ROOT)/hack/common/install/yaml2json.sh $(YAML2JSON_VERSION) ) -endif diff --git a/hack/common/build-binary.sh b/hack/common/build-binary.sh deleted file mode 100755 index e0e1249..0000000 --- a/hack/common/build-binary.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -echo -echo "> Building binaries ..." -( - cd "$PROJECT_ROOT" - for comp in ${COMPONENTS//,/ }; do - for pf in ${PLATFORMS//,/ }; do - echo "> Building binary for component '$comp' ($pf) ..." | indent 1 - os=${pf%/*} - arch=${pf#*/} - CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -a -o bin/${comp}-${os}.${arch} cmd/${comp}/main.go | indent 2 - done - done -) diff --git a/hack/common/build-chart.sh b/hack/common/build-chart.sh deleted file mode 100755 index b136bb2..0000000 --- a/hack/common/build-chart.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -VERSION=$("$COMMON_SCRIPT_DIR/get-version.sh") - -echo -echo "> Packaging helm charts to prepare for upload ..." -tmpdir="$("$COMMON_SCRIPT_DIR/get-tmp-dir.sh")" -for comp in ${COMPONENTS//,/ }; do - echo "> Packaging helm chart for component '$comp' ..." | indent 1 - "$HELM" package "$PROJECT_ROOT/charts/$comp" -d "$tmpdir" --version "$VERSION" | indent 2 # file name is -.tgz (derived from Chart.yaml) -done diff --git a/hack/common/build-component.sh b/hack/common/build-component.sh deleted file mode 100755 index e0234e2..0000000 --- a/hack/common/build-component.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -VERSION=$("$COMMON_SCRIPT_DIR/get-version.sh") -CHART_REGISTRY=$("$COMMON_SCRIPT_DIR/get-registry.sh" --helm) -IMG_REGISTRY=$("$COMMON_SCRIPT_DIR/get-registry.sh" --image) - -pushd ${PROJECT_ROOT} > /dev/null 2>&1 -COMMIT="$(git rev-parse HEAD)" -popd > /dev/null 2>&1 - -echo -echo "> Building component in version ${CD_VERSION:-$VERSION} ..." -compdir="$("$COMMON_SCRIPT_DIR/get-tmp-dir.sh")/component" -$OCM add componentversions --file "$compdir" --version "$VERSION" --create --force --templater spiff "$COMPONENT_DEFINITION_FILE" -- \ - VERSION="$VERSION" \ - CHART_REGISTRY="$CHART_REGISTRY" \ - IMG_REGISTRY="$IMG_REGISTRY" \ - COMMIT="$COMMIT" \ - COMPONENTS="$COMPONENTS" \ - ${CD_VERSION:+CD_VERSION=}${CD_VERSION:-} \ - ${CHART_VERSION:+CHART_VERSION=}${CHART_VERSION:-} \ - ${IMG_VERSION:+IMG_VERSION=}${IMG_VERSION:-} \ - ${BP_COMPONENTS:+BP_COMPONENTS=}${BP_COMPONENTS:-} \ - ${CHART_COMPONENTS:+CHART_COMPONENTS=}${CHART_COMPONENTS:-} \ - ${IMG_COMPONENTS:+IMG_COMPONENTS=}${IMG_COMPONENTS:-} \ - | indent 1 - -echo "Use '$(realpath --relative-base=$(pwd) $OCM) get cv $compdir -o yaml' to view the generated component descriptor." \ No newline at end of file diff --git a/hack/common/build-image.sh b/hack/common/build-image.sh deleted file mode 100755 index c1595c5..0000000 --- a/hack/common/build-image.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -if [[ -z ${IMAGE_REGISTRY:-} ]]; then - IMAGE_REGISTRY=$("$COMMON_SCRIPT_DIR/get-registry.sh" -i) -fi - -VERSION=$("$COMMON_SCRIPT_DIR/get-version.sh") - -DOCKER_BUILDER_NAME="mcp-multiarch-builder" -if ! docker buildx ls | grep "$DOCKER_BUILDER_NAME" >/dev/null; then - docker buildx create --name "$DOCKER_BUILDER_NAME" -fi - -# remove temporary Dockerfile on exit -trap "rm -f \"${PROJECT_ROOT}/Dockerfile.tmp\"" EXIT - -echo -echo "> Building images ..." -for comp in ${COMPONENTS//,/ }; do - for pf in ${PLATFORMS//,/ }; do - os=${pf%/*} - arch=${pf#*/} - img="${IMAGE_REGISTRY}/${comp}:${VERSION}-${os}-${arch}" - echo "> Building image for component '$comp' ($pf): $img ..." | indent 1 - cat "${COMMON_SCRIPT_DIR}/Dockerfile" | sed "s//$comp/g" > "${PROJECT_ROOT}/Dockerfile.tmp" - docker buildx build --builder ${DOCKER_BUILDER_NAME} --load --build-arg COMPONENT=${comp} --platform ${pf} -t $img -f Dockerfile.tmp "${PROJECT_ROOT}" | indent 2 - done -done - -docker buildx rm "$DOCKER_BUILDER_NAME" \ No newline at end of file diff --git a/hack/common/environment.sh b/hack/common/environment.sh deleted file mode 100755 index 2d03251..0000000 --- a/hack/common/environment.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -export COMMON_SCRIPT_DIR="$(realpath "$(dirname ${BASH_SOURCE[0]})")" -source "$COMMON_SCRIPT_DIR/lib.sh" -export PROJECT_ROOT="${PROJECT_ROOT:-$(realpath "$COMMON_SCRIPT_DIR/../..")}" -export COMPONENT_DEFINITION_FILE="${COMPONENT_DEFINITION_FILE:-"$PROJECT_ROOT/components/components.yaml"}" - -export LOCALBIN="${LOCALBIN:-"$PROJECT_ROOT/bin"}" -export HELM="${HELM:-"$LOCALBIN/helm"}" -export JQ="${JQ:-"$LOCALBIN/jq"}" -export FORMATTER=${FORMATTER:-"$LOCALBIN/goimports"} -export OCM="${OCM:-"$LOCALBIN/ocm"}" -export YAML2JSON="${YAML2JSON:-"$LOCALBIN/yaml2json"}" - -if [[ -f "$COMMON_SCRIPT_DIR/../environment.sh" ]]; then - source "$COMMON_SCRIPT_DIR/../environment.sh" -fi diff --git a/hack/common/format.sh b/hack/common/format.sh deleted file mode 100755 index 06c6b33..0000000 --- a/hack/common/format.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -write_mode="-w" -if [[ ${1:-} == "--verify" ]]; then - write_mode="" - shift -fi - -# MODULE_NAME must be set to the name of the local go module. -tmp=$("${FORMATTER}" -l $write_mode -local=$MODULE_NAME $("$COMMON_SCRIPT_DIR/unfold.sh" --clean --no-unfold "$@")) - -if [[ -z ${write_mode} ]] && [[ ${tmp} ]]; then - echo "unformatted files detected, please run 'make format'" 1>&2 - echo "$tmp" 1>&2 - exit 1 -fi - -if [[ ${tmp} ]]; then - echo "> Formatting imports ..." - echo "$tmp" -fi diff --git a/hack/common/generate-docs-index.sh b/hack/common/generate-docs-index.sh deleted file mode 100755 index c0f03a3..0000000 --- a/hack/common/generate-docs-index.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -DOCS_FOLDER="${DOCS_FOLDER:-${PROJECT_ROOT}/docs}" -METAFILE_NAME=".docnames" - -doc_index_file=${1:-"$DOCS_FOLDER/README.md"} - -# prints to the new doc index -function println() { - echo "$@" >> "$newindex" -} - -# expects a path to a folder as argument -# returns how this folder should be named in an index -function getDocFolderName() { - local metafile="$1/$METAFILE_NAME" - if [[ -f "$metafile" ]]; then - cat "$metafile" | $JQ -r '.header' - fi -} - -# expects two arguments: -# - path to a doc folder -# - name of the file in there -# the file is expected to contain its header in the first line -# or there should be an overwrite present in /$METAFILE_NAME -function getDocName() { - local metafile="$1/$METAFILE_NAME" - local filename="$2" - if [[ -f "$metafile" ]]; then - local overwrite="$(cat "$metafile" | $JQ -r '.overwrites[$name]' --arg name "$2")" - if [[ "$overwrite" != "null" ]]; then - echo "$overwrite" - return - fi - fi - if [[ -f "$filename" ]]; then - local firstheader=$(grep -m1 "#" "$filename") - echo "${firstheader#'# '}" - fi -} - -echo "> Generating Documentation Index" - -newindex=$(mktemp) - -println '' -println "# Documentation Index" -println - -( - cd "$DOCS_FOLDER" - for f in *; do - if [[ -d "$f" ]]; then - foldername="$(getDocFolderName "$f")" - if [[ -z "$foldername" ]]; then - echo "Ignoring folder '$f' due to missing '$METAFILE_NAME' file." - continue - fi - - println "## $foldername" - println - - ( - cd "$f" - for f2 in *.md; do - docname="$(getDocName "../$f" "$f2")" - if [[ -z "$docname" ]]; then - echo "Ignoring file '$f/$f2' because the header could not be determined." - # There are two possible reasons for this: - # 1. The file doesn't start with a '# ' in the first line and no overwrite is defined in the folder's metafile. - # 2. The overwrite in the folder's metafile explicitly sets the name to an empty string, meaning this file should be ignored. - continue - fi - println "- [$docname]($f/$f2)" - done - ) - - println - fi - done -) - -cp "$newindex" "$doc_index_file" \ No newline at end of file diff --git a/hack/common/get-registry.sh b/hack/common/get-registry.sh deleted file mode 100755 index fe299fd..0000000 --- a/hack/common/get-registry.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -eu - -set -euo pipefail - -if [[ -z ${BASE_REGISTRY:-} ]]; then - BASE_REGISTRY=ghcr.io/openmcp-project -fi - -if [[ -z ${IMAGE_REGISTRY:-} ]]; then - IMAGE_REGISTRY=$BASE_REGISTRY -fi -if [[ -z ${CHART_REGISTRY:-} ]]; then - CHART_REGISTRY=$BASE_REGISTRY/charts -fi -if [[ -z ${COMPONENT_REGISTRY:-} ]]; then - COMPONENT_REGISTRY=$BASE_REGISTRY/components -fi - -mode="BASE_" - -while [[ "$#" -gt 0 ]]; do - case ${1:-} in - "-i"|"--image") - mode="IMAGE_" - ;; - "-h"|"--helm") - mode="CHART_" - ;; - "-c"|"--component") - mode="COMPONENT_" - ;; - *) - echo "invalid argument: $1" 1>&2 - exit 1 - ;; - esac - shift -done - -eval echo "\$${mode}REGISTRY" diff --git a/hack/common/get-tmp-dir.sh b/hack/common/get-tmp-dir.sh deleted file mode 100755 index 4f844eb..0000000 --- a/hack/common/get-tmp-dir.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -# Creates a directory within the temporary folder (either TMPDIR or /tmp) and returns its path. - -tmpdir="${TMPDIR:-"/tmp"}" -tmpdir="${tmpdir%/}/mcp/$(basename "$PROJECT_ROOT")" -mkdir -p "$tmpdir" -echo "$tmpdir" \ No newline at end of file diff --git a/hack/common/get-version.sh b/hack/common/get-version.sh deleted file mode 100755 index afc4cc9..0000000 --- a/hack/common/get-version.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -eu - -if [[ -n ${EFFECTIVE_VERSION:-} ]] ; then - # running in the pipeline use the provided EFFECTIVE_VERSION - echo "$EFFECTIVE_VERSION" - exit 0 -fi - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -VERSION="$(cat "${PROJECT_ROOT}/VERSION")" - -( - cd "$PROJECT_ROOT" - - if [[ "$VERSION" = *-dev ]] ; then - VERSION="$VERSION-$(git rev-parse HEAD)" - fi - - echo "$VERSION" -) diff --git a/hack/common/install/helm.sh b/hack/common/install/helm.sh deleted file mode 100755 index 5ac6fda..0000000 --- a/hack/common/install/helm.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/../environment.sh")" - -HELM_VERSION="$1" - -arch=$(uname -m) -if [[ "$arch" == "x86_64" ]]; then - arch="amd64" -fi -os=$(uname | tr '[:upper:]' '[:lower:]') -curl -sfL "https://get.helm.sh/helm-${HELM_VERSION}-${os}-${arch}.tar.gz" --output "$LOCALBIN/helm.tar.gz" -mkdir -p "$LOCALBIN/helm-unpacked" -tar -xzf "$LOCALBIN/helm.tar.gz" --directory "$LOCALBIN/helm-unpacked" -mv "$LOCALBIN/helm-unpacked/${os}-${arch}/helm" "$LOCALBIN/helm" -chmod +x "$LOCALBIN/helm" -rm -rf "$LOCALBIN/helm.tar.gz" "$LOCALBIN/helm-unpacked" diff --git a/hack/common/install/jq.sh b/hack/common/install/jq.sh deleted file mode 100755 index b1baeac..0000000 --- a/hack/common/install/jq.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/../environment.sh")" - -JQ_VERSION="$1" -os="linux64" -if [[ $(uname -o) == "Darwin" ]]; then - os="osx-amd64" -fi -curl -sfL "https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-${os}" --output "${LOCALBIN}/jq" -chmod +x "${LOCALBIN}/jq" \ No newline at end of file diff --git a/hack/common/install/yaml2json.sh b/hack/common/install/yaml2json.sh deleted file mode 100755 index 52f3cf9..0000000 --- a/hack/common/install/yaml2json.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/../environment.sh")" - -YAML2JSON_VERSION="$1" - -arch=$(uname -m) -if [[ "$arch" == "x86_64" ]]; then - arch="amd64" -fi -os=$(uname | tr '[:upper:]' '[:lower:]') -curl -sfL "https://github.com/bronze1man/yaml2json/releases/download/${YAML2JSON_VERSION}/yaml2json_${os}_${arch}" --output "${LOCALBIN}/yaml2json" -chmod +x "${LOCALBIN}/yaml2json" \ No newline at end of file diff --git a/hack/common/lib.sh b/hack/common/lib.sh deleted file mode 100755 index fbbf560..0000000 --- a/hack/common/lib.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# pipe some text into 'indent X' to indent each line by X levels (one 'level' being two spaces) -function indent() { - local level=${1:-""} - if [[ -z "$level" ]]; then - level=1 - fi - local spaces=$(($level * 2)) - local iv=$(printf %${spaces}s) - sed "s/^/$iv/" -} \ No newline at end of file diff --git a/hack/common/push-chart.sh b/hack/common/push-chart.sh deleted file mode 100755 index b9be000..0000000 --- a/hack/common/push-chart.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -VERSION=$("$COMMON_SCRIPT_DIR/get-version.sh") -HELM_REGISTRY=$("$COMMON_SCRIPT_DIR/get-registry.sh" --helm) - -echo -echo "> Uploading helm charts to $HELM_REGISTRY ..." -tmpdir="$("$COMMON_SCRIPT_DIR/get-tmp-dir.sh")" -for comp in ${COMPONENTS//,/ }; do - chname="$(cat "$PROJECT_ROOT/charts/$comp/Chart.yaml" | $YAML2JSON | $JQ -r .name)" - echo "> Pushing helm chart for component '$comp' ..." | indent 1 - "$HELM" push "$tmpdir/$chname-$VERSION.tgz" "oci://$HELM_REGISTRY" | indent 2 -done diff --git a/hack/common/push-component.sh b/hack/common/push-component.sh deleted file mode 100755 index 2012650..0000000 --- a/hack/common/push-component.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -VERSION=$("$COMMON_SCRIPT_DIR/get-version.sh") -COMPONENT_REGISTRY="$($COMMON_SCRIPT_DIR/get-registry.sh --component)" - -overwrite="" -if [[ -n ${OVERWRITE_COMPONENTS:-} ]] && [[ ${OVERWRITE_COMPONENTS} != "false" ]]; then - overwrite="--overwrite" -fi - -echo -echo "> Uploading Component Descriptors to $COMPONENT_REGISTRY ..." -compdir="$("$COMMON_SCRIPT_DIR/get-tmp-dir.sh")/component" -$OCM transfer componentversions "$compdir" "$COMPONENT_REGISTRY" $overwrite | indent 1 diff --git a/hack/common/push-image.sh b/hack/common/push-image.sh deleted file mode 100755 index 35814b3..0000000 --- a/hack/common/push-image.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -if [[ -z ${IMAGE_REGISTRY:-} ]]; then - IMAGE_REGISTRY=$("$COMMON_SCRIPT_DIR/get-registry.sh" -i) -fi - -VERSION=$("$COMMON_SCRIPT_DIR/get-version.sh") - -( - cd "$PROJECT_ROOT" - - echo - echo "> Pushing images to registry $IMAGE_REGISTRY ..." - for comp in ${COMPONENTS//,/ }; do - echo "Pushing image for component '$comp' ..." | indent 1 - img="${IMAGE_REGISTRY}/${comp}:${VERSION}" - for pf in ${PLATFORMS//,/ }; do - os=${pf%/*} - arch=${pf#*/} - pfimg="${img}-${os}-${arch}" - - echo "> Pushing platform-specific image for $pf ..." | indent 2 - docker push "$pfimg" | indent 3 - - echo "> Adding image to multi-platform manifest ..." | indent 2 - docker manifest create $img --amend $pfimg | indent 3 - done - - echo "> Pushing multi-platform manifest ..." - docker manifest push "$img" | indent 2 - - if [[ ${ADDITIONAL_TAG:-} ]]; then - echo "> Adding additional tag '$ADDITIONAL_TAG' ..." - docker buildx imagetools create "$img" --tag "${img%:*}:$ADDITIONAL_TAG" | indent 2 - fi - done -) \ No newline at end of file diff --git a/hack/common/release.sh b/hack/common/release.sh deleted file mode 100755 index 35e7e7d..0000000 --- a/hack/common/release.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -VERSION=$("$COMMON_SCRIPT_DIR/get-version.sh") - -( - cd "$PROJECT_ROOT" - - echo "> Checking for uncommitted changes" - if [[ -n "$(git status --porcelain=v1)" ]]; then - echo "There are uncommitted changes in the working directory." - git status --short - echo - echo "These changes will be included in the release commit, unless you stash, commit, or remove them otherwise before." - echo "Do you want to continue, including these changes in the release commit? Please confirm with 'yes' or 'y':" - read confirm - if [[ "$confirm" != "yes" ]] && [[ "$confirm" != "y" ]]; then - echo "Release aborted." - exit 0 - fi - else - echo "No uncommitted changes found." - fi - echo - - echo "> Finding latest release" - major=${VERSION%%.*} - major=${major#v} - minor=${VERSION#*.} - minor=${minor%%.*} - patch=${VERSION##*.} - patch=${patch%%-*} - echo "v${major}.${minor}.${patch}" - echo - - semver=${1:-"minor"} - - case "$semver" in - ("major") - major=$((major + 1)) - minor=0 - patch=0 - ;; - ("minor") - minor=$((minor + 1)) - patch=0 - ;; - ("patch") - patch=$((patch + 1)) - ;; - (*) - echo "invalid argument: $semver" - exit 1 - ;; - esac - - release_version="v$major.$minor.$patch" - - echo "The release version will be $release_version. Please confirm with 'yes' or 'y':" - read confirm - - if [[ "$confirm" != "yes" ]] && [[ "$confirm" != "y" ]]; then - echo "Release not confirmed." - exit 0 - fi - echo - - echo "> Updating version to release version" - "$COMMON_SCRIPT_DIR/set-version.sh" $release_version - echo - - git add --all - git commit -m "release $release_version" - echo - - echo "> Successfully finished" -) \ No newline at end of file diff --git a/hack/common/renovate.json b/hack/common/renovate.json deleted file mode 100644 index 2ce1e84..0000000 --- a/hack/common/renovate.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:best-practices", - "security:openssf-scorecard", - ":dependencyDashboard" - ], - "customManagers": [ - { - "description": "Match in Makefile", - "customType": "regex", - "fileMatch": [ - "(^|/|\\.)([Dd]ocker|[Cc]ontainer)file$", - "(^|/)([Dd]ocker|[Cc]ontainer)file[^/]*$", - "(^|/)Makefile$" - ], - "matchStrings": [ - "# renovate: datasource=(?[a-z-.]+?) depName=(?[^\\s]+?)(?: (lookupName|packageName)=(?[^\\s]+?))?(?: versioning=(?[^\\s]+?))?(?: extractVersion=(?[^\\s]+?))?(?: registryUrl=(?[^\\s]+?))?\\s(?:ENV |ARG )?.+?_VERSION ?(?:\\?=|=)\"? ?(?.+?)\"?\\s" - ] - } - ] -} diff --git a/hack/common/set-version.sh b/hack/common/set-version.sh deleted file mode 100755 index 5a3a752..0000000 --- a/hack/common/set-version.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -VERSION=$1 - -GO_MOD_FILE="${PROJECT_ROOT}/go.mod" - -# update VERSION file -echo "$VERSION" > "$PROJECT_ROOT/VERSION" - -for comp in ${COMPONENTS//,/ }; do - CHART_FILE="${PROJECT_ROOT}/charts/${comp}/Chart.yaml" - CHART_VALUES_FILE="${PROJECT_ROOT}/charts/${comp}/values.yaml" - - # update version and image tag in helm charts - sed -E -i -e "s@version: v?[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+.*@version: $VERSION@1" "${CHART_FILE}" - sed -E -i -e "s@appVersion: v?[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+.*@appVersion: $VERSION@1" "${CHART_FILE}" - sed -i -e "s@ tag: .*@ tag: ${VERSION}@" "${CHART_VALUES_FILE}" - - # remove backup files (created by sed on MacOS) - for file in "${CHART_FILE}" "${CHART_VALUES_FILE}"; do - rm -f "${file}-e" - done -done - -# MODULE_NAME must be set to the local go module name. -# NESTED_MODULES must be set to the list of nested go modules, e.g. 'api,nested2,nested3' -for nm in ${NESTED_MODULES//,/ }; do - # update go.mod - sed -i -e "s@ $MODULE_NAME/$nm .*@ $MODULE_NAME/$nm ${VERSION}@" "${GO_MOD_FILE}" - # remove backup file (created by sed on MacOS) - rm -f "${GO_MOD_FILE}-e" -done diff --git a/hack/common/tidy.sh b/hack/common/tidy.sh deleted file mode 100755 index 8a6d46d..0000000 --- a/hack/common/tidy.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -function tidy() { - go mod tidy -e -} - -# NESTED_MODULES must be set to the list of nested go modules, e.g. 'api,nested2,nested3' -for nm in ${NESTED_MODULES//,/ }; do - echo "Tidy $nm module ..." - ( - cd "$PROJECT_ROOT/$nm" - tidy - ) -done - -echo "Tidy root module ..." -( - cd "$PROJECT_ROOT" - tidy -) diff --git a/hack/common/unfold.sh b/hack/common/unfold.sh deleted file mode 100755 index c2620c2..0000000 --- a/hack/common/unfold.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -# This is a small helper script that takes a list of paths and unfolds them: -# If the path ends with '/...', the path itself (without '/...') and all of its subfolders are printed. -# Otherwise, only the path is printed. -# -# Paths that don't exist will cause an error. -# -# Options: -# -# --absolute -# If active, converts all paths to absolute paths. Overrides --clean. -# -# --clean -# If active, all paths are printed relative to the working directory, with './' and '../' resolved where possible. -# -# --no-unfold -# If active, does simply remove '/...' suffixes instead of unfolding the corresponding paths. -# -# Note that each option's flag -# - toggles that option between active and inactive (with inactive being the default when no flag for that option is specified) -# - can be used multiple times, toggling the option on and off as described above -# - affects only the paths that are specified after it in the command - -# 'toggle X' flips $X between 'true' and 'false'. -function toggle() { - if eval \$$1; then - eval "$1=false" - else - eval "$1=true" - fi -} - -absolute=false -clean=false -no_unfold=false -for f in "$@"; do - case "$f" in - "--absolute") - toggle absolute - ;; - "--clean") - toggle clean - ;; - "--no-unfold") - toggle no_unfold - ;; - *) - depth_mod="" - if [[ "$f" == */... ]]; then - f="${f%/...}" # cut off '/...' - if $no_unfold; then - depth_mod="-maxdepth 0" - fi - else - depth_mod="-maxdepth 0" - fi - if $absolute; then - f="$(realpath "$f")" - elif $clean; then - f="$(realpath --relative-base="$PWD" "$f")" - fi - if tmp=$(find "$f" $depth_mod -type d 2>&1); then - echo "$tmp" - else - echo "error unfolding path '$f': $tmp" >&2 - exit 1 - fi - ;; - esac -done \ No newline at end of file diff --git a/hack/common/verify-docs-index.sh b/hack/common/verify-docs-index.sh deleted file mode 100755 index 4edc398..0000000 --- a/hack/common/verify-docs-index.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -euo pipefail -source "$(realpath "$(dirname $0)/environment.sh")" - -echo "> Checking if documentation index needs changes" -doc_index_file="$PROJECT_ROOT/docs/README.md" -tmp_compare_file=$(mktemp) -"$COMMON_SCRIPT_DIR/generate-docs-index.sh" "$tmp_compare_file" >/dev/null -if ! cmp -s "$doc_index_file" "$tmp_compare_file"; then - echo "The documentation index requires changes." - echo "Please run 'make generate-docs' to update it." - exit 1 -fi -echo "Documentation index is up-to-date." \ No newline at end of file diff --git a/settings.yaml b/settings.yaml deleted file mode 100644 index b341b38..0000000 --- a/settings.yaml +++ /dev/null @@ -1,4 +0,0 @@ -COMPONENT_NAME: mcp-operator -COMPONENT_NAME_PREFIX: github.com/openmcp-project -PROVIDER: openmcp-project -COMPONENT_REPO_PREFIX: ghcr.io/openmcp-project/mcp-operator \ No newline at end of file