zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/Makefile (about) 1 export GO111MODULE=on 2 TOP_LEVEL=$(shell git rev-parse --show-toplevel) 3 COMMIT_HASH=$(shell git describe --always --tags --long) 4 RELEASE_TAG=$(shell git describe --tags --abbrev=0) 5 GO_VERSION=$(shell go version | awk '{print $$3}') 6 COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HASH)-dirty,$(COMMIT_HASH)) 7 CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker) 8 TMPDIR := $(shell mktemp -d) 9 TOOLSDIR := $(shell pwd)/hack/tools 10 PATH := bin:$(TOOLSDIR)/bin:$(PATH) 11 STACKER := $(shell which stacker) 12 GOLINTER := $(TOOLSDIR)/bin/golangci-lint 13 GOLINTER_VERSION := v1.54.2 14 NOTATION := $(TOOLSDIR)/bin/notation 15 NOTATION_VERSION := 1.0.0 16 COSIGN := $(TOOLSDIR)/bin/cosign 17 COSIGN_VERSION := 2.2.0 18 HELM := $(TOOLSDIR)/bin/helm 19 ORAS := $(TOOLSDIR)/bin/oras 20 ORAS_VERSION := 1.0.0-rc.1 21 REGCLIENT := $(TOOLSDIR)/bin/regctl 22 REGCLIENT_VERSION := v0.5.7 23 CRICTL := $(TOOLSDIR)/bin/crictl 24 CRICTL_VERSION := v1.26.1 25 ACTION_VALIDATOR := $(TOOLSDIR)/bin/action-validator 26 ACTION_VALIDATOR_VERSION := v0.5.3 27 ZUI_BUILD_PATH := "" 28 ZUI_VERSION := commit-09ab447 29 ZUI_REPO_OWNER := project-zot 30 ZUI_REPO_NAME := zui 31 SWAGGER_VERSION := v1.16.2 32 STACKER := $(TOOLSDIR)/bin/stacker 33 BATS := $(TOOLSDIR)/bin/bats 34 TESTDATA := $(TOP_LEVEL)/test/data 35 OS ?= $(shell go env GOOS) 36 ARCH ?= $(shell go env GOARCH) 37 38 PROTOC := $(TOOLSDIR)/bin/protoc 39 PROTOC_VERSION := 24.4 40 GO_PROTOC_VERSION := 1.31.0 41 HOST_OS := $(shell go env GOOS) 42 HOST_ARCH := $(shell go env GOARCH) 43 ifeq ($(HOST_OS),linux) 44 PROTOC_OS := linux 45 else ifeq ($(HOST_OS),darwin) 46 PROTOC_OS := osx 47 endif 48 ifeq ($(HOST_ARCH),amd64) 49 PROTOC_ARCH := x86_64 50 else ifeq ($(HOST_ARCH),arm64) 51 PROTOC_ARCH := aarch_64 52 endif 53 54 BENCH_OUTPUT ?= stdout 55 ALL_EXTENSIONS = debug,imagetrust,lint,metrics,mgmt,profile,scrub,search,sync,ui,userprefs 56 EXTENSIONS ?= sync,search,scrub,metrics,lint,ui,mgmt,profile,userprefs,imagetrust 57 UI_DEPENDENCIES := search,mgmt,userprefs 58 # freebsd/arm64 not supported for pie builds 59 BUILDMODE_FLAGS := -buildmode=pie 60 ifeq ($(OS),freebsd) 61 ifeq ($(ARCH),arm64) 62 BUILDMODE_FLAGS= 63 endif 64 endif 65 comma:= , 66 space := $(null) # 67 hyphen:= - 68 69 merge-ui-extensions=$(subst $(1),$(2),$(if $(findstring ui,$(3)),$(3)$(1)$(4),$(3))) 70 merged-extensions = $(call merge-ui-extensions,$(comma),$(space),$(EXTENSIONS),$(UI_DEPENDENCIES)) 71 filter-valid = $(foreach ext, $(merged-extensions), $(if $(findstring $(ext),$(ALL_EXTENSIONS)),$(ext),$(error unknown extension: $(ext)))) 72 add-extensions = $(subst $(1),$(2),$(sort $(filter-valid))) 73 BUILD_LABELS = $(call add-extensions,$(space),$(comma)) 74 extended-name = -$(subst $(comma),$(hyphen),$(BUILD_LABELS)) 75 76 BATS_TEST_FILE_PATH ?= replace_me 77 ifeq ($(BATS_VERBOSITY),2) 78 BATS_FLAGS = --trace --verbose-run --show-output-of-passing-tests --print-output-on-failure 79 else ifeq ($(BATS_VERBOSITY),1) 80 BATS_FLAGS = --trace --verbose-run --print-output-on-failure 81 else 82 BATS_FLAGS = --print-output-on-failure 83 endif 84 85 .PHONY: all 86 all: modcheck swaggercheck binary binary-minimal binary-debug cli bench exporter-minimal verify-config check check-gh-actions test covhtml 87 88 .PHONY: modtidy 89 modtidy: 90 go mod tidy 91 92 .PHONY: modcheck 93 modcheck: modtidy 94 $(eval UNCOMMITED_FILES = $(shell git status --porcelain | grep -c 'go.mod\|go.sum')) 95 @if [ $(UNCOMMITED_FILES) != 0 ]; then \ 96 echo "Updated go.mod and/or go.sum have uncommitted changes, commit the changes accordingly ";\ 97 git status;\ 98 exit 1;\ 99 fi 100 101 .PHONY: swaggercheck 102 swaggercheck: swagger 103 $(eval UNCOMMITED_FILES = $(shell git status --porcelain | grep -c swagger)) 104 @if [ $(UNCOMMITED_FILES) != 0 ]; then \ 105 echo "Updated swagger files uncommitted, make sure all swagger files are committed:";\ 106 git status;\ 107 exit 1;\ 108 fi 109 110 .PHONY: build-metadata 111 build-metadata: $(if $(findstring ui,$(BUILD_LABELS)), ui) 112 # do not allow empty $(BUILD_TAGS) (at least add containers_image_openpgp that doesn't affect package import & files listing) 113 $(eval BUILD_TAGS=$(if $(BUILD_LABELS),$(BUILD_LABELS),containers_image_openpgp)) 114 echo "Imports: \n" 115 go list -tags $(BUILD_TAGS) -f '{{ join .Imports "\n" }}' ./... | sort -u 116 echo "\n Files: \n" 117 go list -tags $(BUILD_TAGS) -f '{{ join .GoFiles "\n" }}' ./... | sort -u 118 119 .PHONY: gen-protobuf 120 gen-protobuf: check-not-freebds $(PROTOC) 121 $(PROTOC) --experimental_allow_proto3_optional \ 122 --proto_path=$(TOP_LEVEL)/pkg/meta/proto \ 123 --go_out=$(TOP_LEVEL)/pkg/meta/proto \ 124 --go_opt='Moci/oci.proto=./gen' \ 125 --go_opt='Mmeta/meta.proto=./gen' \ 126 --go_opt='Moci/config.proto=./gen' \ 127 --go_opt='Moci/manifest.proto=./gen' \ 128 --go_opt='Moci/index.proto=./gen' \ 129 --go_opt='Moci/descriptor.proto=./gen' \ 130 --go_opt='Moci/versioned.proto=./gen' \ 131 $(TOP_LEVEL)/pkg/meta/proto/meta/meta.proto 132 $(PROTOC) --experimental_allow_proto3_optional \ 133 --proto_path=$(TOP_LEVEL)/pkg/meta/proto \ 134 --go_out=$(TOP_LEVEL)/pkg/meta/proto \ 135 --go_opt='Moci/versioned.proto=./gen' \ 136 $(TOP_LEVEL)/pkg/meta/proto/oci/versioned.proto 137 $(PROTOC) --experimental_allow_proto3_optional \ 138 --proto_path=$(TOP_LEVEL)/pkg/meta/proto \ 139 --go_out=$(TOP_LEVEL)/pkg/meta/proto \ 140 --go_opt='Moci/descriptor.proto=./gen' \ 141 $(TOP_LEVEL)/pkg/meta/proto/oci/descriptor.proto 142 $(PROTOC) --experimental_allow_proto3_optional \ 143 --proto_path=$(TOP_LEVEL)/pkg/meta/proto \ 144 --go_out=$(TOP_LEVEL)/pkg/meta/proto \ 145 --go_opt='Moci/descriptor.proto=./gen' \ 146 --go_opt='Moci/versioned.proto=./gen' \ 147 --go_opt='Moci/index.proto=./gen' \ 148 $(TOP_LEVEL)/pkg/meta/proto/oci/index.proto 149 $(PROTOC) --experimental_allow_proto3_optional \ 150 --proto_path=$(TOP_LEVEL)/pkg/meta/proto \ 151 --go_out=$(TOP_LEVEL)/pkg/meta/proto \ 152 --go_opt='Moci/oci.proto=./gen' \ 153 --go_opt='Moci/descriptor.proto=./gen' \ 154 --go_opt='Moci/config.proto=./gen' \ 155 $(TOP_LEVEL)/pkg/meta/proto/oci/config.proto 156 $(PROTOC) --experimental_allow_proto3_optional \ 157 --proto_path=$(TOP_LEVEL)/pkg/meta/proto \ 158 --go_out=$(TOP_LEVEL)/pkg/meta/proto \ 159 --go_opt='Moci/versioned.proto=./gen' \ 160 --go_opt='Moci/descriptor.proto=./gen' \ 161 --go_opt='Moci/manifest.proto=./gen' \ 162 $(TOP_LEVEL)/pkg/meta/proto/oci/manifest.proto 163 164 .PHONY: binary-minimal 165 binary-minimal: EXTENSIONS= 166 binary-minimal: modcheck build-metadata 167 env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH)-minimal $(BUILDMODE_FLAGS) -tags containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.dev/zot/pkg/api/config.ReleaseTag=${RELEASE_TAG} -X zotregistry.dev/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.dev/zot/pkg/api/config.BinaryType=minimal -X zotregistry.dev/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zot 168 169 .PHONY: binary 170 binary: $(if $(findstring ui,$(BUILD_LABELS)), ui) 171 binary: modcheck build-metadata 172 env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH) $(BUILDMODE_FLAGS) -tags $(BUILD_LABELS),containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.dev/zot/pkg/api/config.ReleaseTag=${RELEASE_TAG} -X zotregistry.dev/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.dev/zot/pkg/api/config.BinaryType=$(extended-name) -X zotregistry.dev/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zot 173 174 .PHONY: binary-debug 175 binary-debug: $(if $(findstring ui,$(BUILD_LABELS)), ui) 176 binary-debug: modcheck swaggercheck build-metadata 177 env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-$(OS)-$(ARCH)-debug $(BUILDMODE_FLAGS) -tags $(BUILD_LABELS),debug,containers_image_openpgp -v -gcflags all='-N -l' -ldflags "-X zotregistry.dev/zot/pkg/api/config.ReleaseTag=${RELEASE_TAG} -X zotregistry.dev/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.dev/zot/pkg/api/config.BinaryType=$(extended-name) -X zotregistry.dev/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot 178 179 .PHONY: cli 180 cli: modcheck build-metadata 181 env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zli-$(OS)-$(ARCH) $(BUILDMODE_FLAGS) -tags $(BUILD_LABELS),search,containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.dev/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.dev/zot/pkg/api/config.BinaryType=$(extended-name) -X zotregistry.dev/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zli 182 183 .PHONY: bench 184 bench: modcheck build-metadata 185 env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zb-$(OS)-$(ARCH) $(BUILDMODE_FLAGS) -tags $(BUILD_LABELS),containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.dev/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.dev/zot/pkg/api/config.BinaryType=$(extended-name) -X zotregistry.dev/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zb 186 187 .PHONY: exporter-minimal 188 exporter-minimal: EXTENSIONS= 189 exporter-minimal: modcheck build-metadata 190 env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zxp-$(OS)-$(ARCH) $(BUILDMODE_FLAGS) -tags containers_image_openpgp -v -trimpath ./cmd/zxp 191 192 .PHONY: test-prereq 193 test-prereq: check-skopeo $(TESTDATA) $(ORAS) 194 195 .PHONY: test-extended 196 test-extended: $(if $(findstring ui,$(BUILD_LABELS)), ui) 197 test-extended: test-prereq 198 go test -failfast -tags $(BUILD_LABELS),containers_image_openpgp -trimpath -race -timeout 20m -cover -coverpkg ./... -coverprofile=coverage-extended.txt -covermode=atomic ./... 199 rm -rf /tmp/getter*; rm -rf /tmp/trivy* 200 201 .PHONY: test-minimal 202 test-minimal: test-prereq 203 go test -failfast -tags containers_image_openpgp -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-minimal.txt -covermode=atomic ./... 204 rm -rf /tmp/getter*; rm -rf /tmp/trivy* 205 206 .PHONY: test-devmode 207 test-devmode: $(if $(findstring ui,$(BUILD_LABELS)), ui) 208 test-devmode: test-prereq 209 go test -failfast -tags dev,$(BUILD_LABELS),containers_image_openpgp -trimpath -race -timeout 15m -cover -coverpkg ./... -coverprofile=coverage-dev-extended.txt -covermode=atomic ./pkg/test/... ./pkg/api/... ./pkg/storage/... ./pkg/extensions/sync/... -run ^TestInject 210 rm -rf /tmp/getter*; rm -rf /tmp/trivy* 211 go test -failfast -tags dev,containers_image_openpgp -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-dev-minimal.txt -covermode=atomic ./pkg/test/... ./pkg/storage/... ./pkg/extensions/sync/... -run ^TestInject 212 rm -rf /tmp/getter*; rm -rf /tmp/trivy* 213 go test -failfast -tags stress,$(BUILD_LABELS),containers_image_openpgp -trimpath -race -timeout 15m ./pkg/cli/server/stress_test.go 214 215 .PHONY: test 216 test: $(if $(findstring ui,$(BUILD_LABELS)), ui) 217 test: test-extended test-minimal test-devmode 218 219 .PHONY: privileged-test 220 privileged-test: $(if $(findstring ui,$(BUILD_LABELS)), ui) 221 privileged-test: check-skopeo $(TESTDATA) 222 go test -failfast -tags needprivileges,$(BUILD_LABELS),containers_image_openpgp -trimpath -race -timeout 15m -cover -coverpkg ./... -coverprofile=coverage-dev-needprivileges.txt -covermode=atomic ./pkg/storage/local/... ./pkg/cli/client/... -run ^TestElevatedPrivileges 223 224 $(TESTDATA): check-skopeo 225 mkdir -p ${TESTDATA}; \ 226 cd ${TESTDATA}; ../scripts/gen_certs.sh; \ 227 mkdir -p noidentity; cd ${TESTDATA}/noidentity; ../../scripts/gen_nameless_certs.sh; \ 228 cd ${TOP_LEVEL}; \ 229 skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:7 oci:${TESTDATA}/zot-test:0.0.1; \ 230 skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:8 oci:${TESTDATA}/zot-cve-test:0.0.1; \ 231 skopeo --insecure-policy copy -q docker://ghcr.io/project-zot/test-images/java:0.0.1 oci:${TESTDATA}/zot-cve-java-test:0.0.1; \ 232 skopeo --insecure-policy copy -q docker://ghcr.io/project-zot/test-images/alpine:3.17.3 oci:${TESTDATA}/alpine:3.17.3; \ 233 skopeo --insecure-policy copy -q docker://ghcr.io/project-zot/test-images/spring-web:5.3.31 oci:${TESTDATA}/spring-web:5.3.31; \ 234 chmod -R a=rwx ${TESTDATA} 235 ls -R -l ${TESTDATA} 236 237 .PHONY: run-bench 238 run-bench: binary bench 239 bin/zot-$(OS)-$(ARCH) serve examples/config-bench.json & echo $$! > zot.PID 240 sleep 5 241 bin/zb-$(OS)-$(ARCH) -c 10 -n 100 -o $(BENCH_OUTPUT) http://localhost:8080 242 @if [ -e zot.PID ]; then \ 243 kill -TERM $$(cat zot.PID) || true; \ 244 fi; \ 245 rm zot.PID 246 247 .PHONY: check-skopeo 248 check-skopeo: 249 skopeo -v || (echo "You need skopeo to be installed in order to run tests"; exit 1) 250 251 .PHONY: check-awslocal 252 check-awslocal: 253 awslocal --version || (echo "You need awslocal to be installed in order to run tests"; exit 1) 254 255 $(NOTATION): 256 mkdir -p $(TOOLSDIR)/bin 257 curl -Lo notation.tar.gz https://github.com/notaryproject/notation/releases/download/v$(NOTATION_VERSION)/notation_$(NOTATION_VERSION)_linux_amd64.tar.gz 258 tar xvzf notation.tar.gz -C $(TOOLSDIR)/bin notation 259 rm notation.tar.gz 260 261 $(ORAS): 262 mkdir -p $(TOOLSDIR)/bin 263 curl -Lo oras.tar.gz https://github.com/oras-project/oras/releases/download/v$(ORAS_VERSION)/oras_$(ORAS_VERSION)_linux_amd64.tar.gz 264 tar xvzf oras.tar.gz -C $(TOOLSDIR)/bin oras 265 rm oras.tar.gz 266 267 $(HELM): 268 mkdir -p $(TOOLSDIR)/bin 269 curl -Lo helm.tar.gz https://get.helm.sh/helm-v3.9.1-linux-amd64.tar.gz 270 tar xvzf helm.tar.gz -C $(TOOLSDIR)/bin linux-amd64/helm --strip-components=1 271 rm helm.tar.gz 272 273 $(REGCLIENT): 274 mkdir -p $(TOOLSDIR)/bin 275 curl -Lo regctl https://github.com/regclient/regclient/releases/download/$(REGCLIENT_VERSION)/regctl-linux-amd64 276 mv regctl $(TOOLSDIR)/bin/regctl 277 chmod +x $(TOOLSDIR)/bin/regctl 278 279 $(CRICTL): 280 mkdir -p $(TOOLSDIR)/bin 281 curl -Lo crictl.tar.gz https://github.com/kubernetes-sigs/cri-tools/releases/download/$(CRICTL_VERSION)/crictl-$(CRICTL_VERSION)-linux-amd64.tar.gz 282 tar xvzf crictl.tar.gz && rm crictl.tar.gz 283 mv crictl $(TOOLSDIR)/bin/crictl 284 chmod +x $(TOOLSDIR)/bin/crictl 285 286 $(PROTOC): 287 mkdir -p $(TOOLSDIR)/bin 288 curl -Lo protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS)-$(PROTOC_ARCH).zip 289 unzip -o -d $(TOOLSDIR) protoc.zip bin/protoc 290 rm protoc.zip 291 chmod +x $(PROTOC) 292 go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(GO_PROTOC_VERSION) 293 294 $(ACTION_VALIDATOR): 295 mkdir -p $(TOOLSDIR)/bin 296 curl -Lo action-validator https://github.com/mpalmer/action-validator/releases/download/$(ACTION_VALIDATOR_VERSION)/action-validator_$(OS)_$(ARCH) 297 mv action-validator $(TOOLSDIR)/bin/action-validator 298 chmod +x $(TOOLSDIR)/bin/action-validator 299 300 .PHONY: check-gh-actions 301 check-gh-actions: check-compatibility $(ACTION_VALIDATOR) 302 for i in $$(ls .github/workflows/*); do $(ACTION_VALIDATOR) $$i; done 303 304 .PHONY: covhtml 305 covhtml: 306 go install github.com/wadey/gocovmerge@latest 307 gocovmerge coverage*.txt > coverage.txt 308 go tool cover -html=coverage.txt -o coverage.html 309 310 $(GOLINTER): 311 mkdir -p $(TOOLSDIR)/bin 312 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLSDIR)/bin $(GOLINTER_VERSION) 313 $(GOLINTER) version 314 315 .PHONY: check-logs 316 check-logs: 317 @./scripts/check_logs.sh 318 319 .PHONY: check 320 check: $(if $(findstring ui,$(BUILD_LABELS)), ui) 321 check: ./golangcilint.yaml $(GOLINTER) 322 mkdir -p pkg/extensions/build; touch pkg/extensions/build/.empty 323 $(GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format=colored-line-number --build-tags containers_image_openpgp ./... 324 $(GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format=colored-line-number --build-tags $(BUILD_LABELS),containers_image_openpgp ./... 325 $(GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format=colored-line-number --build-tags debug ./pkg/debug/swagger/ ./pkg/debug/gqlplayground 326 $(GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format=colored-line-number --build-tags dev ./pkg/test/inject/ 327 $(GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format=colored-line-number --build-tags stress ./pkg/cli/server/ 328 rm pkg/extensions/build/.empty 329 330 .PHONY: swagger 331 swagger: 332 swag -v || go install github.com/swaggo/swag/cmd/swag@$(SWAGGER_VERSION) 333 swag init --parseDependency -o swagger -g pkg/api/routes.go -q 334 335 .PHONY: update-licenses 336 # note: for predictable output of below sort command we use locale LC_ALL=C 337 update-licenses: check-linux 338 @echo "Detecting and updating licenses ... please be patient!" 339 go install github.com/google/go-licenses@latest 340 ./scripts/update_licenses.sh 341 $(eval UNCOMMITED_FILES = $(shell git status --porcelain | grep -c THIRD-PARTY-LICENSES.md)) 342 @if [ $(UNCOMMITED_FILES) != 0 ]; then \ 343 echo "THIRD-PARTY-LICENSES.md file needs to be updated";\ 344 git status;\ 345 exit 1;\ 346 fi 347 348 .PHONY: check-licenses 349 check-licenses: 350 # note: "printf" works for darwin instead of "echo -n" 351 go install github.com/google/go-licenses@latest 352 @for tag in "$(BUILD_LABELS),containers_image_openpgp" "containers_image_openpgp"; do \ 353 echo Evaluating tag: $$tag;\ 354 for mod in $$(go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all); do \ 355 while [ x$$mod != x ]; do \ 356 printf "Checking $$mod ... "; \ 357 result=$$(GOFLAGS="-tags=$${tag}" go-licenses check $$mod 2>&1); \ 358 if [ $$? -eq 0 ]; then \ 359 echo OK; \ 360 break; \ 361 fi; \ 362 echo "$${result}" | grep -q "Forbidden"; \ 363 if [ $$? -eq 0 ]; then \ 364 echo FAIL; \ 365 exit 1; \ 366 fi; \ 367 echo "$${result}" | egrep -q "missing go.sum entry|no required module provides package|build constraints exclude all|updates to go.mod needed|non-Go code"; \ 368 if [ $$? -eq 0 ]; then \ 369 echo UNKNOWN; \ 370 break; \ 371 fi; \ 372 done; \ 373 done; \ 374 done 375 376 .PHONY: clean 377 clean: 378 rm -f bin/z* 379 rm -rf hack 380 rm -rf test/data/zot-test 381 rm -rf test/data/zot-cve-test 382 rm -rf test/data/zot-cve-java-test 383 rm -rf pkg/extensions/build 384 385 .PHONY: run 386 run: binary 387 ./bin/zot-$(OS)-$(ARCH) serve examples/config-test.json 388 389 .PHONY: verify-config 390 verify-config: _verify-config verify-config-warnings verify-config-commited 391 392 .PHONY: _verify-config 393 _verify-config: binary 394 rm -f output.txt 395 $(foreach file, $(wildcard examples/config-*), ./bin/zot-$(OS)-$(ARCH) verify $(file) 2>&1 | tee -a output.txt || exit 1;) 396 397 .PHONY: verify-config-warnings 398 verify-config-warnings: _verify-config 399 $(eval WARNINGS = $(shell cat output.txt | grep -c '"warn"')) 400 $(eval ERRORS = $(shell cat output.txt | grep -c '"error"')) 401 @if [ $(WARNINGS) != 0 ] || [ $(ERRORS) != 0 ]; then \ 402 echo "verify-config-warnings: warnings or errors found while verifying configs"; \ 403 rm output.txt; \ 404 exit 1; \ 405 fi 406 rm -f output.txt 407 408 .PHONY: verify-config-commited 409 verify-config-commited: _verify-config 410 $(eval UNCOMMITED_FILES = $(shell git status --porcelain | grep -c examples/config-)) 411 @if [ $(UNCOMMITED_FILES) != 0 ]; then \ 412 echo "Uncommited config files, make sure all config files are commited. Verify might have changed a config file.";\ 413 exit 1;\ 414 fi; \ 415 416 .PHONY: gqlgen 417 gqlgen: 418 cd pkg/extensions/search;\ 419 go run github.com/99designs/gqlgen version;\ 420 go run github.com/99designs/gqlgen generate 421 422 .PHONY: verify-gql-committed 423 verify-gql-committed: 424 $(eval UNCOMMITED_FILES = $(shell git status --porcelain | grep -c extensions/search)) 425 @if [ $(UNCOMMITED_FILES) != 0 ]; then \ 426 echo "Updated gql files uncommitted, make sure all gql files are committed:";\ 427 git status;\ 428 exit 1;\ 429 fi; \ 430 431 .PHONY: binary-container 432 binary-container: 433 ${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f build/Dockerfile -t zot-build:latest . 434 435 .PHONY: run-container 436 run-container: 437 ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/go/src/github.com/project-zot/zot \ 438 zot-build:latest 439 440 .PHONY: binary-minimal-container 441 binary-minimal-container: 442 ${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f build/Dockerfile-minimal -t zot-minimal:latest . 443 444 .PHONY: run-minimal-container 445 run-minimal-container: 446 ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/go/src/github.com/project-zot/zot \ 447 zot-minimal:latest 448 449 .PHONY: binary-exporter-container 450 binary-exporter-container: 451 ${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f build/Dockerfile-zxp -t zxp:latest . 452 453 .PHONY: run-exporter-container 454 run-exporter-container: 455 ${CONTAINER_RUNTIME} run --rm --security-opt label=disable zxp:latest 456 457 .PHONY: oci-image 458 oci-image: $(STACKER) 459 ${STACKER} --debug build \ 460 -f build/stacker.yaml \ 461 --substitute COMMIT=$(COMMIT) \ 462 --substitute ARCH=$(ARCH) \ 463 --substitute OS=$(OS) \ 464 --substitute RELEASE_TAG=$(RELEASE_TAG) \ 465 --substitute REPO_NAME=zot-$(OS)-$(ARCH) 466 467 .PHONY: docker-image 468 docker-image: 469 ${CONTAINER_RUNTIME} buildx build --platform $(OS)/$(ARCH) -f build/Dockerfile . 470 471 $(BATS): 472 rm -rf bats-core; \ 473 git clone https://github.com/bats-core/bats-core.git; \ 474 cd bats-core; ./install.sh $(TOOLSDIR); cd ..; \ 475 rm -rf bats-core 476 477 .PHONY: check-blackbox-prerequisites 478 check-blackbox-prerequisites: check-linux check-skopeo $(BATS) $(REGCLIENT) $(ORAS) $(HELM) $(CRICTL) $(NOTATION) $(COSIGN) $(STACKER) 479 which skopeo && skopeo --version; \ 480 which stacker && stacker --version; \ 481 which regctl && regctl version; \ 482 which oras && oras version; \ 483 which helm && helm version; \ 484 which crictl && crictl version; \ 485 which notation && notation version; \ 486 which cosign && cosign version; 487 488 .PHONY: run-blackbox-tests 489 run-blackbox-tests: $(BATS_TEST_FILE_PATH) check-blackbox-prerequisites binary binary-minimal cli bench 490 echo running bats test "$(BATS_TEST_FILE_PATH)"; \ 491 $(BATS) $(BATS_FLAGS) $(BATS_TEST_FILE_PATH) 492 493 .PHONY: run-blackbox-ci 494 run-blackbox-ci: check-blackbox-prerequisites binary binary-minimal cli 495 echo running CI bats tests concurently 496 BATS_FLAGS="$(BATS_FLAGS)" test/blackbox/ci.sh 497 498 .PHONY: run-blackbox-cloud-ci 499 run-blackbox-cloud-ci: check-blackbox-prerequisites check-awslocal binary $(BATS) 500 echo running cloud CI bats tests; \ 501 $(BATS) $(BATS_FLAGS) test/blackbox/cloud_only.bats 502 $(BATS) $(BATS_FLAGS) test/blackbox/sync_cloud.bats 503 504 .PHONY: run-blackbox-dedupe-nightly 505 run-blackbox-dedupe-nightly: check-blackbox-prerequisites check-awslocal binary binary-minimal 506 echo running nightly dedupe tests; \ 507 $(BATS) $(BATS_FLAGS) test/blackbox/restore_s3_blobs.bats && \ 508 $(BATS) $(BATS_FLAGS) test/blackbox/pushpull_running_dedupe.bats 509 510 .PHONY: run-blackbox-sync-nightly 511 run-blackbox-sync-nightly: check-blackbox-prerequisites binary binary-minimal bench 512 echo running nightly sync tests; \ 513 $(BATS) $(BATS_FLAGS) test/blackbox/sync_harness.bats 514 515 .PHONY: fuzz-all 516 fuzz-all: fuzztime=${1} 517 fuzz-all: 518 rm -rf test-data; \ 519 rm -rf pkg/storage/testdata; \ 520 git clone https://github.com/project-zot/test-data.git; \ 521 mv test-data/storage pkg/storage/testdata; \ 522 rm -rf test-data; \ 523 bash test/scripts/fuzzAll.sh ${fuzztime}; \ 524 rm -rf pkg/storage/testdata; \ 525 526 $(STACKER): check-linux 527 mkdir -p $(TOOLSDIR)/bin; \ 528 curl -fsSL https://github.com/project-stacker/stacker/releases/latest/download/stacker -o $@; \ 529 chmod +x $@ 530 531 $(COSIGN): 532 mkdir -p $(TOOLSDIR)/bin 533 curl -fsSL https://github.com/sigstore/cosign/releases/download/v$(COSIGN_VERSION)/cosign-linux-amd64 -o $@; \ 534 chmod +x $@ 535 536 # set ZUI_VERSION to empty string in order to clone zui locally and build default branch 537 .PHONY: ui 538 ui: 539 echo $(BUILD_LABELS);\ 540 if [ -n $(ZUI_BUILD_PATH) ]; then\ 541 rm -rf ./pkg/extensions/build;\ 542 cp -R $(ZUI_BUILD_PATH) ./pkg/extensions/;\ 543 exit 0;\ 544 fi;\ 545 if [ -z $(ZUI_VERSION) ]; then\ 546 pwd=$$(pwd);\ 547 tdir=$$(mktemp -d);\ 548 cd $$tdir;\ 549 git clone https://github.com/$(ZUI_REPO_OWNER)/$(ZUI_REPO_NAME).git zui;\ 550 cd zui;\ 551 npm install;\ 552 npm run build;\ 553 cd $$pwd;\ 554 rm -rf ./pkg/extensions/build;\ 555 cp -R $$tdir/zui/build ./pkg/extensions/;\ 556 else\ 557 curl --fail --head https://github.com/$(ZUI_REPO_OWNER)/$(ZUI_REPO_NAME)/releases/download/$(ZUI_VERSION)/zui.tgz;\ 558 if [ $$? -ne 0 ]; then\ 559 pwd=$$(pwd);\ 560 tdir=$$(mktemp -d);\ 561 cd $$tdir;\ 562 git clone --depth=1 --branch $(ZUI_VERSION) https://github.com/$(ZUI_REPO_OWNER)/$(ZUI_REPO_NAME).git zui;\ 563 cd zui;\ 564 git checkout $(ZUI_VERSION);\ 565 npm install;\ 566 npm run build;\ 567 cd $$pwd;\ 568 rm -rf ./pkg/extensions/build;\ 569 cp -R $$tdir/zui/build ./pkg/extensions/;\ 570 else\ 571 curl -fsSL https://github.com/$(ZUI_REPO_OWNER)/$(ZUI_REPO_NAME)/releases/download/$(ZUI_VERSION)/zui.tgz -o zui.tgz;\ 572 tar xvzf zui.tgz -C ./pkg/extensions/;\ 573 rm zui.tgz;\ 574 fi;\ 575 fi;\ 576 577 .PHONY: check-linux 578 check-linux: 579 ifneq ($(shell go env GOOS),linux) 580 $(error makefile target can be run only on linux) 581 endif 582 583 .PHONY: check-not-freebds 584 check-not-freebds: 585 ifeq ($(shell go env GOOS),freebsd) 586 $(error makefile target can't be run on freebsd) 587 endif 588 589 .PHONY: check-compatibility 590 check-compatibility: 591 ifeq ($(OS),freebsd) 592 $(error makefile target can't be run on freebsd) 593 endif 594 ifneq ($(OS),$(shell go env GOOS)) 595 $(error target can't be run on $(shell go env GOOS) as binary is compiled for $(OS)) 596 endif 597 ifneq ($(ARCH),$(shell go env GOARCH)) 598 $(error target can't be run on $(shell go env GOARCH) (binary is for $(ARCH))) 599 endif