diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bea15ca6..4401b1a3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -285,3 +285,14 @@ jobs: run: nix develop --impure .#ci -c ./deploy/dev/multi-dc/test/multi-dc-raft.sh install env: OPERATOR_VERSION: ${{ needs.artifacts.outputs.container-image-tag }} + + verify: + name: Verify + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + + steps: + - name: Block Merge Commits + uses: Morishiri/block-merge-commits-action@v1.0.1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index 3c1f800e..df7f5b50 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,14 @@ # A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html -export PATH := $(abspath bin/):${PATH} +# Target image name +IMG ?= ghcr.io/bank-vaults/vault-operator:dev -# Project variables -DOCKER_REGISTRY ?= ghcr.io/bank-vaults -DOCKER_IMAGE = ${DOCKER_REGISTRY}/vault-operator:dev - -# Testing variables +# Default test data TEST_K8S_VERSION ?= 1.27.1 TEST_VAULT_VERSION ?= 1.14.1 TEST_BANK_VAULTS_VERSION ?= 1.20.3-softhsm TEST_BANK_VAULTS_IMAGE ?= ghcr.io/bank-vaults/bank-vaults:$(TEST_BANK_VAULTS_VERSION) -TEST_OPERATOR_VERSION ?= $(lastword $(subst :, ,$(DOCKER_IMAGE))) +TEST_OPERATOR_VERSION ?= $(lastword $(subst :, ,$(IMG))) TEST_KIND_CLUSTER ?= vault-operator # Setting SHELL to bash allows bash commands to be executed by recipes. @@ -29,15 +26,10 @@ default: help help: ## Display this help @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) -.PHONY: deps -deps: $(HELM) $(CONTROLLER_GEN) $(KUSTOMIZE) $(KIND) -deps: $(HELM_DOCS) $(ENVTEST) $(GOLANGCI_LINT) $(LICENSEI) $(KURUN) -deps: ## Download and install dependencies - ##@ Checks .PHONY: fmt -fmt: ## Autofix linting issues +fmt: ## Run go fmt against code $(GOLANGCI_LINT) run --fix .PHONY: lint-go @@ -56,19 +48,32 @@ lint-docker: # Run Dockerfile lint check lint-yaml: # Run yaml lint check $(YAMLLINT) $(if ${CI},-f github,) --no-warnings . +.PHONY: lint +lint: lint-go lint-helm lint-docker lint-yaml +lint: ## Run lint checks + +.PHONY: test +test: ## Run tests + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(TEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \ + go test -race -v ./... -coverprofile cover.out + +.PHONY: test-acceptance +test-acceptance: ## Run acceptance tests. If running on a local kind cluster, run "make import-test" before this + VAULT_VERSION=$(TEST_VAULT_VERSION) BANK_VAULTS_VERSION=$(TEST_BANK_VAULTS_VERSION) OPERATOR_VERSION=$(TEST_OPERATOR_VERSION) \ + go test -race -v -timeout 900s -tags kubeall ./test + .PHONY: license-check -license-check: ## Run license checks +license-check: ## Run license check $(LICENSEI) check $(LICENSEI) header -.PHONY: lint -lint: lint-go lint-helm lint-docker lint-yaml -lint: ## Run lint checks +.PHONY: check +check: lint test ## Run lint checks and tests ##@ Development .PHONY: run -run: deploy ## Run operator from your host +run: deploy ## Run manager from your host OPERATOR_NAME=vault-dev BANK_VAULTS_IMAGE=$(TEST_BANK_VAULTS_IMAGE) go run cmd/main.go -verbose .PHONY: up @@ -81,10 +86,10 @@ down: ## Destroy kind development environment .PHONY: import-image import-image: docker-build ## Import manager image to kind image repository - $(KIND) load docker-image ${DOCKER_IMAGE} --name $(TEST_KIND_CLUSTER) + $(KIND) load docker-image ${IMG} --name $(TEST_KIND_CLUSTER) .PHONY: import-test -import-test: import-image ## Import testing images to kind image repository +import-test: import-image ## Import images required for tests to kind image repository docker pull ghcr.io/bank-vaults/bank-vaults:$(TEST_BANK_VAULTS_VERSION) docker pull hashicorp/vault:$(TEST_VAULT_VERSION) @@ -103,13 +108,13 @@ build: ## Build manager binary # More info: https://docs.docker.com/develop/develop-images/build_enhancements/ .PHONY: docker-build docker-build: ## Build docker image - docker build -t ${DOCKER_IMAGE} . + docker build -t ${IMG} . # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple -# architectures. (i.e. make docker-buildx DOCKER_IMAGE=myregistry/mypoperator:0.0.1). To use this option you need to: +# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/ # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/ -# - be able to push the image for your registry (i.e. if you do not inform a valid value via DOCKER_IMAGE=> then the export will fail) +# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=> then the export will fail) # To properly provided solutions that supports more than one platform you should use this option. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx @@ -118,7 +123,7 @@ docker-buildx: ## Build docker image for cross-platform support sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - docker buildx create --name project-v3-builder docker buildx use project-v3-builder - - docker buildx build --push --platform=$(PLATFORMS) --tag ${DOCKER_IMAGE} -f Dockerfile.cross . + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . - docker buildx rm project-v3-builder rm Dockerfile.cross @@ -131,17 +136,6 @@ helm-chart: ## Build helm chart artifacts: docker-build helm-chart artifacts: ## Build docker image and helm chart -##@ Test - -.PHONY: test -test: ## Run tests - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(TEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \ - go test -race -v ./... -coverprofile cover.out - -.PHONY: test-acceptance -test-acceptance: ## Run acceptance tests. If running on a local kind cluster, run "make import-test" before this - VAULT_VERSION=$(TEST_VAULT_VERSION) BANK_VAULTS_VERSION=$(TEST_BANK_VAULTS_VERSION) OPERATOR_VERSION=$(TEST_OPERATOR_VERSION) \ - go test -race -v -timeout 900s -tags kubeall ./test ##@ Autogeneration @@ -182,13 +176,15 @@ uninstall: gen-manifests ## Uninstall CRDs from the K8s cluster. Call with ignor .PHONY: deploy deploy: gen-manifests ## Deploy manager resources to the K8s cluster - cd deploy/manager && $(KUSTOMIZE) edit set image controller=${DOCKER_IMAGE} + cd deploy/manager && $(KUSTOMIZE) edit set image controller=${IMG} $(KUSTOMIZE) build deploy/default | kubectl apply -f - .PHONY: undeploy clean: ## Clean manager resources from the K8s cluster. Call with ignore-not-found=true to ignore resource not found errors during deletion. $(KUSTOMIZE) build deploy/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - +##@ Dependencies + # Dependency tool chain GOLANGCI_VERSION = 1.53.3 LICENSEI_VERSION = 0.8.0 @@ -257,3 +253,8 @@ $(KURUN): $(LOCALBIN) # TODO: add support for hadolint and yamllint dependencies HADOLINT ?= hadolint YAMLLINT ?= yamllint + +.PHONY: deps +deps: $(HELM) $(CONTROLLER_GEN) $(KUSTOMIZE) $(KIND) +deps: $(HELM_DOCS) $(ENVTEST) $(GOLANGCI_LINT) $(LICENSEI) $(KURUN) +deps: ## Download and install dependencies