From 1a0570e5d704cf4a68a46167336378eb8247e895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20M=C3=B6ller?= Date: Mon, 4 Nov 2024 18:39:58 +0100 Subject: [PATCH] chore: migrate all component builds: ca => ctf (#1043) #### What this PR does / why we need it part of release work on https://github.com/open-component-model/ocm/issues/995 We want to move away from component archives because we only really need the CTF as single source of truth. This makes the makefiles a little easier to understand and allows us to reuse these commands fairly easily in the next github actions reworks. #### Which issue(s) this PR fixes --- .github/workflows/buildcomponents.yaml | 67 ------------------- .github/workflows/release.yaml | 45 ++----------- Makefile | 16 ++--- components/demoplugin/Makefile | 41 +++++++----- .../demoplugin/component-constructor.yaml | 23 +++++++ components/demoplugin/resources.yaml | 18 ----- components/ecrplugin/Makefile | 46 +++++++------ .../ecrplugin/component-constructor.yaml | 23 +++++++ components/ecrplugin/resources.yaml | 18 ----- components/helmdemo/Makefile | 37 +++++----- .../helmdemo/component-constructor.yaml | 58 ++++++++++++++++ components/helmdemo/references.yaml | 4 -- components/helmdemo/resources.yaml | 43 ------------ components/helmdemo/sources.yaml | 7 -- components/helminstaller/Makefile | 58 +++++++--------- components/helminstaller/a.yaml | 1 - .../helminstaller/component-constructor.yaml | 25 +++++++ components/helminstaller/resources.yaml | 20 ------ components/ocmcli/Makefile | 50 ++++++++------ ...ources.yaml => component-constructor.yaml} | 17 ++++- components/ocmcli/sources.yaml | 7 -- 21 files changed, 280 insertions(+), 344 deletions(-) delete mode 100644 .github/workflows/buildcomponents.yaml create mode 100644 components/demoplugin/component-constructor.yaml delete mode 100644 components/demoplugin/resources.yaml create mode 100644 components/ecrplugin/component-constructor.yaml delete mode 100644 components/ecrplugin/resources.yaml create mode 100644 components/helmdemo/component-constructor.yaml delete mode 100644 components/helmdemo/references.yaml delete mode 100644 components/helmdemo/resources.yaml delete mode 100644 components/helmdemo/sources.yaml delete mode 100644 components/helminstaller/a.yaml create mode 100644 components/helminstaller/component-constructor.yaml delete mode 100644 components/helminstaller/resources.yaml rename components/ocmcli/{resources.yaml => component-constructor.yaml} (63%) delete mode 100644 components/ocmcli/sources.yaml diff --git a/.github/workflows/buildcomponents.yaml b/.github/workflows/buildcomponents.yaml deleted file mode 100644 index 49807661ea..0000000000 --- a/.github/workflows/buildcomponents.yaml +++ /dev/null @@ -1,67 +0,0 @@ -name: BuildComponents - -on: - workflow_dispatch: - inputs: - ocm_push: - type: boolean - description: "Push to OCM Repository" - default: false - -jobs: - components: - name: Trigger component build - runs-on: large_runner - permissions: - contents: write - id-token: write - packages: write - repository-projects: read - steps: - - name: Self Hosted Runner Post Job Cleanup Action - uses: TooMuch4U/actions-clean@v2.2 - - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: '${{ github.workspace }}/go.mod' - cache: false - - - name: Get go environment for use with cache - run: | - echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV - echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV - - name: Set up cache - # https://github.com/actions/setup-go/issues/358 - cache is not working with setup-go for multiple jobs - uses: actions/cache/restore@v4 - with: - path: | - ${{ env.go_cache }} - ${{ env.go_modcache }} - key: ${{ env.cache_name }}-${{ runner.os }}-go- - env: - cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - - - name: Push OCM Components - if: inputs.ocm_push == true - env: - GITHUBORG: ${{ github.repository_owner }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - make push - - - name: Build OCM Components - if: inputs.ocm_push == false - env: - GITHUBORG: ${{ github.repository_owner }} - run: | - make ctf - - - name: Upload OCM Archive - uses: actions/upload-artifact@v4 - with: - name: ocm.ctf - path: gen/ctf diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d881b1aee4..5091f797ab 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -33,38 +33,17 @@ jobs: with: fetch-depth: 0 - - name: Job Settings - run: | - echo "Release Job Arguments" - if ${{ github.event.inputs.release_candidate }}; then - v="v$(go run $GITHUB_WORKSPACE/api/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }})" - if [ -n "${{ github.event.inputs.prerelease }}" ]; then - echo "Candidate: $v" - else - echo "Candidate: $v (taken from source)" - fi - else - v="v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)" - echo "Final Release: $v" - if ${{ github.event.inputs.create_branch }}; then - echo "with release branch creation" - else - echo "without release branch creation" - fi - fi - - - name: Set Base Version + - name: Generate Base Version run: | BASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate print-version) echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV - - name: Set Pre-Release Version + - name: Generate Pre-Release Version if: inputs.release_candidate == true run: | RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }}) echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV - - - name: Set Version + - name: Generate Release Version if: inputs.release_candidate == false run: | RELEASE_VERSION=${{env.BASE_VERSION}} @@ -96,13 +75,6 @@ jobs: draft: true releaseName: ${{ env.BASE_VERSION }} - lint-and-test: - name: Lint and Unit Tests - uses: ./.github/workflows/lint_and_test.yaml - needs: check - permissions: - contents: read - pull-requests: read components: name: Component CTF Builds uses: ./.github/workflows/components.yaml @@ -110,13 +82,7 @@ jobs: permissions: contents: read pull-requests: read - diff-check-manifests: - name: Check for diff after go mod tidy and generated targets - uses: ./.github/workflows/check_diff_action.yaml - needs: check - permissions: - contents: read - pull-requests: read + release: needs: @@ -141,6 +107,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: + # fetch all history so we can calculate the version and tagging fetch-depth: 0 token: ${{ steps.generate_token.outputs.token }} @@ -188,14 +155,12 @@ jobs: run: | BASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate print-version) echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV - - name: Set Pre-Release Version if: inputs.release_candidate == true run: | RELEASE_VERSION=v$(go run $GITHUB_WORKSPACE/api/version/generate --no-dev print-rc-version ${{ github.event.inputs.prerelease }}) echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV echo "release name is $RELEASE_VERSION" - - name: Set Version if: inputs.release_candidate == false run: | diff --git a/Makefile b/Makefile index de950abc41..e33fb4c075 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ PLATFORMS = windows/amd64 darwin/arm64 darwin/amd64 linux/amd64 linux/arm64 CREDS ?= OCM := go run $(REPO_ROOT)/cmds/ocm $(CREDS) -CTF_TYPE ?= tgz +CTF_TYPE ?= directory GEN := $(REPO_ROOT)/gen @@ -37,25 +37,25 @@ build: bin bin/ocm bin/helminstaller bin/demo bin/cliplugin bin/ecrplugin bin: mkdir -p bin -bin/ocm: bin ${SOURCES} +bin/ocm: bin $(SOURCES) CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/ocm ./cmds/ocm -bin/helminstaller: bin ${SOURCES} +bin/helminstaller: bin $(SOURCES) CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/helminstaller ./cmds/helminstaller -bin/demo: bin ${SOURCES} +bin/demo: bin $(SOURCES) CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/demo ./cmds/demoplugin -bin/cliplugin: bin ${SOURCES} +bin/cliplugin: bin $(SOURCES) CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/cliplugin ./cmds/cliplugin -bin/ecrplugin: bin ${SOURCES} +bin/ecrplugin: bin $(SOURCES) CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/ecrplugin ./cmds/ecrplugin -api: ${SOURCES} +api: $(SOURCES) go build ./api/... -examples: ${SOURCES} +examples: $(SOURCES) go build ./examples/... diff --git a/components/demoplugin/Makefile b/components/demoplugin/Makefile index 14ae276201..4e1a35502f 100644 --- a/components/demoplugin/Makefile +++ b/components/demoplugin/Makefile @@ -4,6 +4,7 @@ GITHUBORG ?= open-component-model COMPONENT = $(PROVIDER)/plugins/$(NAME) OCMREPO ?= ghcr.io/$(GITHUBORG)/ocm PLATFORMS = linux/amd64 linux/arm64 +CTF_TYPE ?= directory REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/../.. VERSION = $(shell go run ../../api/version/generate/release_generate.go print-rc-version $(CANDIDATE)) @@ -12,7 +13,7 @@ EFFECTIVE_VERSION = $(VERSION)+$(COMMIT) GIT_TREE_STATE := $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] && echo clean || echo dirty) CMDSRCS=$(shell find $(REPO_ROOT)/cmds/$(NAME) -type f) -OCMSRCS=$(shell find $(REPO_ROOT)/pkg -type f) $(REPO_ROOT)/go.* +OCMSRCS=$(shell find $(REPO_ROOT)/api -type f) $(REPO_ROOT)/go.* CREDS ?= # Define the path to the binary @@ -28,6 +29,9 @@ OCM = $(OCM_BIN) $(CREDS) GEN = $(REPO_ROOT)/gen/$(NAME) + $(GEN): + @mkdir -p $(GEN) + NOW := $(shell date -u +%FT%T%z) BUILD_FLAGS := "-s -w \ -X ocm.software/ocm/api/version.gitVersion=$(EFFECTIVE_VERSION) \ @@ -35,11 +39,10 @@ BUILD_FLAGS := "-s -w \ -X ocm.software/ocm/api/version.gitCommit=$(COMMIT) \ -X ocm.software/ocm/api/version.buildDate=$(NOW)" - .PHONY: build build: $(GEN)/build -$(GEN)/build: $(CMDSRCS) $(OCMSRCS) +$(GEN)/build: $(GEN) $(CMDSRCS) $(OCMSRCS) @for i in $(PLATFORMS); do \ tag=$$(echo $$i | sed -e s:/:-:g); \ echo GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(NAME); \ @@ -51,23 +54,27 @@ $(GEN)/build: $(CMDSRCS) $(OCMSRCS) .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca.done $(OCM_BIN) +$(GEN)/ctf: $(OCM_BIN) $(GEN)/.exists $(GEN)/build component-constructor.yaml $(CHARTSRCS) @rm -rf "$(GEN)/ctf" - $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf + $(OCM) add componentversions \ + --create \ + --file $(GEN)/ctf \ + --type $(CTF_TYPE) \ + --templater=spiff \ + COMPONENT="$(COMPONENT)" \ + NAME="$(NAME)" \ + VERSION="$(VERSION)" \ + PROVIDER="$(PROVIDER)" \ + COMMIT="$(COMMIT)" \ + GEN="$(GEN)" \ + PLATFORMS="$(PLATFORMS)" \ + component-constructor.yaml touch "$(GEN)/ctf" .PHONY: version version: @echo $(VERSION) -.PHONY: ca -ca: $(GEN)/ca.done - -$(GEN)/ca.done: $(GEN)/.exists $(GEN)/build resources.yaml $(CHARTSRCS) $(OCM_BIN) - $(OCM) create ca -f $(COMPONENT) "$(VERSION)" --provider $(PROVIDER) --file $(GEN)/ca - $(OCM) add resources --templater=spiff --file $(GEN)/ca NAME="$(NAME)" VERSION="$(VERSION)" COMMIT="$(COMMIT)" GEN="$(GEN)" PLATFORMS="$(PLATFORMS)" resources.yaml - @touch $(GEN)/ca.done - .PHONY: push push: $(GEN)/ctf $(GEN)/push.$(NAME) @@ -97,12 +104,12 @@ info: @echo "COMMIT; $(COMMIT)" .PHONY: describe -describe: $(GEN)/ctf - ocm get resources --lookup $(OCMREPO) -c -o treewide $(GEN)/ctf +describe: $(GEN)/ctf $(OCM_BIN) + $(OCM) get resources --lookup $(OCMREPO) -c -o treewide $(GEN)/ctf .PHONY: descriptor -descriptor: $(GEN)/ctf - ocm get component -S v3alpha1 -o yaml $(GEN)/ctf +descriptor: $(GEN)/ctf $(OCM_BIN) + $(OCM) get component -S v3alpha1 -o yaml $(GEN)/ctf .PHONY: clean clean: diff --git a/components/demoplugin/component-constructor.yaml b/components/demoplugin/component-constructor.yaml new file mode 100644 index 0000000000..253566936f --- /dev/null +++ b/components/demoplugin/component-constructor.yaml @@ -0,0 +1,23 @@ +--- +helper: + <<<: (( &temporary )) + executable: + <<<: (( &template )) + name: demo + type: ocmPlugin + version: (( values.VERSION )) + extraIdentity: + os: ((dirname(p) )) + architecture: (( basename(p) )) + input: + type: file + # Generate the path to the plugin binary by looking into the base path and encoding the platform + path: (( values.GEN "/" values.NAME "." replace(p,"/","-") )) + +components: + - name: (( values.COMPONENT)) + version: (( values.VERSION)) + provider: + name: (( values.PROVIDER)) + # use all platforms and create a resource for each + resources: (( map[split(" ", values.PLATFORMS)|p|-> *helper.executable] )) \ No newline at end of file diff --git a/components/demoplugin/resources.yaml b/components/demoplugin/resources.yaml deleted file mode 100644 index ed51a5f1e9..0000000000 --- a/components/demoplugin/resources.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -helper: - <<<: (( &temporary )) - executable: - <<<: (( &template )) - name: demo - type: ocmPlugin - version: (( values.VERSION )) - extraIdentity: - os: ((dirname(p) )) - architecture: (( basename(p) )) - input: - type: file - path: (( values.GEN "/" values.NAME "." replace(p,"/","-") )) - - -resources: (( map[split(" ", values.PLATFORMS)|p|-> *helper.executable] )) - diff --git a/components/ecrplugin/Makefile b/components/ecrplugin/Makefile index 2034ac669e..5a2175c995 100644 --- a/components/ecrplugin/Makefile +++ b/components/ecrplugin/Makefile @@ -4,6 +4,7 @@ GITHUBORG ?= open-component-model COMPONENT = $(PROVIDER)/plugins/$(NAME) OCMREPO ?= ghcr.io/$(GITHUBORG)/ocm PLATFORMS = linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 +CTF_TYPE ?= directory REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/../.. @@ -13,7 +14,7 @@ EFFECTIVE_VERSION = $(VERSION)+$(COMMIT) GIT_TREE_STATE := $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] && echo clean || echo dirty) CMDSRCS=$(shell find $(REPO_ROOT)/cmds/$(NAME) -type f) -OCMSRCS=$(shell find $(REPO_ROOT)/pkg -type f) $(REPO_ROOT)/go.* +OCMSRCS=$(shell find $(REPO_ROOT)/api -type f) $(REPO_ROOT)/go.* CREDS ?= # Define the path to the binary @@ -29,6 +30,9 @@ OCM = $(OCM_BIN) $(CREDS) GEN = $(REPO_ROOT)/gen/$(NAME) + $(GEN): + @mkdir -p $(GEN) + NOW := $(shell date -u +%FT%T%z) BUILD_FLAGS := "-s -w \ -X ocm.software/ocm/api/version.gitVersion=$(EFFECTIVE_VERSION) \ @@ -36,11 +40,10 @@ BUILD_FLAGS := "-s -w \ -X ocm.software/ocm/api/version.gitCommit=$(COMMIT) \ -X ocm.software/ocm/api/version.buildDate=$(NOW)" - .PHONY: build build: $(GEN)/build -$(GEN)/build: $(CMDSRCS) $(OCMSRCS) +$(GEN)/build: $(GEN) $(CMDSRCS) $(OCMSRCS) @for i in $(PLATFORMS); do \ tag=$$(echo $$i | sed -e s:/:-:g); \ echo GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(NAME); \ @@ -53,28 +56,27 @@ $(GEN)/build: $(CMDSRCS) $(OCMSRCS) .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca.done $(OCM_BIN) +$(GEN)/ctf: $(OCM_BIN) $(GEN)/.exists $(GEN)/build component-constructor.yaml $(CHARTSRCS) @rm -rf "$(GEN)/ctf" - $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf + $(OCM) add componentversions \ + --create \ + --file $(GEN)/ctf \ + --type $(CTF_TYPE) \ + --templater=spiff \ + COMPONENT="$(COMPONENT)" \ + NAME="$(NAME)" \ + VERSION="$(VERSION)" \ + PROVIDER="$(PROVIDER)" \ + COMMIT="$(COMMIT)" \ + GEN="$(GEN)" \ + PLATFORMS="$(PLATFORMS)" \ + component-constructor.yaml touch "$(GEN)/ctf" .PHONY: version version: @echo $(VERSION) -.PHONY: ca -ca: $(GEN)/ca.done - -$(GEN)/ca.done: $(GEN)/.exists $(GEN)/build resources.yaml $(CHARTSRCS) $(OCM_BIN) - $(OCM) create ca -f $(COMPONENT) "$(VERSION)" --provider $(PROVIDER) --file $(GEN)/ca - $(OCM) add resources --templater=spiff --file $(GEN)/ca NAME="$(NAME)" VERSION="$(VERSION)" COMMIT="$(COMMIT)" GEN="$(GEN)" PLATFORMS="$(PLATFORMS)" resources.yaml - @touch $(GEN)/ca.done - -.PHONY: plain-ca -plain-ca: $(GEN)/.exists resources.yaml $(CHARTSRCS) $(OCM_BIN) - $(OCM) create ca -f $(COMPONENT) "$(VERSION)" --provider $(PROVIDER) --file $(GEN)/ca - $(OCM) add resources --templater=spiff --file $(GEN)/ca NAME="$(NAME)" VERSION="$(VERSION)" COMMIT="$(COMMIT)" GEN="$(GEN)" PLATFORMS="$(PLATFORMS)" resources.yaml - .PHONY: push push: $(GEN)/ctf $(GEN)/push.$(NAME) @@ -104,12 +106,12 @@ info: @echo "COMMIT; $(COMMIT)" .PHONY: describe -describe: $(GEN)/ctf - ocm get resources --lookup $(OCMREPO) -c -o treewide $(GEN)/ctf +describe: $(GEN)/ctf $(OCM_BIN) + $(OCM) get resources --lookup $(OCMREPO) -c -o treewide $(GEN)/ctf .PHONY: descriptor -descriptor: $(GEN)/ctf - ocm get component -S v3alpha1 -o yaml $(GEN)/ctf +descriptor: $(GEN)/ctf $(OCM_BIN) + $(OCM) get component -S v3alpha1 -o yaml $(GEN)/ctf .PHONY: clean clean: diff --git a/components/ecrplugin/component-constructor.yaml b/components/ecrplugin/component-constructor.yaml new file mode 100644 index 0000000000..253566936f --- /dev/null +++ b/components/ecrplugin/component-constructor.yaml @@ -0,0 +1,23 @@ +--- +helper: + <<<: (( &temporary )) + executable: + <<<: (( &template )) + name: demo + type: ocmPlugin + version: (( values.VERSION )) + extraIdentity: + os: ((dirname(p) )) + architecture: (( basename(p) )) + input: + type: file + # Generate the path to the plugin binary by looking into the base path and encoding the platform + path: (( values.GEN "/" values.NAME "." replace(p,"/","-") )) + +components: + - name: (( values.COMPONENT)) + version: (( values.VERSION)) + provider: + name: (( values.PROVIDER)) + # use all platforms and create a resource for each + resources: (( map[split(" ", values.PLATFORMS)|p|-> *helper.executable] )) \ No newline at end of file diff --git a/components/ecrplugin/resources.yaml b/components/ecrplugin/resources.yaml deleted file mode 100644 index 69e59a7b55..0000000000 --- a/components/ecrplugin/resources.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -helper: - <<<: (( &temporary )) - executable: - <<<: (( &template )) - name: (( values.NAME )) - type: ocmPlugin - version: (( values.VERSION )) - extraIdentity: - os: ((dirname(p) )) - architecture: (( basename(p) )) - input: - type: file - path: (( values.GEN "/" values.NAME "." replace(p,"/","-") )) - - -resources: (( map[split(" ", values.PLATFORMS)|p|-> *helper.executable] )) - diff --git a/components/helmdemo/Makefile b/components/helmdemo/Makefile index 12d858db1f..4ceba662ff 100644 --- a/components/helmdemo/Makefile +++ b/components/helmdemo/Makefile @@ -3,6 +3,7 @@ PROVIDER ?= ocm.software GITHUBORG ?= open-component-model COMPONENT = $(PROVIDER)/toi/demo/$(NAME) OCMREPO ?= ghcr.io/$(GITHUBORG)/ocm +CTF_TYPE ?= directory HELMINSTCOMP = $(PROVIDER)/toi/installers/helminstaller @@ -26,6 +27,9 @@ OCM = $(OCM_BIN) $(CREDS) GEN := $(REPO_ROOT)/gen/$(NAME) +$(GEN): + @mkdir -p $(GEN) + NOW := $(shell date -u +%FT%T%z) BUILD_FLAGS := "-s -w \ -X ocm.software/ocm/api/version.gitVersion=$(EFFECTIVE_VERSION) \ @@ -38,29 +42,28 @@ CHARTSRCS=$(shell find echoserver -type f) .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca $(OCM_BIN) +$(GEN)/ctf: $(OCM_BIN) $(GEN)/.exists $(CHARTSRCS) $(GEN) component-constructor.yaml packagespec.yaml examples/* helmconfig.yaml @rm -rf $(GEN)/ctf - $(OCM) -X keeplocalblob=true transfer ca $(GEN)/ca $(GEN)/ctf + $(OCM) add componentversions \ + --create \ + --file $(GEN)/ctf \ + --type $(CTF_TYPE) \ + --templater=spiff \ + COMPONENT="$(COMPONENT)" \ + NAME="$(NAME)" \ + VERSION="$(VERSION)" \ + PROVIDER="$(PROVIDER)" \ + COMMIT="$(COMMIT)" \ + GEN="$(GEN)" \ + HELMINSTCOMP=$(HELMINSTCOMP) \ + HELMINSTVERSION=$(HELMINSTVERSION) \ + component-constructor.yaml touch $(GEN)/ctf .PHONY: version version: @echo $(VERSION) -.PHONY: ca -ca: $(GEN)/ca - -$(GEN)/ca: $(GEN)/.exists sources.yaml resources.yaml references.yaml $(CHARTSRCS) packagespec.yaml examples/* helmconfig.yaml $(OCM_BIN) - $(OCM) create ca -f $(COMPONENT) "$(VERSION)" --provider $(PROVIDER) --file $(GEN)/ca - $(OCM) add sources $(GEN)/ca VERSION="$(VERSION)" COMMIT="$(COMMIT)" sources.yaml - $(OCM) add resources $(GEN)/ca VERSION="$(VERSION)" COMMIT="$(COMMIT)" resources.yaml - $(OCM) add references $(GEN)/ca VERSION="$(VERSION)" COMMIT="$(COMMIT)" HELMINSTCOMP=$(HELMINSTCOMP) HELMINSTVERSION=$(HELMINSTVERSION) references.yaml - @touch $(GEN)/ca - -.PHONY: eval-resources -eval-resources: $(OCM_BIN) - $(OCM) add resources --dry-run VERSION="$(VERSION)" COMMIT="$(COMMIT)" resources.yaml -O "$(GEN)/resources.yaml" - .PHONY: push push: $(GEN)/ctf $(GEN)/push.$(NAME) @@ -74,7 +77,7 @@ plain-push: $(GEN) $(OCM_BIN) @touch $(GEN)/push.$(NAME) .PHONY: transport -transport: $(OCM_BIN) +transport: ifneq ($(TARGETREPO),) $(OCM) -X keeplocalblob=true transfer component -Vc $(OCMREPO)//$(COMPONENT):$(VERSION) $(TARGETREPO) endif diff --git a/components/helmdemo/component-constructor.yaml b/components/helmdemo/component-constructor.yaml new file mode 100644 index 0000000000..11f1c78a65 --- /dev/null +++ b/components/helmdemo/component-constructor.yaml @@ -0,0 +1,58 @@ +components: + - name: (( values.COMPONENT)) + version: (( values.VERSION)) + provider: + name: (( values.PROVIDER)) + # use all platforms and create a resource for each +# ADD back once https://github.com/open-component-model/ocm/issues/1041 is fixed + componentReferences: + - name: installer + componentName: (( values.HELMINSTCOMP )) + version: (( values.HELMINSTVERSION )) + sources: + - name: source + type: filesytem + access: + type: github + repoUrl: github.com/open-component-model/ocm + commit: (( values.COMMIT )) + version: (( values.VERSION )) + resources: + - name: creds-example + type: yaml + labels: + - name: commit + value: (( values.COMMIT )) + input: + type: file + mediaType: application/vnd.toi.ocm.software.credentials.v1+yaml + path: examples/creds.yaml + - name: config-example + type: yaml + labels: + - name: commit + value: (( values.COMMIT )) + input: + type: file + mediaType: application/vnd.toi.ocm.software.config.v1+yaml + path: examples/config.yaml + - name: image + type: ociImage + version: "1.0" + access: + type: ociArtifact + imageReference: gcr.io/google-containers/echoserver:1.10 + - name: chart + type: helmChart + input: + type: helm + path: echoserver + - name: package + type: toiPackage + labels: + - name: commit + value: (( values.COMMIT )) + input: + type: spiff + mediaType: application/vnd.toi.ocm.software.package.v1+yaml + path: packagespec.yaml \ No newline at end of file diff --git a/components/helmdemo/references.yaml b/components/helmdemo/references.yaml deleted file mode 100644 index 6c0cf353b5..0000000000 --- a/components/helmdemo/references.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -name: installer -componentName: ${HELMINSTCOMP} -version: ${HELMINSTVERSION} diff --git a/components/helmdemo/resources.yaml b/components/helmdemo/resources.yaml deleted file mode 100644 index cec2758956..0000000000 --- a/components/helmdemo/resources.yaml +++ /dev/null @@ -1,43 +0,0 @@ ---- -name: package -type: toiPackage -labels: - - name: commit - value: ${COMMIT} -input: - type: spiff - mediaType: application/vnd.toi.ocm.software.package.v1+yaml - path: packagespec.yaml ---- -name: chart -type: helmChart -input: - type: helm - path: echoserver ---- -name: image -type: ociImage -version: "1.0" -access: - type: ociArtifact - imageReference: gcr.io/google-containers/echoserver:1.10 ---- -name: config-example -type: yaml -labels: - - name: commit - value: ${COMMIT} -input: - type: file - mediaType: application/vnd.toi.ocm.software.config.v1+yaml - path: examples/config.yaml ---- -name: creds-example -type: yaml -labels: - - name: commit - value: ${COMMIT} -input: - type: file - mediaType: application/vnd.toi.ocm.software.credentials.v1+yaml - path: examples/creds.yaml diff --git a/components/helmdemo/sources.yaml b/components/helmdemo/sources.yaml deleted file mode 100644 index dcc9c5f896..0000000000 --- a/components/helmdemo/sources.yaml +++ /dev/null @@ -1,7 +0,0 @@ -name: source -type: filesytem -access: - type: github - repoUrl: github.com/open-component-model/ocm - commit: ${COMMIT} -version: ${VERSION} diff --git a/components/helminstaller/Makefile b/components/helminstaller/Makefile index 24513b618c..ed3d368daa 100644 --- a/components/helminstaller/Makefile +++ b/components/helminstaller/Makefile @@ -6,6 +6,7 @@ COMPONENT := $(PROVIDER)/toi/installers/$(NAME) OCMREPO ?= ghcr.io/$(GITHUBORG)/ocm MULTI ?= true PLATFORMS ?= linux/amd64 linux/arm64 +CTF_TYPE ?= directory REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/../.. VERSION := $(shell go run ../../api/version/generate/release_generate.go print-rc-version $(CANDIDATE)) @@ -30,6 +31,9 @@ OCM = $(OCM_BIN) $(CREDS) GEN = $(REPO_ROOT)/gen/$(NAME) +$(GEN): + @mkdir -p $(GEN) + NOW := $(shell date -u +%FT%T%z) BUILD_FLAGS := "-s -w \ -X ocm.software/ocm/api/version.gitVersion=$(EFFECTIVE_VERSION) \ @@ -40,8 +44,6 @@ BUILD_FLAGS := "-s -w \ CMDSRCS=$(shell find $(REPO_ROOT)/cmds/$(NAME) -type f) OCMSRCS=$(shell find $(REPO_ROOT)/pkg -type f) $(REPO_ROOT)/go.* -ATTRIBUTES = VERSION="$(VERSION)" COMMIT="$(COMMIT)" IMAGE="$(IMAGE):$(VERSION)" PLATFORMS="$(PLATFORMS)" MULTI=$(MULTI) - ifeq ($(MULTI),true) FLAGSUF = .multi endif @@ -49,39 +51,29 @@ endif .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca $(OCM_BIN) +$(GEN)/ctf: $(OCM_BIN) $(GEN)/.exists $(GEN)/image.$(NAME)$(FLAGSUF) component-constructor.yaml executorspec.yaml @rm -rf "$(GEN)/ctf" - $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf - touch $(GEN)/ctf - -.PHONY: plain-ctf -plain-ctf: $(OCM_BIN) - $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf - touch $(GEN)/ctf + $(OCM) add componentversions \ + --create \ + --file $(GEN)/ctf \ + --type $(CTF_TYPE) \ + --templater=spiff \ + COMPONENT="$(COMPONENT)" \ + NAME="$(NAME)" \ + VERSION="$(VERSION)" \ + PROVIDER="$(PROVIDER)" \ + COMMIT="$(COMMIT)" \ + GEN="$(GEN)" \ + PLATFORMS="$(PLATFORMS)" \ + MULTI="$(MULTI)" \ + IMAGE="$(IMAGE):$(VERSION)" \ + component-constructor.yaml + touch "$(GEN)/ctf" .PHONY: version version: @echo $(VERSION) -.PHONY: ca -ca: $(GEN)/ca - -$(GEN)/ca: $(GEN)/.exists $(GEN)/image.$(NAME)$(FLAGSUF) resources.yaml executorspec.yaml $(OCM_BIN) - $(OCM) create ca -f $(COMPONENT) "$(VERSION)" --provider $(PROVIDER) --file $(GEN)/ca - $(OCM) add resources --templater spiff $(GEN)/ca $(ATTRIBUTES) resources.yaml - @touch $(GEN)/ca - - -.PHONY: plain-ca -plain-ca: $(GEN)/.exists $(OCM_BIN) - $(OCM) create ca -f $(COMPONENT) "$(VERSION)" --provider $(PROVIDER) --file $(GEN)/ca - $(OCM) add resources --templater spiff $(GEN)/ca $(ATTRIBUTES) resources.yaml - @touch $(GEN)/ca - -.PHONY: eval-resources -eval-resources: $(OCM_BIN) - $(OCM) add resources --dry-run --templater spiff $(ATTRIBUTES) resources.yaml - .PHONY: build build: $(GEN)/image.$(NAME)$(FLAGSUF) @@ -145,12 +137,12 @@ info: @echo "PATFORM: $(PLATFORM)" .PHONY: describe -describe: $(GEN)/ctf - ocm get resources --lookup $(OCMREPO) -r -o treewide $(GEN)/ctf +describe: $(OCM_BIN) $(GEN)/ctf + $(OCM) get resources --lookup $(OCMREPO) -r -o treewide $(GEN)/ctf .PHONY: descriptor -descriptor: $(GEN)/ctf - ocm get component -S v3alpha1 -o yaml $(GEN)/ctf +descriptor: $(OCM_BIN) $(GEN)/ctf + $(OCM) get component -S v3alpha1 -o yaml $(GEN)/ctf .PHONY: setup setup: diff --git a/components/helminstaller/a.yaml b/components/helminstaller/a.yaml deleted file mode 100644 index 21ceec38d8..0000000000 --- a/components/helminstaller/a.yaml +++ /dev/null @@ -1 +0,0 @@ -flag: (( flag ? "yes" :"no" )) diff --git a/components/helminstaller/component-constructor.yaml b/components/helminstaller/component-constructor.yaml new file mode 100644 index 0000000000..a2223653ad --- /dev/null +++ b/components/helminstaller/component-constructor.yaml @@ -0,0 +1,25 @@ +--- +components: + - name: (( values.COMPONENT)) + version: (( values.VERSION)) + provider: + name: (( values.PROVIDER)) + # use all platforms and create a resource for each + resources: + - name: toiexecutor + type: toiExecutor + labels: + - name: commit + value: (( values.COMMIT )) + input: + type: file + mediaType: application/x-yaml + path: executorspec.yaml + - name: toiimage + type: ociImage + version: (( values.VERSION )) + input: + type: (( bool(values.MULTI) ? "dockermulti" :"docker" )) + repository: (( index(values.IMAGE, ":") >= 0 ? substr(values.IMAGE,0,index(values.IMAGE,":")) :values.IMAGE )) + variants: (( bool(values.MULTI) ? map[split(" ", values.PLATFORMS)|v|-> values.IMAGE "-" replace(v,"/","-")] :~~ )) + path: (( !bool(values.MULTI) ? values.IMAGE :~~ )) \ No newline at end of file diff --git a/components/helminstaller/resources.yaml b/components/helminstaller/resources.yaml deleted file mode 100644 index 9a6f2ef0eb..0000000000 --- a/components/helminstaller/resources.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: toiimage -type: ociImage -version: (( values.VERSION )) -input: - type: (( bool(values.MULTI) ? "dockermulti" :"docker" )) - repository: (( index(values.IMAGE, ":") >= 0 ? substr(values.IMAGE,0,index(values.IMAGE,":")) :values.IMAGE )) - variants: (( bool(values.MULTI) ? map[split(" ", values.PLATFORMS)|v|-> values.IMAGE "-" replace(v,"/","-")] :~~ )) - path: (( !bool(values.MULTI) ? values.IMAGE :~~ )) ---- -name: toiexecutor -type: toiExecutor -labels: - - name: commit - value: (( values.COMMIT )) -input: - type: file - mediaType: application/x-yaml - path: executorspec.yaml - diff --git a/components/ocmcli/Makefile b/components/ocmcli/Makefile index 418712ca37..2502ef16e3 100644 --- a/components/ocmcli/Makefile +++ b/components/ocmcli/Makefile @@ -8,6 +8,7 @@ OCMREPO ?= ghcr.io/$(GITHUBORG)/ocm MULTI ?= true IMAGE_PLATFORMS ?= linux/amd64 linux/arm64 PLATFORMS = $(IMAGE_PLATFORMS) darwin/arm64 darwin/amd64 windows/amd64 +CTF_TYPE ?= directory REPO_ROOT := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))../.. GIT_TREE_STATE = $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] && echo clean || echo dirty) @@ -18,9 +19,7 @@ PLATFORM_OS := $(shell go env GOOS) PLATFORM_ARCH := $(shell go env GOARCH) CMDSRCS=$(shell find $(REPO_ROOT)/cmds/$(CMD) -type f) Makefile -OCMSRCS=$(shell find $(REPO_ROOT)/pkg -type f) $(REPO_ROOT)/go.* - -ATTRIBUTES = VERSION="$(VERSION)" NAME="$(NAME)" COMMIT="$(COMMIT)" IMAGE="$(IMAGE):$(VERSION)" PLATFORMS="$(PLATFORMS)" IMAGE_PLATFORMS="$(IMAGE_PLATFORMS)" GEN="$(GEN)" MULTI=$(MULTI) +OCMSRCS=$(shell find $(REPO_ROOT)/api -type f) $(REPO_ROOT)/go.* ifeq ($(MULTI),true) FLAGSUF = .multi @@ -38,7 +37,10 @@ $(OCM_BIN): $(REPO_ROOT)/cmds/ocm/main.go # Use the binary for the OCM command OCM = $(OCM_BIN) $(CREDS) -GEN = $(REPO_ROOT)/gen/$(shell basename $(realpath .)) +GEN = $(REPO_ROOT)/gen/$(NAME) + + $(GEN): + @mkdir -p $(GEN) NOW := $(shell date -u +%FT%T%z) BUILD_FLAGS := "-s -w \ @@ -52,7 +54,7 @@ ALPINE_LATEST_VER=$(shell curl -s https://registry.hub.docker.com/v2/repositorie .PHONY: build build: $(GEN)/build -$(GEN)/build: $(GEN)/.exists $(CMDSRCS) $(OCMSRCS) +$(GEN)/build: $(GEN) $(GEN)/.exists $(CMDSRCS) $(OCMSRCS) @for i in $(PLATFORMS); do \ tag=$$(echo $$i | sed -e s:/:-:g); \ echo GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(CMD); \ @@ -99,24 +101,30 @@ $(GEN)/image.multi: Dockerfile $(GEN)/build .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca.done $(OCM_BIN) +$(GEN)/ctf: $(OCM_BIN) $(GEN)/.exists $(GEN)/build $(GEN)/image$(FLAGSUF) component-constructor.yaml $(CHARTSRCS) Makefile @rm -rf "$(GEN)/ctf" - $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf - touch $(GEN)/ctf + $(OCM) add componentversions \ + --create \ + --file $(GEN)/ctf \ + --type $(CTF_TYPE) \ + --templater=spiff \ + COMPONENT="$(COMPONENT)" \ + NAME="$(NAME)" \ + VERSION="$(VERSION)" \ + PROVIDER="$(PROVIDER)" \ + COMMIT="$(COMMIT)" \ + GEN="$(GEN)" \ + PLATFORMS="$(PLATFORMS)" \ + IMAGE_PLATFORMS="$(IMAGE_PLATFORMS)" \ + MULTI=$(MULTI) \ + IMAGE="$(IMAGE):$(VERSION)" \ + component-constructor.yaml + touch "$(GEN)/ctf" .PHONY: version version: @echo $(VERSION) -.PHONY: ca -ca: $(GEN)/ca.done - -$(GEN)/ca.done: $(GEN)/.exists $(GEN)/build $(GEN)/image$(FLAGSUF) resources.yaml $(CHARTSRCS) Makefile $(OCM_BIN) - $(OCM) create ca -f $(COMPONENT) "$(VERSION)" --provider $(PROVIDER) --file $(GEN)/ca - $(OCM) add resources --templater=spiff --file $(GEN)/ca $(ATTRIBUTES) resources.yaml - $(OCM) add sources $(GEN)/ca VERSION="$(VERSION)" COMMIT="$(COMMIT)" sources.yaml - @touch $(GEN)/ca.done - .PHONY: push push: $(GEN)/ctf $(GEN)/push.$(NAME) @@ -147,12 +155,12 @@ info: @echo "GIT_TREE: $(GIT_TREE_STATE)" .PHONY: describe -describe: $(GEN)/ctf - ocm get resources --lookup $(OCMREPO) -c -o treewide $(GEN)/ctf +describe: $(GEN)/ctf $(OCM_BIN) + $(OCM) get resources --lookup $(OCMREPO) -c -o treewide $(GEN)/ctf .PHONY: descriptor -descriptor: $(GEN)/ctf - ocm get component -S v3alpha1 -o yaml $(GEN)/ctf +descriptor: $(GEN)/ctf $(OCM_BIN) + $(OCM) get component -S v3alpha1 -o yaml $(GEN)/ctf .PHONY: clean clean: diff --git a/components/ocmcli/resources.yaml b/components/ocmcli/component-constructor.yaml similarity index 63% rename from components/ocmcli/resources.yaml rename to components/ocmcli/component-constructor.yaml index ac152b9b83..11eb4bcecb 100644 --- a/components/ocmcli/resources.yaml +++ b/components/ocmcli/component-constructor.yaml @@ -26,6 +26,21 @@ helper: variants: (( bool(values.MULTI) ? map[split(" ", values.IMAGE_PLATFORMS)|v|-> values.IMAGE "-" replace(v,"/","-")] :~~ )) path: (( !bool(values.MULTI) ? values.IMAGE :~~ )) +components: + - name: (( values.COMPONENT)) + version: (( values.VERSION)) + provider: + name: (( values.PROVIDER)) + # use all platforms and create a resource for each + resources: (( map[split(" ", values.PLATFORMS)|p|-> *helper.executable] *helper.image )) + sources: + - name: source + type: filesytem + access: + type: github + repoUrl: github.com/open-component-model/ocm + commit: (( values.COMMIT )) + version: (( values.VERSION )) + -resources: (( map[split(" ", values.PLATFORMS)|p|-> *helper.executable] *helper.image )) diff --git a/components/ocmcli/sources.yaml b/components/ocmcli/sources.yaml deleted file mode 100644 index dcc9c5f896..0000000000 --- a/components/ocmcli/sources.yaml +++ /dev/null @@ -1,7 +0,0 @@ -name: source -type: filesytem -access: - type: github - repoUrl: github.com/open-component-model/ocm - commit: ${COMMIT} -version: ${VERSION}