diff --git a/.github/workflows/blackduck_scan_scheduled.yaml b/.github/workflows/blackduck_scan_scheduled.yaml index 2dbff357dd..4b2146e628 100644 --- a/.github/workflows/blackduck_scan_scheduled.yaml +++ b/.github/workflows/blackduck_scan_scheduled.yaml @@ -23,6 +23,24 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: '${{ github.workspace }}/go.mod' + cache: false + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) + with: + path: | + ${{ env.go_cache }} + ${{ env.go_modcache }} + key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }} + restore-keys: | + ${{ 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: Blackduck Full Scan uses: mercedesbenzio/detect-action@v2 diff --git a/.github/workflows/buildcomponents.yaml b/.github/workflows/buildcomponents.yaml index d86805b513..49807661ea 100644 --- a/.github/workflows/buildcomponents.yaml +++ b/.github/workflows/buildcomponents.yaml @@ -36,16 +36,14 @@ jobs: 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@v4 + uses: actions/cache/restore@v4 with: path: | ${{ env.go_cache }} ${{ env.go_modcache }} - key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }} - restore-keys: | - ${{ env.cache_name }}-${{ runner.os }}-go- + key: ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: buildcomponents-go-cache + 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 diff --git a/.github/workflows/check_diff_action.yaml b/.github/workflows/check_diff_action.yaml index d3439e427c..30cfeeb60b 100644 --- a/.github/workflows/check_diff_action.yaml +++ b/.github/workflows/check_diff_action.yaml @@ -21,9 +21,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see lint_and_test.yaml => "test" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -32,7 +37,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: diff-check-go-cache + cache_name: run-tests-go-cache # needs to be the same key in the end as in the build step - name: Make generate and deepcopy run: | diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 0e1964b0cd..7f05fae76d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -27,7 +27,8 @@ jobs: # - https://gh.io/supported-runners-and-hardware-resources # - https://gh.io/using-larger-runners (GitHub.com only) # Consider using larger runners or machines with greater resources for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + # - ADDENDUM: We moved this to a larger runner for faster analysis + runs-on: large_runner timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} permissions: # required for all workflows @@ -45,7 +46,7 @@ jobs: matrix: include: - language: go - build-mode: autobuild + build-mode: manual # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' # Use `c-cpp` to analyze code written in C, C++ or both # Use 'java-kotlin' to analyze code written in Java, Kotlin or both @@ -61,7 +62,39 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # Initializes the CodeQL tools for scanning. + + - name: Setup Go + uses: actions/setup-go@v5 + if: matrix.build-mode == 'manual' + with: + go-version-file: '${{ github.workspace }}/go.mod' + cache: false + + - name: Get go environment for use with cache + if: matrix.build-mode == 'manual' + run: | + echo "go_cache=$(go env GOCACHE)" >> $GITHUB_ENV + echo "go_modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + if: matrix.build-mode == 'manual' + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) + with: + path: | + ${{ env.go_cache }} + ${{ env.go_modcache }} + key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }} + restore-keys: | + ${{ 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 + + # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v3 with: @@ -74,20 +107,9 @@ jobs: # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs # queries: security-extended,security-and-quality - # If the analyze step fails for one of the languages you are analyzing with - # "We were unable to automatically build your code", modify the matrix above - # to set the build mode to "manual" for that language. Then modify this step - # to build your code. - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - if: matrix.build-mode == 'manual' - run: | - echo 'If you are using a "manual" build mode for one or more of the' \ - 'languages you are analyzing, replace this with the commands to build' \ - 'your code, for example:' - echo ' make bootstrap' - echo ' make release' - exit 1 + - name: Build + if: matrix.build-mode == 'manual' + run: make build -j - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/components.yaml b/.github/workflows/components.yaml index 88958fc9ed..dee82afeb0 100644 --- a/.github/workflows/components.yaml +++ b/.github/workflows/components.yaml @@ -28,9 +28,13 @@ jobs: 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@v4 + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -39,7 +43,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: cli-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: CTF run: | @@ -62,9 +66,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -73,7 +82,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: helminstaller-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: CTF run: | @@ -96,9 +105,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -107,7 +121,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: helmdemo-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: CTF run: | @@ -130,9 +144,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -141,7 +160,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: helm-subchart-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: CTF run: | @@ -167,9 +186,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -178,7 +202,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: ecr-plugin-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: CTF run: | diff --git a/.github/workflows/lint_and_test.yaml b/.github/workflows/lint_and_test.yaml index a728855768..20bfddb4a1 100644 --- a/.github/workflows/lint_and_test.yaml +++ b/.github/workflows/lint_and_test.yaml @@ -30,9 +30,17 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see lint_and_test.yaml => "test" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + # + # NOTE: This is different from our regular build cache (which contains all archs and is built in a different job) + # This is because it requires caching of test dependencies, which are compiled only for linux-amd64 for test runs in CI. + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -41,10 +49,27 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: run-tests-go-cache + cache_name: run-tests-go-cache # needs to be the same key in the end as in the build step + - name: Build + run: make build -j - name: Test - run: make build install-requirements test + run: make install-requirements test + + # NOTE: This is different from our regular build cache (which contains all archs and is built in a different job) + # This is because it requires caching of test dependencies, which are compiled only for linux-amd64 for test runs in CI. + - name: Save Cache of Build (only on main) + id: cache-golang-save + if: github.ref == 'refs/heads/main' # Only run on main, never in PR + uses: actions/cache/save@v4 # Only saves cache build-test (linux-amd64) + with: + path: | + ${{ env.go_cache }} + ${{ env.go_modcache }} + key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }} + upload-chunk-size: 256000000 # default of 32MB is not really optimal for our large cache, choose 256MB instead + env: + cache_name: run-tests-go-cache # needs to be the same key in the end as in the build step go-lint: name: Lint Golang @@ -64,9 +89,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -75,7 +105,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: golint-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: Install goimports run: go install golang.org/x/tools/cmd/goimports@latest diff --git a/.github/workflows/publish-latest.yaml b/.github/workflows/publish-latest.yaml index 7d2ee728b2..9d60f1dd52 100644 --- a/.github/workflows/publish-latest.yaml +++ b/.github/workflows/publish-latest.yaml @@ -108,9 +108,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -119,7 +124,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: ocm-cli-latest-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: Goreleaser release snapshot uses: goreleaser/goreleaser-action@v6 @@ -149,3 +154,16 @@ jobs: skipIfReleaseExists: false body: | holds always the latest ocm-cli binaries + + # This step is actually responsible for populating our build cache for the next runs in PRs or on main. + - name: Save Cache of Build (only on main) + id: cache-golang-save + uses: actions/cache/save@v4 # Only save build cache once + with: + path: | + ${{ env.go_cache }} + ${{ env.go_modcache }} + key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }} + upload-chunk-size: 256000000 # default of 32MB is not really optimal for our large cache, choose 256MB instead + env: + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step \ No newline at end of file diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index efa4b7c86c..59e819bed0 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -29,9 +29,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -40,7 +45,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: release-draft-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: Set Version run: | diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f84cd02dcb..d881b1aee4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -155,9 +155,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -166,7 +171,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: release-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: Setup Syft uses: anchore/sbom-action/download-syft@251a468eed47e5082b105c3ba6ee500c0e65a764 # v0.17.6 diff --git a/.github/workflows/releasenotes.yaml b/.github/workflows/releasenotes.yaml index 9988dd047c..bec485b73f 100644 --- a/.github/workflows/releasenotes.yaml +++ b/.github/workflows/releasenotes.yaml @@ -27,9 +27,14 @@ jobs: 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@v4 + + # This step will only reuse the go mod and build cache from main made during the Build, + # see push_ocm.yaml => "ocm-cli-latest" Job + # This means it never caches by itself and PRs cannot cause cache pollution / thrashing + # This is because we have huge storage requirements for our cache because of the mass of dependencies + - name: Restore / Reuse Cache from central build + id: cache-golang-restore + uses: actions/cache/restore@v4 # Only Restore, not build another cache (too big) with: path: | ${{ env.go_cache }} @@ -38,7 +43,7 @@ jobs: restore-keys: | ${{ env.cache_name }}-${{ runner.os }}-go- env: - cache_name: releasenotes-go-cache + cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step - name: Setup git config run: | diff --git a/Makefile b/Makefile index b7ca8a681b..de950abc41 100644 --- a/Makefile +++ b/Makefile @@ -27,26 +27,44 @@ BUILD_FLAGS := "-s -w \ -X ocm.software/ocm/api/version.gitTreeState=$(GIT_TREE_STATE) \ -X ocm.software/ocm/api/version.gitCommit=$(COMMIT) \ -X ocm.software/ocm/api/version.buildDate=$(NOW)" +CGO_ENABLED := 0 COMPONENTS ?= ocmcli helminstaller demoplugin ecrplugin helmdemo subchartsdemo -.PHONY: build -build: ${SOURCES} +.PHONY: build bin +build: bin bin/ocm bin/helminstaller bin/demo bin/cliplugin bin/ecrplugin + +bin: mkdir -p bin + +bin/ocm: bin ${SOURCES} + CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/ocm ./cmds/ocm + +bin/helminstaller: bin ${SOURCES} + CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/helminstaller ./cmds/helminstaller + +bin/demo: bin ${SOURCES} + CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/demo ./cmds/demoplugin + +bin/cliplugin: bin ${SOURCES} + CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/cliplugin ./cmds/cliplugin + +bin/ecrplugin: bin ${SOURCES} + CGO_ENABLED=$(CGO_ENABLED) go build -ldflags $(BUILD_FLAGS) -o bin/ecrplugin ./cmds/ecrplugin + +api: ${SOURCES} go build ./api/... + +examples: ${SOURCES} go build ./examples/... - CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/ocm ./cmds/ocm - CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/helminstaller ./cmds/helminstaller - CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/demo ./cmds/demoplugin - CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/cliplugin ./cmds/cliplugin - CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o bin/ecrplugin ./cmds/ecrplugin build-platforms: $(GEN)/.exists $(SOURCES) @for i in $(PLATFORMS); do \ echo GOARCH=$$(basename $$i) GOOS=$$(dirname $$i); \ - GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build ./cmds/ocm ./cmds/helminstaller ./cmds/ecrplugin; \ - done + GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=$(CGO_ENABLED) go build ./cmds/ocm ./cmds/helminstaller ./cmds/ecrplugin & \ + done; \ + wait .PHONY: install-requirements install-requirements: @@ -72,18 +90,18 @@ check-and-fix: .PHONY: force-test force-test: - @go test --count=1 $(EFFECTIVE_DIRECTORIES) + @go test -vet=off --count=1 $(EFFECTIVE_DIRECTORIES) -TESTFLAGS = --tags=integration +TESTFLAGS = -vet=off --tags=integration .PHONY: test test: @echo "> Run Tests" - go test $(TESTFLAGS) $(EFFECTIVE_DIRECTORIES) + go test $(TESTFLAGS) $(EFFECTIVE_DIRECTORIES) .PHONY: unit-test unit-test: @echo "> Run Unit Tests" - @go test $(EFFECTIVE_DIRECTORIES) + @go test -vet=off $(EFFECTIVE_DIRECTORIES) .PHONY: generate generate: diff --git a/components/demoplugin/Makefile b/components/demoplugin/Makefile index b10d4e36d3..14ae276201 100644 --- a/components/demoplugin/Makefile +++ b/components/demoplugin/Makefile @@ -15,7 +15,16 @@ CMDSRCS=$(shell find $(REPO_ROOT)/cmds/$(NAME) -type f) OCMSRCS=$(shell find $(REPO_ROOT)/pkg -type f) $(REPO_ROOT)/go.* CREDS ?= -OCM = go run $(REPO_ROOT)/cmds/ocm $(CREDS) +# Define the path to the binary +OCM_BIN = $(REPO_ROOT)/bin/ocm + +# Rule to build the binary if it doesn't exist or if the source code has changed +$(OCM_BIN): $(REPO_ROOT)/cmds/ocm/main.go + mkdir -p $(REPO_ROOT)/bin + go build -ldflags $(BUILD_FLAGS) -o $(OCM_BIN) $(REPO_ROOT)/cmds/ocm + +# Use the binary for the OCM command +OCM = $(OCM_BIN) $(CREDS) GEN = $(REPO_ROOT)/gen/$(NAME) @@ -34,15 +43,15 @@ $(GEN)/build: $(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); \ - GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(NAME); \ - done + GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(NAME) & \ + done; \ + wait @touch $(GEN)/build - .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca.done +$(GEN)/ctf: $(GEN)/ca.done $(OCM_BIN) @rm -rf "$(GEN)/ctf" $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf touch "$(GEN)/ctf" @@ -54,7 +63,7 @@ version: .PHONY: ca ca: $(GEN)/ca.done -$(GEN)/ca.done: $(GEN)/.exists $(GEN)/build resources.yaml $(CHARTSRCS) +$(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 @@ -62,17 +71,17 @@ $(GEN)/ca.done: $(GEN)/.exists $(GEN)/build resources.yaml $(CHARTSRCS) .PHONY: push push: $(GEN)/ctf $(GEN)/push.$(NAME) -$(GEN)/push.$(NAME): $(GEN)/ctf +$(GEN)/push.$(NAME): $(GEN)/ctf $(OCM_BIN) $(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: plain-push -plain-push: $(GEN) +plain-push: $(GEN) $(OCM_BIN) $(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: transport -transport: +transport: $(OCM_BIN) ifneq ($(TARGETREPO),) $(OCM) transfer component -Vc $(OCMREPO)//$(COMPONENT):$(VERSION) $(TARGETREPO) endif diff --git a/components/ecrplugin/Makefile b/components/ecrplugin/Makefile index 3f037f8f21..2034ac669e 100644 --- a/components/ecrplugin/Makefile +++ b/components/ecrplugin/Makefile @@ -16,7 +16,16 @@ CMDSRCS=$(shell find $(REPO_ROOT)/cmds/$(NAME) -type f) OCMSRCS=$(shell find $(REPO_ROOT)/pkg -type f) $(REPO_ROOT)/go.* CREDS ?= -OCM = go run $(REPO_ROOT)/cmds/ocm $(CREDS) +# Define the path to the binary +OCM_BIN = $(REPO_ROOT)/bin/ocm + +# Rule to build the binary if it doesn't exist or if the source code has changed +$(OCM_BIN): $(REPO_ROOT)/cmds/ocm/main.go + mkdir -p $(REPO_ROOT)/bin + go build -ldflags $(BUILD_FLAGS) -o $(OCM_BIN) $(REPO_ROOT)/cmds/ocm + +# Use the binary for the OCM command +OCM = $(OCM_BIN) $(CREDS) GEN = $(REPO_ROOT)/gen/$(NAME) @@ -35,15 +44,16 @@ $(GEN)/build: $(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); \ - GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(NAME); \ - done + GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(NAME) & \ + done; \ + wait @touch $(GEN)/build .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca.done +$(GEN)/ctf: $(GEN)/ca.done $(OCM_BIN) @rm -rf "$(GEN)/ctf" $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf touch "$(GEN)/ctf" @@ -55,30 +65,30 @@ version: .PHONY: ca ca: $(GEN)/ca.done -$(GEN)/ca.done: $(GEN)/.exists $(GEN)/build resources.yaml $(CHARTSRCS) +$(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) +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) -$(GEN)/push.$(NAME): $(GEN)/ctf +$(GEN)/push.$(NAME): $(GEN)/ctf $(OCM_BIN) $(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: plain-push -plain-push: $(GEN) +plain-push: $(GEN) $(OCM_BIN) $(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: transport -transport: +transport: $(OCM_BIN) ifneq ($(TARGETREPO),) $(OCM) transfer component -Vc $(OCMREPO)//$(COMPONENT):$(VERSION) $(TARGETREPO) endif diff --git a/components/helmdemo/Makefile b/components/helmdemo/Makefile index 6268331544..12d858db1f 100644 --- a/components/helmdemo/Makefile +++ b/components/helmdemo/Makefile @@ -13,16 +13,32 @@ EFFECTIVE_VERSION = $(VERSION)-$(COMMIT) HELMINSTVERSION ?= $(VERSION) CREDS ?= -OCM = go run $(REPO_ROOT)/cmds/ocm $(CREDS) +# Define the path to the binary +OCM_BIN = $(REPO_ROOT)/bin/ocm + +# Rule to build the binary if it doesn't exist or if the source code has changed +$(OCM_BIN): $(REPO_ROOT)/cmds/ocm/main.go + mkdir -p $(REPO_ROOT)/bin + go build -ldflags $(BUILD_FLAGS) -o $(OCM_BIN) $(REPO_ROOT)/cmds/ocm + +# Use the binary for the OCM command +OCM = $(OCM_BIN) $(CREDS) GEN := $(REPO_ROOT)/gen/$(NAME) +NOW := $(shell date -u +%FT%T%z) +BUILD_FLAGS := "-s -w \ + -X ocm.software/ocm/api/version.gitVersion=$(EFFECTIVE_VERSION) \ + -X ocm.software/ocm/api/version.gitTreeState=$(GIT_TREE_STATE) \ + -X ocm.software/ocm/api/version.gitCommit=$(COMMIT) \ + -X ocm.software/ocm/api/version.buildDate=$(NOW)" + CHARTSRCS=$(shell find echoserver -type f) .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca +$(GEN)/ctf: $(GEN)/ca $(OCM_BIN) @rm -rf $(GEN)/ctf $(OCM) -X keeplocalblob=true transfer ca $(GEN)/ca $(GEN)/ctf touch $(GEN)/ctf @@ -34,7 +50,7 @@ version: .PHONY: ca ca: $(GEN)/ca -$(GEN)/ca: $(GEN)/.exists sources.yaml resources.yaml references.yaml $(CHARTSRCS) packagespec.yaml examples/* helmconfig.yaml +$(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 @@ -42,23 +58,23 @@ $(GEN)/ca: $(GEN)/.exists sources.yaml resources.yaml references.yaml $(CHARTSRC @touch $(GEN)/ca .PHONY: eval-resources -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) -$(GEN)/push.$(NAME): $(GEN)/ctf +$(GEN)/push.$(NAME): $(GEN)/ctf $(OCM_BIN) $(OCM) -X keeplocalblob=true transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: plain-push -plain-push: $(GEN) +plain-push: $(GEN) $(OCM_BIN) $(OCM) -X keeplocalblob=true transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: transport -transport: +transport: $(OCM_BIN) ifneq ($(TARGETREPO),) $(OCM) -X keeplocalblob=true transfer component -Vc $(OCMREPO)//$(COMPONENT):$(VERSION) $(TARGETREPO) endif @@ -76,11 +92,11 @@ info: @echo "version for helminstaller: $(HELMINSTVERSION)" .PHONY: describe -describe: $(GEN)/ctf +describe: $(GEN)/ctf $(OCM_BIN) $(OCM) get resources --lookup $(OCMREPO) -r -o treewide $(GEN)/ctf .PHONY: descriptor -descriptor: $(GEN)/ctf +descriptor: $(GEN)/ctf $(OCM_BIN) $(OCM) get component -S v3alpha1 -o yaml $(GEN)/ctf .PHONY: clean diff --git a/components/helminstaller/Dockerfile b/components/helminstaller/Dockerfile index 008f78d481..f0d8aa97e4 100644 --- a/components/helminstaller/Dockerfile +++ b/components/helminstaller/Dockerfile @@ -8,8 +8,8 @@ COPY api api COPY cmds cmds COPY hack/generate-docs hack/generate-docs #COPY go/api api -RUN --mount=type=cache,target=/root/.cache/go-build go get -d ./... -RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ +RUN go get -d ./... +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ go build -o /main -ldflags "-s -w \ -X ocm.software/ocm/api/version.gitVersion=$EFFECTIVE_VERSION \ -X ocm.software/ocm/api/version.gitTreeState=$GIT_TREE_STATE \ diff --git a/components/helminstaller/Makefile b/components/helminstaller/Makefile index ccc438c2f1..24513b618c 100644 --- a/components/helminstaller/Makefile +++ b/components/helminstaller/Makefile @@ -13,12 +13,30 @@ COMMIT := $(shell git rev-parse --verify EFFECTIVE_VERSION := $(VERSION)-$(COMMIT) GIT_TREE_STATE := $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] && echo clean || echo dirty) PLATFORM := $(shell go env GOOS)/$(shell go env GOARCH) +CACHE_DIR := $(shell go env GOCACHE) +MOD_CACHE_DIR := $(shell go env GOMODCACHE) CREDS ?= -OCM = go run $(REPO_ROOT)/cmds/ocm $(CREDS) +# Define the path to the binary +OCM_BIN = $(REPO_ROOT)/bin/ocm + +# Rule to build the binary if it doesn't exist or if the source code has changed +$(OCM_BIN): $(REPO_ROOT)/cmds/ocm/main.go + mkdir -p $(REPO_ROOT)/bin + go build -ldflags $(BUILD_FLAGS) -o $(OCM_BIN) $(REPO_ROOT)/cmds/ocm + +# Use the binary for the OCM command +OCM = $(OCM_BIN) $(CREDS) GEN = $(REPO_ROOT)/gen/$(NAME) +NOW := $(shell date -u +%FT%T%z) +BUILD_FLAGS := "-s -w \ + -X ocm.software/ocm/api/version.gitVersion=$(EFFECTIVE_VERSION) \ + -X ocm.software/ocm/api/version.gitTreeState=$(GIT_TREE_STATE) \ + -X ocm.software/ocm/api/version.gitCommit=$(COMMIT) \ + -X ocm.software/ocm/api/version.buildDate=$(NOW)" + CMDSRCS=$(shell find $(REPO_ROOT)/cmds/$(NAME) -type f) OCMSRCS=$(shell find $(REPO_ROOT)/pkg -type f) $(REPO_ROOT)/go.* @@ -31,13 +49,13 @@ endif .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca +$(GEN)/ctf: $(GEN)/ca $(OCM_BIN) @rm -rf "$(GEN)/ctf" $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf touch $(GEN)/ctf .PHONY: plain-ctf -plain-ctf: +plain-ctf: $(OCM_BIN) $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf touch $(GEN)/ctf @@ -48,20 +66,20 @@ version: .PHONY: ca ca: $(GEN)/ca -$(GEN)/ca: $(GEN)/.exists $(GEN)/image.$(NAME)$(FLAGSUF) resources.yaml executorspec.yaml +$(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 +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: +eval-resources: $(OCM_BIN) $(OCM) add resources --dry-run --templater spiff $(ATTRIBUTES) resources.yaml .PHONY: build @@ -70,8 +88,10 @@ build: $(GEN)/image.$(NAME)$(FLAGSUF) $(GEN)/image.$(NAME): $(GEN)/.exists Dockerfile $(CMDSRCS) $(OCMSRCS) docker buildx build -t $(IMAGE):$(VERSION) --platform $(PLATFORM) --file Dockerfile $(REPO_ROOT) \ --build-arg COMMIT=$(COMMIT) \ + --build-arg CACHE_DIR=$(CACHE_DIR) \ + --build-arg MOD_CACHE_DIR=$(MOD_CACHE_DIR) \ --build-arg EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) \ - --build-arg GIT_TREE_STATE=$(GIT_TREE_STATE) + --build-arg GIT_TREE_STATE=$(GIT_TREE_STATE); \ @touch $(GEN)/image.$(NAME) push-image: @@ -87,6 +107,8 @@ $(GEN)/image.$(NAME).multi: $(GEN)/.exists Dockerfile $(CMDSRCS) $(OCMSRCS) echo building platform $$i; \ docker buildx build --load -t $(IMAGE):$(VERSION)-$$tag --platform $$i --file Dockerfile $(REPO_ROOT) \ --build-arg COMMIT=$(COMMIT) \ + --build-arg CACHE_DIR=$(CACHE_DIR) \ + --build-arg MOD_CACHE_DIR=$(MOD_CACHE_DIR) \ --build-arg EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) \ --build-arg GIT_TREE_STATE=$(GIT_TREE_STATE); \ done @@ -95,17 +117,17 @@ $(GEN)/image.$(NAME).multi: $(GEN)/.exists Dockerfile $(CMDSRCS) $(OCMSRCS) .PHONY: push push: $(GEN)/ctf $(GEN)/push.$(NAME) -$(GEN)/push.$(NAME): $(GEN)/ctf +$(GEN)/push.$(NAME): $(GEN)/ctf $(OCM_BIN) $(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: plain-push -plain-push: $(GEN)/.exists +plain-push: $(GEN)/.exists $(OCM_BIN) $(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: transport -transport: +transport: $(OCM_BIN) ifneq ($(TARGETREPO),) $(OCM) transfer component -Vr $(OCMREPO)//$(COMPONENT):$(VERSION) $(TARGETREPO) endif diff --git a/components/ocmcli/Makefile b/components/ocmcli/Makefile index 66979a20bc..418712ca37 100644 --- a/components/ocmcli/Makefile +++ b/components/ocmcli/Makefile @@ -27,7 +27,16 @@ FLAGSUF = .multi endif CREDS ?= -OCM = go run $(REPO_ROOT)/cmds/ocm $(CREDS) +# Define the path to the binary +OCM_BIN = $(REPO_ROOT)/bin/ocm + +# Rule to build the binary if it doesn't exist or if the source code has changed +$(OCM_BIN): $(REPO_ROOT)/cmds/ocm/main.go + mkdir -p $(REPO_ROOT)/bin + go build -ldflags $(BUILD_FLAGS) -o $(OCM_BIN) $(REPO_ROOT)/cmds/ocm + +# Use the binary for the OCM command +OCM = $(OCM_BIN) $(CREDS) GEN = $(REPO_ROOT)/gen/$(shell basename $(realpath .)) @@ -45,10 +54,11 @@ build: $(GEN)/build $(GEN)/build: $(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); \ - GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(CMD); \ - done + 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); \ + GOARCH=$$(basename $$i) GOOS=$$(dirname $$i) CGO_ENABLED=0 go build -ldflags $(BUILD_FLAGS) -o $(GEN)/$(NAME).$$tag ../../cmds/$(CMD) & \ + done; \ + wait @touch $(GEN)/build .PHONY: image @@ -89,7 +99,7 @@ $(GEN)/image.multi: Dockerfile $(GEN)/build .PHONY: ctf ctf: $(GEN)/ctf -$(GEN)/ctf: $(GEN)/ca.done +$(GEN)/ctf: $(GEN)/ca.done $(OCM_BIN) @rm -rf "$(GEN)/ctf" $(OCM) transfer ca $(GEN)/ca $(GEN)/ctf touch $(GEN)/ctf @@ -101,7 +111,7 @@ version: .PHONY: ca ca: $(GEN)/ca.done -$(GEN)/ca.done: $(GEN)/.exists $(GEN)/build $(GEN)/image$(FLAGSUF) resources.yaml $(CHARTSRCS) Makefile +$(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 @@ -110,17 +120,17 @@ $(GEN)/ca.done: $(GEN)/.exists $(GEN)/build $(GEN)/image$(FLAGSUF) resources.yam .PHONY: push push: $(GEN)/ctf $(GEN)/push.$(NAME) -$(GEN)/push.$(NAME): $(GEN)/ctf +$(GEN)/push.$(NAME): $(GEN)/ctf $(OCM_BIN) $(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: plain-push -plain-push: $(GEN) +plain-push: $(GEN) $(OCM_BIN) $(OCM) transfer ctf -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: transport -transport: +transport: $(OCM_BIN) ifneq ($(TARGETREPO),) $(OCM) transfer component -Vc $(OCMREPO)//$(COMPONENT):$(VERSION) $(TARGETREPO) endif diff --git a/components/subchartsdemo/Makefile b/components/subchartsdemo/Makefile index 67a3af7da6..3987b361e1 100644 --- a/components/subchartsdemo/Makefile +++ b/components/subchartsdemo/Makefile @@ -12,13 +12,30 @@ PODINFO_VERSION = 6.3.5 PODINFO_CHART_VERSION = 6.3.5 REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/../.. +GIT_TREE_STATE = $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] && echo clean || echo dirty) VERSION = $(shell go run $(REPO_ROOT)/api/version/generate/release_generate.go print-rc-version $(CANDIDATE)) COMMIT = $(shell git rev-parse HEAD) EFFECTIVE_VERSION = $(VERSION)-$(COMMIT) HELMINSTVERSION ?= $(VERSION) CREDS ?= -OCM = go run $(REPO_ROOT)/cmds/ocm $(CREDS) +# Define the path to the binary +OCM_BIN = $(REPO_ROOT)/bin/ocm + +# Rule to build the binary if it doesn't exist or if the source code has changed +$(OCM_BIN): $(REPO_ROOT)/cmds/ocm/main.go + mkdir -p $(REPO_ROOT)/bin + go build -ldflags $(BUILD_FLAGS) -o $(OCM_BIN) $(REPO_ROOT)/cmds/ocm + +# Use the binary for the OCM command +OCM = $(OCM_BIN) $(CREDS) + +NOW := $(shell date -u +%FT%T%z) +BUILD_FLAGS := "-s -w \ + -X ocm.software/ocm/api/version.gitVersion=$(EFFECTIVE_VERSION) \ + -X ocm.software/ocm/api/version.gitTreeState=$(GIT_TREE_STATE) \ + -X ocm.software/ocm/api/version.gitCommit=$(COMMIT) \ + -X ocm.software/ocm/api/version.buildDate=$(NOW)" GEN = $(REPO_ROOT)/gen/subchartsdemo @@ -31,7 +48,7 @@ ctf: $(GEN)/ctf version: @echo $(VERSION) -$(GEN)/ctf: $(GEN)/.exists component-constructor.yaml $(ECHOCHARTSRCS) packagespec.yaml podinfo/podinfo-$(PODINFO_CHART_VERSION).tgz +$(GEN)/ctf: $(GEN)/.exists component-constructor.yaml $(ECHOCHARTSRCS) packagespec.yaml podinfo/podinfo-$(PODINFO_CHART_VERSION).tgz $(OCM_BIN) @rm -rf $(GEN)/ctf $(OCM) add componentversions --create VERSION="$(VERSION)" COMMIT="$(COMMIT)" COMPONENT_PREFIX=$(COMPONENT_PREFIX) PROVIDER=$(PROVIDER) PODINFO_VERSION=$(PODINFO_VERSION) PODINFO_CHART_VERSION=$(PODINFO_CHART_VERSION) HELMINSTCOMP=$(HELMINSTCOMP) HELMINSTVERSION=$(HELMINSTVERSION) ECHO_VERSION=$(ECHO_VERSION) ECHO_CHART_VERSION=$(ECHO_CHART_VERSION) --file $(GEN)/ctf component-constructor.yaml @touch $(GEN)/ctf @@ -39,12 +56,12 @@ $(GEN)/ctf: $(GEN)/.exists component-constructor.yaml $(ECHOCHARTSRCS) packagesp .PHONY: push push: $(GEN)/ctf $(GEN)/push.$(NAME) -$(GEN)/push.$(NAME): $(GEN)/ctf +$(GEN)/push.$(NAME): $(GEN)/ctf $(OCM_BIN) $(OCM) -X keeplocalblob=true transfer ctf --copy-resources -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME) .PHONY: plain-push -plain-push: $(GEN) +plain-push: $(GEN) $(OCM_BIN) $(OCM) -X keeplocalblob=true transfer ctf --copy-resources -f $(GEN)/ctf $(OCMREPO) @touch $(GEN)/push.$(NAME)