diff --git a/.envrc b/.envrc index 5a606f32e..84fc8e536 100644 --- a/.envrc +++ b/.envrc @@ -1,11 +1,7 @@ -strict_env +# Automatically sets up your devbox environment whenever you cd into this +# directory via our direnv integration: -source_env_if_exists .envrc.local-asdf +eval "$(devbox generate direnv --print-envrc)" -use asdf - -PATH_add .local/bin - -source_env_if_exists envrc.local - -command -v yamale &>/dev/null || pip install yamale +# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/ +# for more details diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index c6042e1e3..d319c50c3 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -26,13 +26,13 @@ jobs: - name: Check out code uses: actions/checkout@v3 - - name: Install asdf - uses: asdf-vm/actions/setup@v2 + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.5.0 with: - asdf_branch: v0.11.3 + enable-cache: true - name: Run unit tests - run: make test + run: devbox run -- make test - name: Annotate tests if: always() @@ -48,76 +48,97 @@ jobs: with: fetch-depth: 0 - - name: Install asdf - uses: asdf-vm/actions/setup@v2 + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.5.0 with: - asdf_branch: v0.11.3 + enable-cache: true - name: Build and install on KinD - run: make dev.run-on-kind + run: devbox run -- make dev.run-on-kind env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run e2e tests - run: make e2e-test + run: devbox run -- make e2e-test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Cleanup KinD cluster if: always() - run: make kind.delete + run: devbox run -- make kind.delete - lint: + lint-go: runs-on: ubuntu-22.04 steps: - name: Check out code uses: actions/checkout@v3 - - name: Gather tool versions - uses: endorama/asdf-parse-tool-versions@v1 + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.5.0 + with: + enable-cache: true + + - name: Export golang and golangci-lint versions id: versions + run: | + echo "golangci-lint=$(devbox run -- golangci-lint version --format short)" >>"${GITHUB_OUTPUT}" + echo "golang=$(devbox run -- go version | grep -o "[[:digit:]]\+.[[:digit:]]\+\(.[[:digit:]]\+\)\?")" >>"${GITHUB_OUTPUT}" - name: golangci-lint uses: reviewdog/action-golangci-lint@v2 with: fail_on_error: true reporter: github-pr-review - golangci_lint_version: v${{ fromJson(steps.versions.outputs.tools).golangci-lint }} - go_version: v${{ fromJson(steps.versions.outputs.tools).golang }} + golangci_lint_version: v${{ steps.versions.outputs.golangci-lint }} + go_version: v${{ steps.versions.outputs.golang }} - pre-commit: + lint-gha: runs-on: ubuntu-22.04 steps: - name: Check out code uses: actions/checkout@v3 - - name: Gather tool versions - uses: endorama/asdf-parse-tool-versions@v1 - id: versions - - - uses: actions/setup-go@v4 + - name: actionlint + uses: reviewdog/action-actionlint@v1 with: - go-version: ${{ fromJson(steps.versions.outputs.tools).golang }} - check-latest: false - cache: true + fail_on_error: true + reporter: github-pr-review - - uses: mfinelli/setup-shfmt@v2 + lint-dockerfile: + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: actionlint + uses: reviewdog/action-hadolint@v1 with: - shfmt-version: ${{ fromJson(steps.versions.outputs.tools).shfmt }} + fail_on_error: true + reporter: github-pr-review - - name: Install asdf - uses: asdf-vm/actions/setup@v2 + pre-commit: + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v3 with: - asdf_branch: v0.11.3 + ref: ${{ github.event.pull_request.head.sha }} - - name: Install helm-docs - run: make install-tool.helm-docs + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.5.0 + with: + enable-cache: true - - uses: pre-commit/action@v3.0.0 + - name: Set up pre-commit cache + uses: actions/cache@v3 with: - extra_args: --all-files --show-diff-on-failure + path: ~/.cache/pre-commit + key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + + - name: Run pre-commit + run: devbox run -- make pre-commit env: - SKIP: no-commit-to-branch,golangci-lint + SKIP: no-commit-to-branch,golangci-lint,actionlint-system lint-test-helm: runs-on: ubuntu-22.04 @@ -127,70 +148,53 @@ jobs: with: fetch-depth: 0 - - name: Gather tool versions - uses: endorama/asdf-parse-tool-versions@v1 - id: versions - - - name: Set up Helm - uses: azure/setup-helm@v3 - with: - version: v${{ fromJson(steps.versions.outputs.tools).helm }} - - - uses: actions/setup-python@v4 + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.5.0 with: - python-version: '3.10' - check-latest: true - - - name: Set up chart-testing - uses: helm/chart-testing-action@v2 - with: - version: v${{ fromJson(steps.versions.outputs.tools).helm-ct }} - yamllint_version: ${{ fromJson(steps.versions.outputs.tools).yamllint }} + enable-cache: true - name: Run chart-testing (list-changed) id: list-changed run: | - changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }}) + git fetch origin main:main + changed=$(devbox run -- ct list-changed --target-branch ${{ github.event.repository.default_branch }}) if [[ -n "$changed" ]]; then echo "changed=true" >> "$GITHUB_OUTPUT" fi - if: steps.list-changed.outputs.changed == 'true' name: Run chart-testing (lint) - run: ct lint --config charts/ct-config.yaml + run: devbox run -- ct lint --config charts/ct-config.yaml - if: steps.list-changed.outputs.changed == 'true' name: Create kind cluster - uses: helm/kind-action@v1 - with: - version: v${{ fromJson(steps.versions.outputs.tools).kind }} - kubectl_version: v${{ fromJson(steps.versions.outputs.tools).kubectl }} - node_image: ghcr.io/mesosphere/kind-node:v${{ fromJson(steps.versions.outputs.tools).kubectl }} + run: | + devbox run -- kind create cluster \ + --image=ghcr.io/mesosphere/kind-node:"$(kubectl version --output=json --client | gojq --raw-output .clientVersion.gitVersion)" \ + --name=chart-testing env: KUBECONFIG: ct-kind-kubeconfig - - if: steps.list-changed.outputs.changed == 'true' - name: Install asdf - uses: asdf-vm/actions/setup@v2 - with: - asdf_branch: v0.11.3 - - if: steps.list-changed.outputs.changed == 'true' name: Build Docker images - run: make release-snapshot + run: devbox run -- make release-snapshot - if: steps.list-changed.outputs.changed == 'true' name: Sideload docker image - run: kind load docker-image --name chart-testing "$(jq -r '.[] | select(.type == "Docker Image" and .goos == "linux" and .goarch == "amd64").name' dist/artifacts.json)" + run: devbox run -- kind load docker-image --name chart-testing "$(jq -r '.[] | select(.type == "Docker Image" and .goos == "linux" and .goarch == "amd64").name' dist/artifacts.json)" - if: steps.list-changed.outputs.changed == 'true' name: Setup Cluster API and cert-manager - run: make clusterctl.init + run: devbox run -- make clusterctl.init env: KIND_KUBECONFIG: ct-kind-kubeconfig - if: steps.list-changed.outputs.changed == 'true' name: Run chart-testing (install) - run: ct install --config charts/ct-config.yaml --helm-extra-set-args "--set=image.tag=$(jq -r .version dist/metadata.json)" + run: devbox run -- ct install --config charts/ct-config.yaml --helm-extra-set-args "--set=image.tag=$(jq -r .version dist/metadata.json)" env: KUBECONFIG: ct-kind-kubeconfig + + - if: steps.list-changed.outputs.changed == 'true' && always() + name: + run: devbox run -- kind delete cluster --name chart-testing || true diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index f92d917b5..416912c8f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -30,13 +30,13 @@ jobs: with: languages: ${{ matrix.language }} - - name: Install tools via asdf - uses: asdf-vm/actions/install@master + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.5.0 with: - asdf_branch: v0.11.3 + enable-cache: true - name: Build - run: make build-snapshot + run: devbox run -- make build-snapshot - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/recover-secret.yaml b/.github/workflows/recover-secret.yaml deleted file mode 100644 index 39115d44f..000000000 --- a/.github/workflows/recover-secret.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2023 D2iQ, Inc. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -on: workflow_dispatch -jobs: - openssl: - name: Recover Secret With OpenSSL - runs-on: ubuntu-22.04 - steps: - - env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - OPENSSL_PASSWORD: ${{ secrets.OPENSSL_PASSWORD }} - OPENSSL_ITER: ${{ secrets.OPENSSL_ITER }} - run: | - echo "$(echo "${DOCKER_PASSWORD}" | openssl enc -e -aes-256-cbc -a -pbkdf2 -iter ${OPENSSL_ITER} -k "${OPENSSL_PASSWORD}")" - echo "Copy the above value, and then execute locally:" - echo "echo PASTE_HERE | openssl base64 -d | openssl enc -d -pbkdf2 -iter \$OPENSSL_ITER -aes-256-cbc -k \$OPENSSL_PASSWORD" diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml index 64d0b3012..45a262f4e 100644 --- a/.github/workflows/release-please.yaml +++ b/.github/workflows/release-please.yaml @@ -8,6 +8,11 @@ on: branches: - main +permissions: + contents: write + pull-requests: write + actions: write + jobs: release-please: runs-on: ubuntu-22.04 @@ -21,54 +26,8 @@ jobs: changelog-notes-type: github - if: ${{ steps.release-please.outputs.release_created }} - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - if: ${{ steps.release-please.outputs.release_created }} - name: Fetch all tags - run: git fetch --force --tags - - - if: ${{ steps.release-please.outputs.release_created }} - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - if: ${{ steps.release-please.outputs.release_created }} - name: Gather tool versions - uses: endorama/asdf-parse-tool-versions@v1 - id: versions - - - if: ${{ steps.release-please.outputs.release_created }} - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - if: ${{ steps.release-please.outputs.release_created }} - name: Install go - uses: actions/setup-go@v4 - with: - go-version: ${{ fromJson(steps.versions.outputs.tools).golang }} - check-latest: false - cache: true - - - if: ${{ steps.release-please.outputs.release_created }} - name: Run goreleaser - uses: goreleaser/goreleaser-action@v4 - with: - distribution: goreleaser - version: ${{ fromJson(steps.versions.outputs.tools).goreleaser }} - args: release --clean - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - if: ${{ steps.release-please.outputs.release_created }} - name: Publish Helm chart - uses: stefanprodan/helm-gh-pages@v1.7.0 + name: Run release workflow + uses: benc-uk/workflow-dispatch@v121 with: - token: ${{ secrets.GITHUB_TOKEN }} - app_version: ${{ steps.release-please.outputs.tag_name }} - chart_version: ${{ steps.release-please.outputs.tag_name }} - target_dir: repo + workflow: release-tag.yaml + ref: ${{ steps.release-please.outputs.tag_name }} diff --git a/.github/workflows/release-tag.yaml b/.github/workflows/release-tag.yaml new file mode 100644 index 000000000..29cfa700c --- /dev/null +++ b/.github/workflows/release-tag.yaml @@ -0,0 +1,48 @@ +# Copyright 2021-2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +name: release + +on: + workflow_dispatch: + push: + tags: + - v* + +permissions: + contents: write + packages: write + +jobs: + release-tag: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.5.0 + with: + enable-cache: true + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Release + run: devbox run -- make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish Helm chart + uses: stefanprodan/helm-gh-pages@v1.7.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + app_version: ${{ github.ref_name }} + chart_version: ${{ github.ref_name }} + target_dir: repo diff --git a/.go-tools b/.go-tools index f11d5ac2d..01cbd2fdf 100644 --- a/.go-tools +++ b/.go-tools @@ -1,6 +1,2 @@ github.com/oligot/go-mod-upgrade@v0.9.1 -github.com/segmentio/golines@v0.11.0 -gotest.tools/gotestsum@v1.10.0 sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20230611165747-7edfc04cacbd -github.com/google/go-containerregistry/cmd/crane@v0.15.2 -github.com/drone/envsubst/cmd/envsubst@v1.0.3 diff --git a/.golangci.yml b/.golangci.yml index 3f07f1c37..433ec262f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,4 @@ -# Copyright 2023 D2iQ, Inc. All rights reserved. +# Copyright 2021-2023 D2iQ, Inc. All rights reserved. # SPDX-License-Identifier: Apache-2.0 linters: @@ -38,11 +38,11 @@ linters: linters-settings: depguard: - list-type: blacklist - packages: - - k8s.io/kubernetes - packages-with-error-messages: - k8s.io/kubernetes: "do not use k8s.io/kubernetes directly" + rules: + main: + deny: + - pkg: k8s.io/kubernetes + desc: "do not use k8s.io/kubernetes directly" errcheck: exclude-functions: - encoding/json.Marshal @@ -53,6 +53,7 @@ linters-settings: sections: - Standard - Default + - Prefix(github.com/d2iq-labs) - Prefix(github.com/d2iq-labs/capi-runtime-extensions) gocritic: enabled-tags: @@ -62,7 +63,6 @@ linters-settings: - performance - style gofumpt: - lang-version: "1.17" extra-rules: true lll: line-length: 120 diff --git a/.goreleaser.yml b/.goreleaser.yml index 037190767..20d46eb3f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -50,7 +50,7 @@ archives: dockers: - image_templates: # Specify the image tag including `-amd64` suffix if the build is not a snapshot build or is not being built on - # arm64 machine. This allows for using the snapshot image build without the archtecture specific suffix + # arm64 machine. This allows for using the snapshot image build without the architecture specific suffix # consistently on local machines, i.e. can always use `ghcr.io/d2iq-labs/capi-runtime-extensions:v` on the machine the snapshot # is built on. # @@ -69,7 +69,7 @@ dockers: - "--label=org.opencontainers.image.source={{.GitURL}}" - image_templates: # Specify the image tag including `-amd64v8` suffix if the build is not a snapshot build or is not being built on - # arm64 machine. This allows for using the snapshot image build without the archtecture specific suffix + # arm64 machine. This allows for using the snapshot image build without the architecture specific suffix # consistently on local machines, i.e. can always use `ghcr.io/d2iq-labs/capi-runtime-extensions:v` on the machine the snapshot # is built on. # diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0ba1eb54e..e360b718c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,11 +41,21 @@ repos: stages: [commit] - id: end-of-file-fixer stages: [commit] +- repo: https://github.com/rhysd/actionlint + rev: v1.6.25 + hooks: + - id: actionlint-system + stages: [commit] +- repo: https://github.com/hadolint/hadolint + rev: v2.12.0 + hooks: + - id: hadolint - repo: https://github.com/jorisroovers/gitlint rev: v0.19.1 hooks: - id: gitlint - stages: [commit-msg] + - id: gitlint-ci + args: ["--commits", "origin/main..HEAD"] - repo: https://github.com/jumanjihouse/pre-commit-hooks rev: 3.0.0 hooks: diff --git a/Dockerfile b/Dockerfile index 147f070cd..11c4758a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,12 @@ # Copyright 2023 D2iQ, Inc. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +# hadolint ignore=DL3029 FROM --platform=linux/amd64 gcr.io/distroless/static@sha256:1b4dbd7d38a0fd4bbaf5216a21a615d07b56747a96d3c650689cbb7fdc412b49 as linux-amd64 +# hadolint ignore=DL3029 FROM --platform=linux/arm64 gcr.io/distroless/static@sha256:05810557ec4b4bf01f4df548c06cc915bb29d81cb339495fe1ad2e668434bf8e as linux-arm64 +# hadolint ignore=DL3006,DL3029 FROM --platform=linux/${TARGETARCH} linux-${TARGETARCH} COPY capi-runtime-extensions /usr/local/bin/capi-runtime-extensions diff --git a/Makefile b/Makefile index 178c2fddd..6fa8be54b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ REPO_ROOT := $(CURDIR) -# Versions for tools that are not managed by asdf. -ENVTEST_VERSION=1.25.x +# Versions for tools that are not managed by devbox. +ENVTEST_VERSION=1.27.x include make/all.mk diff --git a/devbox.json b/devbox.json new file mode 100644 index 000000000..9b3b9cc1e --- /dev/null +++ b/devbox.json @@ -0,0 +1,41 @@ +{ + "packages": [ + "clusterctl@latest", + "fluxcd@latest", + "ginkgo@latest", + "github-cli@latest", + "gojq@latest", + "go@latest", + "golangci-lint@latest", + "goreleaser@latest", + "kubernetes-helm@latest", + "helm-docs@latest", + "kind@latest", + "kubebuilder@latest", + "kubectl@latest", + "kustomize@latest", + "pre-commit@latest", + "shfmt@latest", + "upx@latest", + "yamllint@latest", + "chart-testing@latest", + "google-cloud-sdk@latest", + "crane@latest", + "gotestsum@latest", + "golines@latest", + "envsubst@latest", + "kubernetes-controller-tools@latest", + "actionlint@latest", + "hadolint@latest" + ], + "shell": { + "init_hook": [ + "echo 'Welcome to devbox!' > /dev/null" + ], + "scripts": { + "test": [ + "echo \"Error: no test specified\" && exit 1" + ] + } + } +} diff --git a/devbox.lock b/devbox.lock new file mode 100644 index 000000000..e764f137e --- /dev/null +++ b/devbox.lock @@ -0,0 +1,167 @@ +{ + "lockfile_version": "1", + "packages": { + "actionlint@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#actionlint", + "source": "devbox-search", + "version": "1.6.25" + }, + "chart-testing@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#chart-testing", + "source": "devbox-search", + "version": "3.9.0" + }, + "clusterctl@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#clusterctl", + "source": "devbox-search", + "version": "1.4.4" + }, + "crane@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#crane", + "source": "devbox-search", + "version": "0.15.2" + }, + "envsubst@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#envsubst", + "source": "devbox-search", + "version": "1.4.2" + }, + "fluxcd@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#fluxcd", + "source": "devbox-search", + "version": "2.0.1" + }, + "ginkgo@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#ginkgo", + "source": "devbox-search", + "version": "2.11.0" + }, + "github-cli@latest": { + "last_modified": "2023-05-14T19:13:12Z", + "resolved": "github:NixOS/nixpkgs/3007746b3f5bfcb49e102b517bca891822a41b31#github-cli", + "source": "devbox-search", + "version": "2.29.0" + }, + "go@latest": { + "last_modified": "2023-07-30T12:29:02Z", + "resolved": "github:NixOS/nixpkgs/3acb5c4264c490e7714d503c7166a3fde0c51324#go", + "source": "devbox-search", + "version": "1.20.6" + }, + "gojq@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#gojq", + "source": "devbox-search", + "version": "0.12.13" + }, + "golangci-lint@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#golangci-lint", + "source": "devbox-search", + "version": "1.53.3" + }, + "golines@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#golines", + "source": "devbox-search", + "version": "0.11.0" + }, + "google-cloud-sdk@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#google-cloud-sdk", + "source": "devbox-search", + "version": "433.0.1" + }, + "goreleaser@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#goreleaser", + "source": "devbox-search", + "version": "1.19.2" + }, + "gotestsum@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#gotestsum", + "source": "devbox-search", + "version": "1.10.1" + }, + "hadolint@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#hadolint", + "source": "devbox-search", + "version": "2.12.0" + }, + "helm-docs@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#helm-docs", + "source": "devbox-search", + "version": "1.11.0" + }, + "kind@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#kind", + "source": "devbox-search", + "version": "0.20.0" + }, + "kubebuilder@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#kubebuilder", + "source": "devbox-search", + "version": "3.11.1" + }, + "kubectl@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#kubectl", + "source": "devbox-search", + "version": "1.27.3" + }, + "kubernetes-controller-tools@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#kubernetes-controller-tools", + "source": "devbox-search", + "version": "0.12.1" + }, + "kubernetes-helm@latest": { + "last_modified": "2023-07-23T03:35:12Z", + "resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#kubernetes-helm", + "source": "devbox-search", + "version": "3.12.2" + }, + "kustomize@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#kustomize", + "source": "devbox-search", + "version": "5.1.0" + }, + "pre-commit@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#pre-commit", + "source": "devbox-search", + "version": "3.3.3" + }, + "shfmt@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#shfmt", + "source": "devbox-search", + "version": "3.7.0" + }, + "upx@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#upx", + "source": "devbox-search", + "version": "4.0.2" + }, + "yamllint@latest": { + "last_modified": "2023-06-30T04:44:22Z", + "resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#yamllint", + "source": "devbox-search", + "version": "1.32.0" + } + } +} diff --git a/make/addons.mk b/make/addons.mk index 0bc8c31dc..529048156 100644 --- a/make/addons.mk +++ b/make/addons.mk @@ -4,5 +4,5 @@ export CALICO_VERSION := v3.25 .PHONY: update-addon.calico -update-addon.calico: install-tool.gojq install-tool.kubectl ; $(info $(M) updating calico manifests) +update-addon.calico: ; $(info $(M) updating calico manifests) ./hack/addons/update-calico-manifests.sh diff --git a/make/clusterctl.mk b/make/clusterctl.mk index 8564030c3..c522cffd8 100644 --- a/make/clusterctl.mk +++ b/make/clusterctl.mk @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 .PHONY: clusterctl.init -clusterctl.init: install-tool.clusterctl +clusterctl.init: env CLUSTER_TOPOLOGY=true \ EXP_RUNTIME_SDK=true \ EXP_CLUSTER_RESOURCE_SET=true \ @@ -12,5 +12,5 @@ clusterctl.init: install-tool.clusterctl --wait-providers .PHONY: clusterctl.delete -clusterctl.delete: install-tool.clusterctl +clusterctl.delete: clusterctl delete --kubeconfig=$(KIND_KUBECONFIG) --all diff --git a/make/dev.mk b/make/dev.mk index 2fed7db13..7d66c8459 100644 --- a/make/dev.mk +++ b/make/dev.mk @@ -5,7 +5,7 @@ ADDONS_PROVIDER := ClusterResourceSet .PHONY: dev.run-on-kind dev.run-on-kind: export KUBECONFIG := $(KIND_KUBECONFIG) -dev.run-on-kind: kind.create flux.install clusterctl.init install-tool.helm install-tool.gojq +dev.run-on-kind: kind.create flux.install clusterctl.init ifndef SKIP_BUILD $(MAKE) release-snapshot endif diff --git a/make/docker.mk b/make/docker.mk index bf36d652b..d1be90e38 100644 --- a/make/docker.mk +++ b/make/docker.mk @@ -10,7 +10,7 @@ endif endif .PHONY: update-distroless-base-image -update-distroless-base-image: install-tool.gcloud install-tool.gojq install-tool.go.crane; $(info $(M) updating distroless base image) +update-distroless-base-image: ; $(info $(M) updating distroless base image) LATEST_DISTROLESS_NONROOT_DIGEST="$$(gcloud container images list-tags gcr.io/distroless/static --format=json | gojq -r '.[] | select(.tags | index("nonroot")) | .digest')"; \ DISTROLESS_AMD64_DIGEST="$$(crane manifest gcr.io/distroless/static@$${LATEST_DISTROLESS_NONROOT_DIGEST} | gojq -r '.manifests[] | select(.platform.os == "linux" and .platform.architecture == "amd64").digest')"; \ DISTROLESS_ARM64_DIGEST="$$(crane manifest gcr.io/distroless/static@$${LATEST_DISTROLESS_NONROOT_DIGEST} | gojq -r '.manifests[] | select(.platform.os == "linux" and .platform.architecture == "arm64").digest')"; \ diff --git a/make/flux.mk b/make/flux.mk index 125fa1d80..188febe13 100644 --- a/make/flux.mk +++ b/make/flux.mk @@ -2,5 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 .PHONY: flux.install -flux.install: install-tool.flux2 +flux.install: flux install --components=source-controller,helm-controller diff --git a/make/go.mk b/make/go.mk index be5041332..539477ab9 100644 --- a/make/go.mk +++ b/make/go.mk @@ -46,7 +46,7 @@ endif .PHONY: test.% test.%: ## Runs go tests for a specific module -test.%: install-tool.go.gotestsum install-tool.go.setup-envtest ; $(info $(M) running tests$(if $(GOTEST_RUN), matching "$(GOTEST_RUN)") for $* module) +test.%: install-tool.go.setup-envtest ; $(info $(M) running tests$(if $(GOTEST_RUN), matching "$(GOTEST_RUN)") for $* module) $(if $(filter-out root,$*),cd $* && )$(call go_test) .PHONY: integration-test @@ -79,7 +79,7 @@ E2E_FLAKE_ATTEMPTS ?= 1 .PHONY: e2e-test e2e-test: ## Runs e2e tests ifneq ($(wildcard test/e2e/*),) -e2e-test: install-tool.golang install-tool.ginkgo install-tool.gojq +e2e-test: $(info $(M) running e2e tests$(if $(E2E_LABEL), labelled "$(E2E_LABEL)")$(if $(E2E_FOCUS), matching "$(E2E_FOCUS)")) ifneq ($(SKIP_BUILD),true) $(MAKE) GORELEASER_FLAGS=$$'--config=<(env GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) gojq --yaml-input --yaml-output \'del(.builds[0].goarch) | del(.builds[0].goos) | .builds[0].targets|=(["linux_amd64","linux_arm64",env.GOOS+"_"+env.GOARCH] | unique | map(. | sub("_amd64";"_amd64_v1")))\' .goreleaser.yml) --clean --skip-validate --skip-publish' release @@ -125,10 +125,11 @@ endif .PHONY: lint.% lint.%: ## Runs golangci-lint for a specific module -lint.%: install-tool.golangci-lint install-tool.go.golines; $(info $(M) linting $* module) - $(if $(filter-out root,$*),cd $* && )golines -w . - $(if $(filter-out root,$*),cd $* && )golangci-lint run --fix --config=$(GOLANGCI_CONFIG_FILE) +lint.%: ; $(info $(M) linting $* module) $(if $(filter-out root,$*),cd $* && )go fix ./... + $(if $(filter-out root,$*),cd $* && )golines -w $$(go list ./... | sed "s|^$$(go list -m)|.|") + $(if $(filter-out root,$*),cd $* && )golangci-lint run --fix --config=$(GOLANGCI_CONFIG_FILE) + $(if $(filter-out root,$*),cd $* && )golines -w $$(go list ./... | sed "s|^$$(go list -m)|.|") .PHONY: mod-tidy mod-tidy: ## Run go mod tidy for all modules @@ -141,7 +142,7 @@ endif .PHONY: mod-tidy.% mod-tidy.%: ## Runs go mod tidy for a specific module -mod-tidy.%: install-tool.golang; $(info $(M) running go mod tidy for $* module) +mod-tidy.%: ; $(info $(M) running go mod tidy for $* module) $(if $(filter-out root,$*),cd $* && )go mod tidy -v -compat=1.17 $(if $(filter-out root,$*),cd $* && )go mod verify @@ -156,12 +157,12 @@ endif .PHONY: go-clean.% go-clean.%: ## Cleans go build, test and modules caches for a specific module -go-clean.%: install-tool.golang; $(info $(M) running go clean for $* module) +go-clean.%: ; $(info $(M) running go clean for $* module) $(if $(filter-out root,$*),cd $* && )go clean -r -i -cache -testcache -modcache .PHONY: go-generate go-generate: ## Runs go generate -go-generate: install-tool.golang install-tool.kube-controller-tools ; $(info $(M) running go generate) +go-generate: ; $(info $(M) running go generate) go generate -x ./... controller-gen rbac:roleName=capi-runtime-extensions-manager-role crd webhook paths="./..." \ output:crd:artifacts:config=charts/capi-runtime-extensions/crds \ diff --git a/make/goreleaser.mk b/make/goreleaser.mk index 00182b104..592821fec 100644 --- a/make/goreleaser.mk +++ b/make/goreleaser.mk @@ -10,7 +10,7 @@ endif .PHONY: build-snapshot build-snapshot: ## Builds a snapshot with goreleaser -build-snapshot: dockerauth install-tool.goreleaser install-tool.golang go-generate ; $(info $(M) building snapshot $*) +build-snapshot: dockerauth go-generate ; $(info $(M) building snapshot $*) goreleaser --debug=$(GORELEASER_DEBUG) \ build \ --snapshot \ @@ -21,7 +21,7 @@ build-snapshot: dockerauth install-tool.goreleaser install-tool.golang go-genera .PHONY: release release: ## Builds a release with goreleaser -release: dockerauth install-tool.goreleaser install-tool.golang go-generate ; $(info $(M) building release $*) +release: dockerauth go-generate ; $(info $(M) building release $*) goreleaser --debug=$(GORELEASER_DEBUG) \ release \ --clean \ @@ -31,7 +31,7 @@ release: dockerauth install-tool.goreleaser install-tool.golang go-generate ; $( .PHONY: release-snapshot release-snapshot: ## Builds a snapshot release with goreleaser -release-snapshot: dockerauth install-tool.goreleaser install-tool.golang go-generate ; $(info $(M) building snapshot release $*) +release-snapshot: dockerauth go-generate ; $(info $(M) building snapshot release $*) goreleaser --debug=$(GORELEASER_DEBUG) \ release \ --snapshot \ diff --git a/make/helm.mk b/make/helm.mk index f8e8d5ec4..f7590c475 100644 --- a/make/helm.mk +++ b/make/helm.mk @@ -3,11 +3,11 @@ .PHONY: lint-chart lint-chart: ## Lints helm chart -lint-chart: install-tool.helm-ct install-tool.yamllint +lint-chart: ct lint --config charts/ct-config.yaml .PHONY: lint-and-install-chart lint-and-install-chart: ## Lints and installs helm chart -lint-and-install-chart: install-tool.helm-ct install-tool.yamllint +lint-and-install-chart: ct lint-and-install --config charts/ct-config.yaml ct lint-and-install --config charts/ct-config.yaml --upgrade diff --git a/make/kind.mk b/make/kind.mk index b519f0a23..8522fb96e 100644 --- a/make/kind.mk +++ b/make/kind.mk @@ -24,7 +24,7 @@ kind.recreate: kind.delete kind.create .PHONY: kind.create kind.create: ## Creates new KinD cluster -kind.create: install-tool.kubectl install-tool.kind install-tool.go.envsubst ; $(info $(M) creating kind cluster - $(KIND_CLUSTER_NAME)) +kind.create: ; $(info $(M) creating kind cluster - $(KIND_CLUSTER_NAME)) (kind get clusters | grep -Eq '^$(KIND_CLUSTER_NAME)$$' && echo '$(KIND_CLUSTER_NAME) already exists') || \ env KUBECONFIG=$(KIND_KUBECONFIG) $(REPO_ROOT)/hack/kind/create-cluster.sh \ --cluster-name $(KIND_CLUSTER_NAME) \ @@ -34,7 +34,7 @@ kind.create: install-tool.kubectl install-tool.kind install-tool.go.envsubst ; $ .PHONY: kind.delete kind.delete: ## Deletes KinD cluster -kind.delete: install-tool.kind ; $(info $(M) deleting kind cluster - $(KIND_CLUSTER_NAME)) +kind.delete: ; $(info $(M) deleting kind cluster - $(KIND_CLUSTER_NAME)) (kind get clusters | grep -Eq '^$(KIND_CLUSTER_NAME)$$' && kind delete cluster --name $(KIND_CLUSTER_NAME)) || \ echo '$(KIND_CLUSTER_NAME) does not exist' rm -rf $(KIND_DIR)/$(KIND_CLUSTER_NAME) diff --git a/make/pre-commit.mk b/make/pre-commit.mk index 65df34376..410a3b42d 100644 --- a/make/pre-commit.mk +++ b/make/pre-commit.mk @@ -9,8 +9,10 @@ endif .PHONY: pre-commit pre-commit: ## Runs pre-commit on all files -pre-commit: install-tool.pre-commit; $(info $(M) running pre-commit) +pre-commit: ; $(info $(M) running pre-commit) ifeq ($(wildcard $(PRE_COMMIT_CONFIG_FILE)),) $(error Cannot find pre-commit config file $(PRE_COMMIT_CONFIG_FILE). Specify the config file via PRE_COMMIT_CONFIG_FILE variable) endif env SKIP=$(SKIP) pre-commit run -a --show-diff-on-failure --config $(PRE_COMMIT_CONFIG_FILE) + git fetch origin main + pre-commit run --hook-stage manual gitlint-ci diff --git a/make/tools.mk b/make/tools.mk index 5d81feb54..4e80a9ee7 100644 --- a/make/tools.mk +++ b/make/tools.mk @@ -18,67 +18,26 @@ endef .PHONY: install-tool.go.%: ## Installs go tools -install-tool.go.%: install-tool.golang; $(info $(M) installing go tool $*) +install-tool.go.%: ; $(info $(M) installing go tool $*) $(call install_go_tool,$*) endif -ifndef SKIP_ASDF_CHECK -ifeq ($(shell command -v asdf),) - $(error "This repo requires asdf - see https://asdf-vm.com/guide/getting-started.html for instructions to install") -endif -endif - -define install_tool - $(if $(1), \ - (asdf plugin list 2>/dev/null | grep -E '^$(1)$$' &>/dev/null) || asdf plugin add $(1), \ - grep -Eo '^[^#]\S+' $(REPO_ROOT)/.tool-versions | \ - xargs -I{} bash -ec '(asdf plugin list 2>/dev/null | grep -E "^{}$$" &>/dev/null) || \ - asdf plugin add {}' \ - ) - asdf install $1 -endef - .PHONY: install-tools install-tools: ## Install all tools install-tools: ; $(info $(M) installing all tools) - $(call install_tool,) ifneq ($(wildcard $(GO_TOOLS_FILE)),) cat $(GO_TOOLS_FILE) | xargs -L1 go install -v endif -.PHONY: install-tool.% -install-tool.%: ## Install specific tool -install-tool.%: ; $(info $(M) installing $*) - $(call install_tool,$*) - .PHONY: upgrade-tools -# ASDF plugins use different env vars for GitHub authentication when querying releases. Try to -# handle this nicely by specifying some of the known env vars to prevent rate limiting. -ifdef GITHUB_USER_TOKEN -upgrade-tools: export GITHUB_API_TOKEN=$(GITHUB_USER_TOKEN) -else -ifdef GITHUB_TOKEN -upgrade-tools: export GITHUB_API_TOKEN=$(GITHUB_TOKEN) -endif -endif -upgrade-tools: export OAUTH_TOKEN=$(GITHUB_API_TOKEN) upgrade-tools: ## Upgrades all tools to latest available versions -upgrade-tools: upgrade-go-tools; $(info $(M) upgrading all tools to latest available versions) - grep -Eo '^[^#]\S+' $(REPO_ROOT)/.tool-versions | \ - xargs -I{} bash -ec '(asdf plugin list 2>/dev/null | grep -E "^{}$$" &>/dev/null) || \ - asdf plugin add {}' - grep -v '# FREEZE' $(REPO_ROOT)/.tool-versions | \ - grep -Eo '^[^#]\S+' | \ - xargs -I{} bash -ec '\ - export VERSION="$$( \ - asdf list all {} | \ - grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | \ - tail -1 \ - )" && asdf install {} $${VERSION} && asdf local {} $${VERSION}' +upgrade-tools:; $(info $(M) upgrading all tools to latest available versions) + devbox update + $(MAKE) upgrade-go-tools .PHONY: upgrade-go-tools upgrade-go-tools: ## Upgrades all go tools to latest available versions -upgrade-go-tools: install-tool.golang; $(info $(M) upgrading all go tools to latest available versions) +upgrade-go-tools: ; $(info $(M) upgrading all go tools to latest available versions) grep -v '# FREEZE' .go-tools | \ grep -Eo '^[^#][^@]+' | \ xargs -I {} bash -ec ' \ diff --git a/make/upx.mk b/make/upx.mk index d4f31167b..fd1ce08bd 100644 --- a/make/upx.mk +++ b/make/upx.mk @@ -12,7 +12,6 @@ upx: ; $(info $(M) skipping packing $(UPX_REAL_TARGET) - $(GOOS)/$(GOARCH) is no else ifeq ($(GOOS)/$(GOARCH),darwin/arm64) upx: ; $(info $(M) skipping packing $(UPX_REAL_TARGET) - $(GOOS)/$(GOARCH) has a bug in packing - https://github.com/upx/upx/issues/628 - should be fixed in 4.0.2) else -upx: install-tool.upx upx: ## Pack executable using upx upx: ; $(info $(M) packing $(UPX_REAL_TARGET)) (upx -l $(UPX_REAL_TARGET) &>/dev/null && echo $(UPX_REAL_TARGET) is already packed) || upx -9 --lzma $(UPX_REAL_TARGET)