diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml new file mode 100644 index 0000000..5dfab39 --- /dev/null +++ b/.github/workflows/build-and-release.yml @@ -0,0 +1,92 @@ +name: Build & Release + +on: + push: + branches: [main] + tags: ["v*"] + +permissions: {} + +jobs: + build: + permissions: + contents: read + packages: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0 + + - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - id: meta + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=sha + + - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + release: + if: startsWith(github.ref, 'refs/tags/') + needs: build + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: go.mod + + - name: Run tests + run: make test + + - name: Build release assets + env: + IMAGE: ghcr.io/${{ github.repository }}:${{ github.ref_name }} + run: | + make clusterctl-release \ + IMG="${IMAGE}" \ + CLUSTERCTL_RELEASE_VERSION="${GITHUB_REF_NAME}" + make build-installer IMG="${IMAGE}" + + - name: Generate checksums + run: | + release_dir="dist/clusterctl/infrastructure-stackit/${GITHUB_REF_NAME}" + ( + cd "${release_dir}" + find . -type f ! -name checksums.txt -print0 | sort -z | xargs -0 sha256sum + ) > "${release_dir}/checksums.txt" + sha256sum dist/install.yaml >> "${release_dir}/checksums.txt" + + - name: Publish GitHub release + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + run: | + release_dir="dist/clusterctl/infrastructure-stackit/${TAG}" + gh release create "${TAG}" \ + --title "${TAG}" \ + --generate-notes \ + "${release_dir}"/* \ + "${release_dir}"/addons/* \ + dist/install.yaml diff --git a/.github/workflows/build-container-image.yml b/.github/workflows/build-container-image.yml deleted file mode 100644 index bf3815d..0000000 --- a/.github/workflows/build-container-image.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build container image - -on: - push: - branches: [main] - tags: ["v*"] - -permissions: - contents: read - packages: write - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - - uses: docker/setup-buildx-action@v3 - - - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/${{ github.repository }} - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=sha - - - uses: docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0d3c1dd..a028856 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the code - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false @@ -67,4 +67,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0 + uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 06b19df..ea3ef10 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,12 +16,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Setup Go - uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: go-version-file: go.mod diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ff5508..bc616f0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,12 +16,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Clone the code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Setup Go - uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: go-version-file: go.mod diff --git a/Makefile b/Makefile index a88c218..431c0b6 100644 --- a/Makefile +++ b/Makefile @@ -207,8 +207,11 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform .PHONY: build-installer build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment. mkdir -p dist - cd config/manager && "$(KUSTOMIZE)" edit set image controller=${IMG} - "$(KUSTOMIZE)" build config/default > dist/install.yaml + tmp_dir="$$(mktemp -d)"; \ + trap 'rm -rf "$$tmp_dir"' EXIT; \ + cp -R config "$$tmp_dir/config"; \ + cd "$$tmp_dir/config/manager" && "$(KUSTOMIZE)" edit set image controller=${IMG}; \ + "$(KUSTOMIZE)" build "$$tmp_dir/config/default" > "$(CURDIR)/dist/install.yaml" .PHONY: clusterctl-release clusterctl-release: manifests generate kustomize ## Generate clusterctl release assets. diff --git a/docs/src/usage/clusterctl.md b/docs/src/usage/clusterctl.md index c344334..205e974 100644 --- a/docs/src/usage/clusterctl.md +++ b/docs/src/usage/clusterctl.md @@ -1,6 +1,23 @@ # clusterctl -The provider can be packaged as a local clusterctl repository: +Each release publishes `infrastructure-components.yaml`, `metadata.yaml`, and +cluster templates as GitHub Release assets. Install a published version with: + +```sh +clusterctl init \ + --infrastructure \ + https://github.com/stackitcloud/cluster-api-provider-stackit/releases/download/v/infrastructure-components.yaml +``` + +Or latest: + +```sh +clusterctl init \ + --infrastructure \ + https://github.com/stackitcloud/cluster-api-provider-stackit/releases/download/latest/infrastructure-components.yaml +``` + +For local development, package the provider as a local clusterctl repository: ```sh make clusterctl-release IMG=/cluster-api-provider-stackit: