github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/Makefile (about) 1 # SPDX-License-Identifier: Apache-2.0 2 # SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 # Provide a default value for the operating system architecture used in tests, e.g. " APPLIANCE_MODE=true|false make test-e2e ARCH=arm64" 5 ARCH ?= amd64 6 KEY ?= "" 7 ###################################################################################### 8 9 # Figure out which Jackal binary we should use based on the operating system we are on 10 JACKAL_BIN := ./build/jackal 11 BUILD_CLI_FOR_SYSTEM := build-cli-linux-amd 12 ifeq ($(OS),Windows_NT) 13 JACKAL_BIN := $(addsuffix .exe,$(JACKAL_BIN)) 14 BUILD_CLI_FOR_SYSTEM := build-cli-windows-amd 15 else 16 UNAME_S := $(shell uname -s) 17 UNAME_P := $(shell uname -p) 18 ifneq ($(UNAME_S),Linux) 19 ifeq ($(UNAME_S),Darwin) 20 JACKAL_BIN := $(addsuffix -mac,$(JACKAL_BIN)) 21 endif 22 ifeq ($(UNAME_P),i386) 23 JACKAL_BIN := $(addsuffix -intel,$(JACKAL_BIN)) 24 BUILD_CLI_FOR_SYSTEM = build-cli-mac-intel 25 endif 26 ifeq ($(UNAME_P),arm) 27 JACKAL_BIN := $(addsuffix -apple,$(JACKAL_BIN)) 28 BUILD_CLI_FOR_SYSTEM = build-cli-mac-apple 29 endif 30 endif 31 endif 32 33 CLI_VERSION ?= $(if $(shell git describe --tags),$(shell git describe --tags),"UnknownVersion") 34 BUILD_ARGS := -s -w -X github.com/Racer159/jackal/src/config.CLIVersion=$(CLI_VERSION) 35 K8S_MODULES_VER=$(subst ., ,$(subst v,,$(shell go list -f '{{.Version}}' -m k8s.io/client-go))) 36 K8S_MODULES_MAJOR_VER=$(shell echo $$(($(firstword $(K8S_MODULES_VER)) + 1))) 37 K8S_MODULES_MINOR_VER=$(word 2,$(K8S_MODULES_VER)) 38 K8S_MODULES_PATCH_VER=$(word 3,$(K8S_MODULES_VER)) 39 K9S_VERSION=$(shell go list -f '{{.Version}}' -m github.com/derailed/k9s) 40 CRANE_VERSION=$(shell go list -f '{{.Version}}' -m github.com/google/go-containerregistry) 41 SYFT_VERSION=$(shell go list -f '{{.Version}}' -m github.com/anchore/syft) 42 ARCHIVER_VERSION=$(shell go list -f '{{.Version}}' -m github.com/mholt/archiver/v3) 43 HELM_VERSION=$(shell go list -f '{{.Version}}' -m helm.sh/helm/v3) 44 45 BUILD_ARGS += -X helm.sh/helm/v3/pkg/lint/rules.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER) 46 BUILD_ARGS += -X helm.sh/helm/v3/pkg/lint/rules.k8sVersionMinor=$(K8S_MODULES_MINOR_VER) 47 BUILD_ARGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMajor=$(K8S_MODULES_MAJOR_VER) 48 BUILD_ARGS += -X helm.sh/helm/v3/pkg/chartutil.k8sVersionMinor=$(K8S_MODULES_MINOR_VER) 49 BUILD_ARGS += -X k8s.io/component-base/version.gitVersion=v$(K8S_MODULES_MAJOR_VER).$(K8S_MODULES_MINOR_VER).$(K8S_MODULES_PATCH_VER) 50 BUILD_ARGS += -X github.com/derailed/k9s/cmd.version=$(K9S_VERSION) 51 BUILD_ARGS += -X github.com/google/go-containerregistry/cmd/crane/cmd.Version=$(CRANE_VERSION) 52 BUILD_ARGS += -X github.com/Racer159/jackal/src/cmd/tools.syftVersion=$(SYFT_VERSION) 53 BUILD_ARGS += -X github.com/Racer159/jackal/src/cmd/tools.archiverVersion=$(ARCHIVER_VERSION) 54 BUILD_ARGS += -X github.com/Racer159/jackal/src/cmd/tools.helmVersion=$(HELM_VERSION) 55 56 GIT_SHA := $(if $(shell git rev-parse HEAD),$(shell git rev-parse HEAD),"") 57 BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ') 58 BUILD_ARGS += -X k8s.io/component-base/version.gitCommit=$(GIT_SHA) 59 BUILD_ARGS += -X k8s.io/component-base/version.buildDate=$(BUILD_DATE) 60 61 .DEFAULT_GOAL := build 62 63 .PHONY: help 64 help: ## Display this help information 65 @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ 66 | sort | awk 'BEGIN {FS = ":.*?## "}; \ 67 {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 68 69 clean: ## Clean the build directory 70 rm -rf build 71 72 destroy: ## Run `jackal destroy` on the current cluster 73 $(JACKAL_BIN) destroy --confirm --remove-components 74 rm -fr build 75 76 delete-packages: ## Delete all Jackal package tarballs in the project recursively 77 find . -type f -name 'jackal-package-*' -delete 78 79 # Note: the path to the main.go file is not used due to https://github.com/golang/go/issues/51831#issuecomment-1074188363 80 .PHONY: build 81 build: ## Build the Jackal CLI for the machines OS and architecture 82 $(MAKE) $(BUILD_CLI_FOR_SYSTEM) 83 84 build-cli-linux-amd: ## Build the Jackal CLI for Linux on AMD64 85 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(BUILD_ARGS)" -o build/jackal . 86 87 build-cli-linux-arm: ## Build the Jackal CLI for Linux on ARM 88 CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(BUILD_ARGS)" -o build/jackal-arm . 89 90 build-cli-mac-intel: ## Build the Jackal CLI for macOS on AMD64 91 GOOS=darwin GOARCH=amd64 go build -ldflags="$(BUILD_ARGS)" -o build/jackal-mac-intel . 92 93 build-cli-mac-apple: ## Build the Jackal CLI for macOS on ARM 94 GOOS=darwin GOARCH=arm64 go build -ldflags="$(BUILD_ARGS)" -o build/jackal-mac-apple . 95 96 build-cli-windows-amd: ## Build the Jackal CLI for Windows on AMD64 97 GOOS=windows GOARCH=amd64 go build -ldflags="$(BUILD_ARGS)" -o build/jackal.exe . ## Build the Jackal CLI for Windows on AMD64 98 99 build-cli-windows-arm: ## Build the Jackal CLI for Windows on ARM 100 GOOS=windows GOARCH=arm64 go build -ldflags="$(BUILD_ARGS)" -o build/jackal-arm.exe . ## Build the Jackal CLI for Windows on ARM 101 102 build-cli-linux: build-cli-linux-amd build-cli-linux-arm ## Build the Jackal CLI for Linux on AMD64 and ARM 103 104 build-cli: build-cli-linux-amd build-cli-linux-arm build-cli-mac-intel build-cli-mac-apple build-cli-windows-amd build-cli-windows-arm ## Build the CLI 105 106 docs-and-schema: ## Generate the Jackal Documentation and Schema 107 hack/gen-cli-docs.sh 108 JACKAL_CONFIG=hack/empty-config.toml hack/create-jackal-schema.sh 109 110 lint-packages-and-examples: build ## Recursively lint all jackal.yaml files in the repo except for those dedicated to tests 111 hack/lint_all_jackal_packages.sh $(JACKAL_BIN) 112 113 # INTERNAL: a shim used to build the agent image only if needed on Windows using the `test` command 114 init-package-local-agent: 115 @test "$(AGENT_IMAGE_TAG)" != "local" || $(MAKE) build-local-agent-image 116 117 build-local-agent-image: ## Build the Jackal agent image to be used in a locally built init package 118 @ if [ "$(ARCH)" = "amd64" ] && [ ! -s ./build/jackal ]; then $(MAKE) build-cli-linux-amd; fi 119 @ if [ "$(ARCH)" = "amd64" ]; then cp build/jackal build/jackal-linux-amd64; fi 120 @ if [ "$(ARCH)" = "arm64" ] && [ ! -s ./build/jackal-arm ]; then $(MAKE) build-cli-linux-arm; fi 121 @ if [ "$(ARCH)" = "arm64" ]; then cp build/jackal-arm build/jackal-linux-arm64; fi 122 docker buildx build --load --platform linux/$(ARCH) --tag ghcr.io/Racer159/jackal/agent:local . 123 @ if [ "$(ARCH)" = "amd64" ]; then rm build/jackal-linux-amd64; fi 124 @ if [ "$(ARCH)" = "arm64" ]; then rm build/jackal-linux-arm64; fi 125 126 init-package: ## Create the jackal init package (must `brew install coreutils` on macOS and have `docker` first) 127 @test -s $(JACKAL_BIN) || $(MAKE) build-cli 128 $(JACKAL_BIN) package create -o build -a $(ARCH) --confirm . 129 130 # INTERNAL: used to build a release version of the init package with a specific agent image 131 release-init-package: 132 $(JACKAL_BIN) package create -o build -a $(ARCH) --set AGENT_IMAGE_TAG=$(AGENT_IMAGE_TAG) --confirm . 133 134 # INTERNAL: used to build an iron bank version of the init package with an ib version of the registry image 135 ib-init-package: 136 @test -s $(JACKAL_BIN) || $(MAKE) build-cli 137 $(JACKAL_BIN) package create -o build -a $(ARCH) --confirm . \ 138 --set REGISTRY_IMAGE_DOMAIN="registry1.dso.mil/" \ 139 --set REGISTRY_IMAGE="ironbank/opensource/docker/registry-v2" \ 140 --set REGISTRY_IMAGE_TAG="2.8.3" 141 142 # INTERNAL: used to publish the init package 143 publish-init-package: 144 $(JACKAL_BIN) package publish build/jackal-init-$(ARCH)-$(CLI_VERSION).tar.zst oci://$(REPOSITORY_URL) 145 $(JACKAL_BIN) package publish . oci://$(REPOSITORY_URL) 146 147 build-examples: ## Build all of the example packages 148 @test -s $(JACKAL_BIN) || $(MAKE) build-cli 149 150 @test -s ./build/jackal-package-dos-games-$(ARCH)-1.0.0.tar.zst || $(JACKAL_BIN) package create examples/dos-games -o build -a $(ARCH) --confirm 151 152 @test -s ./build/jackal-package-manifests-$(ARCH)-0.0.1.tar.zst || $(JACKAL_BIN) package create examples/manifests -o build -a $(ARCH) --confirm 153 154 @test -s ./build/jackal-package-component-actions-$(ARCH).tar.zst || $(JACKAL_BIN) package create examples/component-actions -o build -a $(ARCH) --confirm 155 156 @test -s ./build/jackal-package-component-choice-$(ARCH).tar.zst || $(JACKAL_BIN) package create examples/component-choice -o build -a $(ARCH) --confirm 157 158 @test -s ./build/jackal-package-variables-$(ARCH).tar.zst || $(JACKAL_BIN) package create examples/variables --set NGINX_VERSION=1.23.3 -o build -a $(ARCH) --confirm 159 160 @test -s ./build/jackal-package-kiwix-$(ARCH)-3.5.0.tar || $(JACKAL_BIN) package create examples/kiwix -o build -a $(ARCH) --confirm 161 162 @test -s ./build/jackal-package-git-data-$(ARCH)-0.0.1.tar.zst || $(JACKAL_BIN) package create examples/git-data -o build -a $(ARCH) --confirm 163 164 @test -s ./build/jackal-package-helm-charts-$(ARCH)-0.0.1.tar.zst || $(JACKAL_BIN) package create examples/helm-charts -o build -a $(ARCH) --confirm 165 166 @test -s ./build/jackal-package-podinfo-flux-$(ARCH).tar.zst || $(JACKAL_BIN) package create examples/podinfo-flux -o build -a $(ARCH) --confirm 167 168 @test -s ./build/jackal-package-argocd-$(ARCH).tar.zst || $(JACKAL_BIN) package create examples/argocd -o build -a $(ARCH) --confirm 169 170 @test -s ./build/jackal-package-yolo-$(ARCH).tar.zst || $(JACKAL_BIN) package create examples/yolo -o build -a $(ARCH) --confirm 171 172 @test -s ./build/jackal-package-component-webhooks-$(ARCH)-0.0.1.tar.zst || $(JACKAL_BIN) package create examples/component-webhooks -o build -a $(ARCH) --confirm 173 174 build-injector-linux: ## Build the Jackal injector for AMD64 and ARM64 175 docker run --rm --user "$(id -u)":"$(id -g)" -v $$PWD/src/injector:/usr/src/jackal-injector -w /usr/src/jackal-injector rust:1.71.0-bookworm make build-injector-linux 176 177 ## NOTE: Requires an existing cluster or the env var APPLIANCE_MODE=true 178 .PHONY: test-e2e 179 test-e2e: test-e2e-without-cluster test-e2e-with-cluster ## Run all of the core Jackal CLI E2E tests (builds any deps that aren't present) 180 181 .PHONY: test-e2e-with-cluster 182 test-e2e-with-cluster: build-examples ## Run all of the core Jackal CLI E2E tests that DO require a cluster (builds any deps that aren't present) 183 @test -s ./build/jackal-init-$(ARCH)-$(CLI_VERSION).tar.zst || $(MAKE) init-package 184 cd src/test/e2e && go test ./main_test.go ./[2-9]*.go -failfast -v -timeout 35m 185 186 .PHONY: test-e2e-without-cluster 187 test-e2e-without-cluster: build-examples ## Run all of the core Jackal CLI E2E tests that DO NOT require a cluster (builds any deps that aren't present) 188 @test -s ./build/jackal-init-$(ARCH)-$(CLI_VERSION).tar.zst || $(MAKE) init-package 189 cd src/test/e2e && go test ./main_test.go ./[01]* -failfast -v -timeout 35m 190 191 ## NOTE: Requires an existing cluster 192 .PHONY: test-external 193 test-external: ## Run the Jackal CLI E2E tests for an external registry and cluster 194 @test -s $(JACKAL_BIN) || $(MAKE) build-cli 195 @test -s ./build/jackal-init-$(ARCH)-$(CLI_VERSION).tar.zst || $(MAKE) init-package 196 @test -s ./build/jackal-package-podinfo-flux-$(ARCH).tar.zst || $(JACKAL_BIN) package create examples/podinfo-flux -o build -a $(ARCH) --confirm 197 @test -s ./build/jackal-package-argocd-$(ARCH).tar.zst || $(JACKAL_BIN) package create examples/argocd -o build -a $(ARCH) --confirm 198 cd src/test/external && go test -failfast -v -timeout 30m 199 200 ## NOTE: Requires an existing cluster and 201 .PHONY: test-upgrade 202 test-upgrade: ## Run the Jackal CLI E2E tests for an external registry and cluster 203 @test -s $(JACKAL_BIN) || $(MAKE) build-cli 204 [ -n "$(shell jackal version)" ] || (echo "Jackal must be installed prior to the upgrade test" && exit 1) 205 [ -n "$(shell jackal package list 2>&1 | grep test-upgrade-package)" ] || (echo "Jackal must be initialized and have the 6.3.3 upgrade-test package installed prior to the upgrade test" && exit 1) 206 @test -s "jackal-package-test-upgrade-package-amd64-6.3.4.tar.zst" || jackal package create src/test/upgrade/ --set PODINFO_VERSION=6.3.4 --confirm 207 cd src/test/upgrade && go test -failfast -v -timeout 30m 208 209 .PHONY: test-unit 210 test-unit: ## Run unit tests 211 cd src/pkg && go test ./... -failfast -v -timeout 30m 212 cd src/internal && go test ./... -failfast -v timeout 30m 213 cd src/extensions/bigbang && go test ./. -failfast -v timeout 30m 214 215 # INTERNAL: used to test that a dev has ran `make docs-and-schema` in their PR 216 test-docs-and-schema: 217 $(MAKE) docs-and-schema 218 hack/check-jackal-docs-and-schema.sh 219 220 # INTERNAL: used to test for new CVEs that may have been introduced 221 test-cves: 222 go run main.go tools sbom scan . -o json --exclude './docs-website' --exclude './examples' | grype --fail-on low 223 224 cve-report: ## Create a CVE report for the current project (must `brew install grype` first) 225 @test -d ./build || mkdir ./build 226 go run main.go tools sbom scan . -o json --exclude './docs-website' --exclude './examples' | grype -o template -t hack/.templates/grype.tmpl > build/jackal-known-cves.csv 227 228 lint-go: ## Run revive to lint the go code (must `brew install revive` first) 229 revive -config revive.toml -exclude src/cmd/viper.go -formatter stylish ./src/...