2019-06-20 18:36:40 -05:00
export GO111MODULE = on
2019-07-20 19:30:58 -05:00
TOP_LEVEL = $( shell git rev-parse --show-toplevel)
2019-09-16 13:01:59 -05:00
COMMIT_HASH = $( shell git describe --always --tags --long)
2022-10-11 11:01:59 -05:00
RELEASE_TAG = $( shell git describe --tags --abbrev= 0)
2021-10-15 10:05:00 -05:00
GO_VERSION = $( shell go version | awk '{print $$3}' )
2021-12-15 17:47:53 -05:00
COMMIT ?= $( if $( shell git status --porcelain --untracked-files= no) ,$( COMMIT_HASH) -dirty,$( COMMIT_HASH) )
2019-08-14 14:35:51 -05:00
CONTAINER_RUNTIME := $( shell command -v podman 2> /dev/null || echo docker)
2020-07-09 02:10:11 -05:00
TMPDIR := $( shell mktemp -d)
2022-03-22 17:13:10 -05:00
TOOLSDIR := $( shell pwd ) /hack/tools
PATH := bin:$( TOOLSDIR) /bin:$( PATH)
2020-11-05 20:57:06 -05:00
STACKER := $( shell which stacker)
2021-12-13 14:23:31 -05:00
GOLINTER := $( TOOLSDIR) /bin/golangci-lint
2024-07-29 12:32:51 -05:00
GOLINTER_VERSION := v1.59.1
2021-12-07 08:07:22 -05:00
NOTATION := $( TOOLSDIR) /bin/notation
2023-10-12 20:45:20 -05:00
NOTATION_VERSION := 1.0.0
2022-11-01 11:16:14 -05:00
COSIGN := $( TOOLSDIR) /bin/cosign
2023-09-20 14:01:36 -05:00
COSIGN_VERSION := 2.2.0
2022-07-22 06:34:12 -05:00
HELM := $( TOOLSDIR) /bin/helm
ORAS := $( TOOLSDIR) /bin/oras
2023-02-28 10:38:49 -05:00
ORAS_VERSION := 1.0.0-rc.1
2022-07-22 06:34:12 -05:00
REGCLIENT := $( TOOLSDIR) /bin/regctl
2024-03-08 11:49:12 -05:00
REGCLIENT_VERSION := v0.5.7
2023-04-13 15:47:38 -05:00
CRICTL := $( TOOLSDIR) /bin/crictl
CRICTL_VERSION := v1.26.1
2023-01-13 03:49:42 -05:00
ACTION_VALIDATOR := $( TOOLSDIR) /bin/action-validator
2023-09-28 13:59:52 -05:00
ACTION_VALIDATOR_VERSION := v0.5.3
2023-12-07 08:02:29 -05:00
ZUI_BUILD_PATH := ""
2024-08-19 10:14:06 -05:00
ZUI_VERSION := commit-3178209
2023-11-13 12:57:51 -05:00
ZUI_REPO_OWNER := project-zot
ZUI_REPO_NAME := zui
2024-02-07 13:54:28 -05:00
SWAGGER_VERSION := v1.16.2
2022-10-18 22:47:41 -05:00
STACKER := $( TOOLSDIR) /bin/stacker
2022-03-22 17:13:10 -05:00
BATS := $( TOOLSDIR) /bin/bats
2022-03-15 09:34:39 -05:00
TESTDATA := $( TOP_LEVEL) /test/data
2023-08-18 16:18:10 -05:00
OS ?= $( shell go env GOOS)
ARCH ?= $( shell go env GOARCH)
2023-10-30 15:06:04 -05:00
PROTOC := $( TOOLSDIR) /bin/protoc
PROTOC_VERSION := 24.4
GO_PROTOC_VERSION := 1.31.0
HOST_OS := $( shell go env GOOS)
HOST_ARCH := $( shell go env GOARCH)
i f e q ( $( HOST_OS ) , l i n u x )
PROTOC_OS := linux
e l s e i f e q ( $( HOST_OS ) , d a r w i n )
PROTOC_OS := osx
e n d i f
i f e q ( $( HOST_ARCH ) , a m d 6 4 )
PROTOC_ARCH := x86_64
e l s e i f e q ( $( HOST_ARCH ) , a r m 6 4 )
PROTOC_ARCH := aarch_64
e n d i f
2022-01-13 17:06:35 -05:00
BENCH_OUTPUT ?= stdout
2023-09-18 16:05:41 -05:00
ALL_EXTENSIONS = debug,imagetrust,lint,metrics,mgmt,profile,scrub,search,sync,ui,userprefs
EXTENSIONS ?= sync,search,scrub,metrics,lint,ui,mgmt,profile,userprefs,imagetrust
2023-08-02 13:58:34 -05:00
UI_DEPENDENCIES := search,mgmt,userprefs
2024-03-20 13:53:11 -05:00
# freebsd is not supported for pie builds if CGO is disabled
# see supported platforms at https://cs.opensource.google/go/go/+/master:src/internal/platform/supported.go;l=222-231;drc=d7fcb5cf80953f1d63246f1ae9defa60c5ce2d76
2023-07-31 15:51:03 -05:00
BUILDMODE_FLAGS := -buildmode= pie
i f e q ( $( OS ) , f r e e b s d )
2024-03-20 13:53:11 -05:00
BUILDMODE_FLAGS =
2023-07-31 15:51:03 -05:00
e n d i f
2022-04-27 01:00:20 -05:00
comma := ,
2023-05-12 11:43:14 -05:00
space := $( null) #
2022-04-27 01:00:20 -05:00
hyphen := -
2019-06-20 18:36:40 -05:00
2023-08-03 12:53:37 -05:00
merge-ui-extensions = $( subst $( 1) ,$( 2) ,$( if $( findstring ui,$( 3) ) ,$( 3) $( 1) $( 4) ,$( 3) ) )
merged-extensions = $( call merge-ui-extensions,$( comma) ,$( space) ,$( EXTENSIONS) ,$( UI_DEPENDENCIES) )
filter-valid = $( foreach ext, $( merged-extensions) , $( if $( findstring $( ext) ,$( ALL_EXTENSIONS) ) ,$( ext) ,$( error unknown extension: $( ext) ) ) )
add-extensions = $( subst $( 1) ,$( 2) ,$( sort $( filter-valid) ) )
BUILD_LABELS = $( call add-extensions,$( space) ,$( comma) )
2023-09-12 13:31:10 -05:00
extended-name = -$( subst $( comma) ,$( hyphen) ,$( BUILD_LABELS) )
2023-05-12 11:43:14 -05:00
2023-09-07 13:06:21 -05:00
BATS_TEST_FILE_PATH ?= replace_me
i f e q ( $( BATS_VERBOSITY ) , 2 )
BATS_FLAGS = --trace --verbose-run --show-output-of-passing-tests --print-output-on-failure
e l s e i f e q ( $( BATS_VERBOSITY ) , 1 )
BATS_FLAGS = --trace --verbose-run --print-output-on-failure
e l s e
BATS_FLAGS = --print-output-on-failure
e n d i f
2019-06-20 18:36:40 -05:00
.PHONY : all
2023-09-07 13:06:21 -05:00
all : modcheck swaggercheck binary binary -minimal binary -debug cli bench exporter -minimal verify -config check check -gh -actions test covhtml
2022-03-02 16:20:35 -05:00
2023-03-21 12:25:13 -05:00
.PHONY : modtidy
modtidy :
2022-03-02 16:20:35 -05:00
go mod tidy
2022-01-24 00:19:01 -05:00
2023-03-21 12:25:13 -05:00
.PHONY : modcheck
modcheck : modtidy
$( eval UNCOMMITED_FILES = $( shell git status --porcelain | grep -c 'go.mod\|go.sum' ) )
@if [ $( UNCOMMITED_FILES) != 0 ] ; then \
echo "Updated go.mod and/or go.sum have uncommitted changes, commit the changes accordingly " ; \
git status; \
exit 1; \
fi
2023-08-23 11:21:43 -05:00
.PHONY : swaggercheck
swaggercheck : swagger
$( eval UNCOMMITED_FILES = $( shell git status --porcelain | grep -c swagger) )
@if [ $( UNCOMMITED_FILES) != 0 ] ; then \
echo "Updated swagger files uncommitted, make sure all swagger files are committed:" ; \
git status; \
exit 1; \
fi
2022-07-07 06:11:01 -05:00
.PHONY : build -metadata
2023-05-12 11:43:14 -05:00
build-metadata : $( if $ ( findstring ui ,$ ( BUILD_LABELS ) ) , ui )
2023-09-12 13:31:10 -05:00
# do not allow empty $(BUILD_TAGS) (at least add containers_image_openpgp that doesn't affect package import & files listing)
$( eval BUILD_TAGS = $( if $( BUILD_LABELS) ,$( BUILD_LABELS) ,containers_image_openpgp) )
2022-07-07 06:11:01 -05:00
echo "Imports: \n"
2023-09-12 13:31:10 -05:00
go list -tags $( BUILD_TAGS) -f '{{ join .Imports "\n" }}' ./... | sort -u
2022-07-07 06:11:01 -05:00
echo "\n Files: \n"
2023-09-12 13:31:10 -05:00
go list -tags $( BUILD_TAGS) -f '{{ join .GoFiles "\n" }}' ./... | sort -u
2022-07-07 06:11:01 -05:00
2023-10-30 15:06:04 -05:00
.PHONY : gen -protobuf
gen-protobuf : check -not -freebds $( PROTOC )
$( PROTOC) --experimental_allow_proto3_optional \
--proto_path= $( TOP_LEVEL) /pkg/meta/proto \
--go_out= $( TOP_LEVEL) /pkg/meta/proto \
--go_opt= 'Moci/oci.proto=./gen' \
--go_opt= 'Mmeta/meta.proto=./gen' \
--go_opt= 'Moci/config.proto=./gen' \
--go_opt= 'Moci/manifest.proto=./gen' \
--go_opt= 'Moci/index.proto=./gen' \
--go_opt= 'Moci/descriptor.proto=./gen' \
--go_opt= 'Moci/versioned.proto=./gen' \
$( TOP_LEVEL) /pkg/meta/proto/meta/meta.proto
$( PROTOC) --experimental_allow_proto3_optional \
--proto_path= $( TOP_LEVEL) /pkg/meta/proto \
--go_out= $( TOP_LEVEL) /pkg/meta/proto \
--go_opt= 'Moci/versioned.proto=./gen' \
$( TOP_LEVEL) /pkg/meta/proto/oci/versioned.proto
$( PROTOC) --experimental_allow_proto3_optional \
--proto_path= $( TOP_LEVEL) /pkg/meta/proto \
--go_out= $( TOP_LEVEL) /pkg/meta/proto \
--go_opt= 'Moci/descriptor.proto=./gen' \
$( TOP_LEVEL) /pkg/meta/proto/oci/descriptor.proto
$( PROTOC) --experimental_allow_proto3_optional \
--proto_path= $( TOP_LEVEL) /pkg/meta/proto \
--go_out= $( TOP_LEVEL) /pkg/meta/proto \
--go_opt= 'Moci/descriptor.proto=./gen' \
--go_opt= 'Moci/versioned.proto=./gen' \
--go_opt= 'Moci/index.proto=./gen' \
$( TOP_LEVEL) /pkg/meta/proto/oci/index.proto
$( PROTOC) --experimental_allow_proto3_optional \
--proto_path= $( TOP_LEVEL) /pkg/meta/proto \
--go_out= $( TOP_LEVEL) /pkg/meta/proto \
--go_opt= 'Moci/oci.proto=./gen' \
--go_opt= 'Moci/descriptor.proto=./gen' \
--go_opt= 'Moci/config.proto=./gen' \
$( TOP_LEVEL) /pkg/meta/proto/oci/config.proto
$( PROTOC) --experimental_allow_proto3_optional \
--proto_path= $( TOP_LEVEL) /pkg/meta/proto \
--go_out= $( TOP_LEVEL) /pkg/meta/proto \
--go_opt= 'Moci/versioned.proto=./gen' \
--go_opt= 'Moci/descriptor.proto=./gen' \
--go_opt= 'Moci/manifest.proto=./gen' \
$( TOP_LEVEL) /pkg/meta/proto/oci/manifest.proto
2022-10-03 11:53:44 -05:00
.PHONY : binary -minimal
2023-09-12 13:31:10 -05:00
binary-minimal : EXTENSIONS =
2022-10-03 11:53:44 -05:00
binary-minimal : modcheck build -metadata
2024-01-31 23:34:07 -05:00
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
2022-10-03 11:53:44 -05:00
2022-04-27 01:00:20 -05:00
.PHONY : binary
2023-05-12 11:43:14 -05:00
binary : $( if $ ( findstring ui ,$ ( BUILD_LABELS ) ) , ui )
2023-09-12 13:31:10 -05:00
binary : modcheck build -metadata
2024-01-31 23:34:07 -05:00
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
2022-04-27 01:00:20 -05:00
2022-01-24 00:19:01 -05:00
.PHONY : binary -debug
2023-05-12 11:43:14 -05:00
binary-debug : $( if $ ( findstring ui ,$ ( BUILD_LABELS ) ) , ui )
2023-09-12 13:31:10 -05:00
binary-debug : modcheck swaggercheck build -metadata
2024-01-31 23:34:07 -05:00
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
2021-12-15 17:14:53 -05:00
2022-01-10 20:15:35 -05:00
.PHONY : cli
2023-09-12 13:31:10 -05:00
cli : modcheck build -metadata
2024-01-31 23:34:07 -05:00
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
2022-01-10 20:15:35 -05:00
2021-12-10 17:27:40 -05:00
.PHONY : bench
2023-09-12 13:31:10 -05:00
bench : modcheck build -metadata
2024-01-31 23:34:07 -05:00
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
2021-12-10 17:27:40 -05:00
2021-10-15 10:05:00 -05:00
.PHONY : exporter -minimal
2023-09-12 13:31:10 -05:00
exporter-minimal : EXTENSIONS =
2022-07-07 06:11:01 -05:00
exporter-minimal : modcheck build -metadata
2023-07-31 15:51:03 -05:00
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
2019-06-20 18:36:40 -05:00
2023-09-28 13:59:52 -05:00
.PHONY : test -prereq
test-prereq : check -skopeo $( TESTDATA ) $( ORAS )
.PHONY : test -extended
test-extended : $( if $ ( findstring ui ,$ ( BUILD_LABELS ) ) , ui )
test-extended : test -prereq
2023-12-11 13:00:34 -05:00
go test -failfast -tags $( BUILD_LABELS) ,containers_image_openpgp -trimpath -race -timeout 20m -cover -coverpkg ./... -coverprofile= coverage-extended.txt -covermode= atomic ./...
2023-06-15 17:07:28 -05:00
rm -rf /tmp/getter*; rm -rf /tmp/trivy*
2023-09-28 13:59:52 -05:00
.PHONY : test -minimal
test-minimal : test -prereq
go test -failfast -tags containers_image_openpgp -trimpath -race -cover -coverpkg ./... -coverprofile= coverage-minimal.txt -covermode= atomic ./...
2023-06-15 17:07:28 -05:00
rm -rf /tmp/getter*; rm -rf /tmp/trivy*
2023-09-28 13:59:52 -05:00
.PHONY : test -devmode
test-devmode : $( if $ ( findstring ui ,$ ( BUILD_LABELS ) ) , ui )
test-devmode : test -prereq
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
2023-06-15 17:07:28 -05:00
rm -rf /tmp/getter*; rm -rf /tmp/trivy*
2023-09-28 13:59:52 -05:00
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
2023-06-15 17:07:28 -05:00
rm -rf /tmp/getter*; rm -rf /tmp/trivy*
2023-09-28 13:59:52 -05:00
go test -failfast -tags stress,$( BUILD_LABELS) ,containers_image_openpgp -trimpath -race -timeout 15m ./pkg/cli/server/stress_test.go
.PHONY : test
test : $( if $ ( findstring ui ,$ ( BUILD_LABELS ) ) , ui )
test : test -extended test -minimal test -devmode
2019-06-20 18:36:40 -05:00
2022-03-15 09:34:39 -05:00
.PHONY : privileged -test
2023-05-12 11:43:14 -05:00
privileged-test : $( if $ ( findstring ui ,$ ( BUILD_LABELS ) ) , ui )
2023-02-13 13:43:52 -05:00
privileged-test : check -skopeo $( TESTDATA )
2023-09-28 13:59:52 -05:00
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
2022-03-15 09:34:39 -05:00
$(TESTDATA) : check -skopeo
2023-05-31 16:37:46 -05:00
mkdir -p ${ TESTDATA } ; \
cd ${ TESTDATA } ; ../scripts/gen_certs.sh; \
mkdir -p noidentity; cd ${ TESTDATA } /noidentity; ../../scripts/gen_nameless_certs.sh; \
cd ${ TOP_LEVEL } ; \
skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:7 oci:${ TESTDATA } /zot-test:0.0.1; \
skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:8 oci:${ TESTDATA } /zot-cve-test:0.0.1; \
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; \
2023-07-06 03:36:26 -05:00
skopeo --insecure-policy copy -q docker://ghcr.io/project-zot/test-images/alpine:3.17.3 oci:${ TESTDATA } /alpine:3.17.3; \
2024-02-15 16:19:49 -05:00
skopeo --insecure-policy copy -q docker://ghcr.io/project-zot/test-images/spring-web:5.3.31 oci:${ TESTDATA } /spring-web:5.3.31; \
2023-05-31 16:37:46 -05:00
chmod -R a = rwx ${ TESTDATA }
2023-08-18 03:46:11 -05:00
ls -R -l ${ TESTDATA }
2022-03-15 09:34:39 -05:00
2022-01-13 17:06:35 -05:00
.PHONY : run -bench
run-bench : binary bench
2023-09-28 13:59:52 -05:00
bin/zot-$( OS) -$( ARCH) serve examples/config-bench.json & echo $$ ! > zot.PID
2024-09-30 12:37:53 -05:00
curl --connect-timeout 3 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 180 --retry-connrefused http://localhost:8080/v2/
2022-01-24 00:19:01 -05:00
bin/zb-$( OS) -$( ARCH) -c 10 -n 100 -o $( BENCH_OUTPUT) http://localhost:8080
2023-09-28 13:59:52 -05:00
@if [ -e zot.PID ] ; then \
kill -TERM $$ ( cat zot.PID) || true; \
fi ; \
rm zot.PID
2022-01-13 17:06:35 -05:00
2021-12-07 08:07:22 -05:00
.PHONY : check -skopeo
check-skopeo :
skopeo -v || ( echo "You need skopeo to be installed in order to run tests" ; exit 1)
2023-09-07 13:06:21 -05:00
.PHONY : check -awslocal
check-awslocal :
awslocal --version || ( echo "You need awslocal to be installed in order to run tests" ; exit 1)
2021-12-07 08:07:22 -05:00
$(NOTATION) :
mkdir -p $( TOOLSDIR) /bin
2023-02-13 13:43:52 -05:00
curl -Lo notation.tar.gz https://github.com/notaryproject/notation/releases/download/v$( NOTATION_VERSION) /notation_$( NOTATION_VERSION) _linux_amd64.tar.gz
2021-12-07 08:07:22 -05:00
tar xvzf notation.tar.gz -C $( TOOLSDIR) /bin notation
rm notation.tar.gz
2022-07-22 06:34:12 -05:00
$(ORAS) :
mkdir -p $( TOOLSDIR) /bin
2022-11-28 13:43:53 -05:00
curl -Lo oras.tar.gz https://github.com/oras-project/oras/releases/download/v$( ORAS_VERSION) /oras_$( ORAS_VERSION) _linux_amd64.tar.gz
2022-07-22 06:34:12 -05:00
tar xvzf oras.tar.gz -C $( TOOLSDIR) /bin oras
rm oras.tar.gz
$(HELM) :
mkdir -p $( TOOLSDIR) /bin
curl -Lo helm.tar.gz https://get.helm.sh/helm-v3.9.1-linux-amd64.tar.gz
tar xvzf helm.tar.gz -C $( TOOLSDIR) /bin linux-amd64/helm --strip-components= 1
rm helm.tar.gz
$(REGCLIENT) :
mkdir -p $( TOOLSDIR) /bin
2022-11-08 03:38:16 -05:00
curl -Lo regctl https://github.com/regclient/regclient/releases/download/$( REGCLIENT_VERSION) /regctl-linux-amd64
2023-08-03 12:53:37 -05:00
mv regctl $( TOOLSDIR) /bin/regctl
2022-07-22 06:34:12 -05:00
chmod +x $( TOOLSDIR) /bin/regctl
2023-04-13 15:47:38 -05:00
$(CRICTL) :
mkdir -p $( TOOLSDIR) /bin
curl -Lo crictl.tar.gz https://github.com/kubernetes-sigs/cri-tools/releases/download/$( CRICTL_VERSION) /crictl-$( CRICTL_VERSION) -linux-amd64.tar.gz
2023-08-03 12:53:37 -05:00
tar xvzf crictl.tar.gz && rm crictl.tar.gz
mv crictl $( TOOLSDIR) /bin/crictl
2023-04-13 15:47:38 -05:00
chmod +x $( TOOLSDIR) /bin/crictl
2023-10-30 15:06:04 -05:00
$(PROTOC) :
mkdir -p $( TOOLSDIR) /bin
curl -Lo protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$( PROTOC_VERSION) /protoc-$( PROTOC_VERSION) -$( PROTOC_OS) -$( PROTOC_ARCH) .zip
unzip -o -d $( TOOLSDIR) protoc.zip bin/protoc
rm protoc.zip
chmod +x $( PROTOC)
go install google.golang.org/protobuf/cmd/protoc-gen-go@v$( GO_PROTOC_VERSION)
2023-04-13 15:47:38 -05:00
2023-01-13 03:49:42 -05:00
$(ACTION_VALIDATOR) :
mkdir -p $( TOOLSDIR) /bin
2023-09-28 13:59:52 -05:00
curl -Lo action-validator https://github.com/mpalmer/action-validator/releases/download/$( ACTION_VALIDATOR_VERSION) /action-validator_$( OS) _$( ARCH)
2023-08-03 12:53:37 -05:00
mv action-validator $( TOOLSDIR) /bin/action-validator
2023-01-13 03:49:42 -05:00
chmod +x $( TOOLSDIR) /bin/action-validator
.PHONY : check -gh -actions
2023-09-28 13:59:52 -05:00
check-gh-actions : check -compatibility $( ACTION_VALIDATOR )
2023-01-13 03:49:42 -05:00
for i in $$ ( ls .github/workflows/*) ; do $( ACTION_VALIDATOR) $$ i; done
2020-01-24 16:32:38 -05:00
.PHONY : covhtml
covhtml :
2021-12-20 23:18:13 -05:00
go install github.com/wadey/gocovmerge@latest
2022-03-15 09:34:39 -05:00
gocovmerge coverage*.txt > coverage.txt
2020-01-24 16:32:38 -05:00
go tool cover -html= coverage.txt -o coverage.html
2021-12-13 14:23:31 -05:00
$(GOLINTER) :
mkdir -p $( TOOLSDIR) /bin
2022-03-21 12:37:23 -05:00
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $( TOOLSDIR) /bin $( GOLINTER_VERSION)
2021-12-13 14:23:31 -05:00
$( GOLINTER) version
2023-12-08 03:05:02 -05:00
.PHONY : check -logs
check-logs :
@./scripts/check_logs.sh
2019-06-20 18:36:40 -05:00
.PHONY : check
2023-05-12 11:43:14 -05:00
check : $( if $ ( findstring ui ,$ ( BUILD_LABELS ) ) , ui )
2021-12-13 14:23:31 -05:00
check : ./golangcilint .yaml $( GOLINTER )
2023-02-10 17:52:54 -05:00
mkdir -p pkg/extensions/build; touch pkg/extensions/build/.empty
2022-04-27 01:00:20 -05:00
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags containers_image_openpgp ./...
2023-09-28 13:59:52 -05:00
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags $( BUILD_LABELS) ,containers_image_openpgp ./...
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags debug ./pkg/debug/swagger/ ./pkg/debug/gqlplayground
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags dev ./pkg/test/inject/
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags stress ./pkg/cli/server/
2023-02-10 17:52:54 -05:00
rm pkg/extensions/build/.empty
2019-06-20 18:36:40 -05:00
2023-08-15 15:07:56 -05:00
.PHONY : swagger
swagger :
2023-06-01 18:53:50 -05:00
swag -v || go install github.com/swaggo/swag/cmd/swag@$( SWAGGER_VERSION)
2023-06-12 12:32:11 -05:00
swag init --parseDependency -o swagger -g pkg/api/routes.go -q
2019-06-20 18:36:40 -05:00
2020-12-03 14:33:38 -05:00
.PHONY : update -licenses
2023-10-09 22:23:51 -05:00
# note: for predictable output of below sort command we use locale LC_ALL=C
2023-10-16 03:51:00 -05:00
update-licenses : check -linux
2022-01-24 12:31:39 -05:00
@echo "Detecting and updating licenses ... please be patient!"
go install github.com/google/go-licenses@latest
2024-02-07 13:54:28 -05:00
./scripts/update_licenses.sh
2023-10-09 22:23:51 -05:00
$( eval UNCOMMITED_FILES = $( shell git status --porcelain | grep -c THIRD-PARTY-LICENSES.md) )
@if [ $( UNCOMMITED_FILES) != 0 ] ; then \
echo "THIRD-PARTY-LICENSES.md file needs to be updated" ; \
git status; \
exit 1; \
fi
2022-01-24 12:31:39 -05:00
.PHONY : check -licenses
check-licenses :
2023-09-28 13:59:52 -05:00
# note: "printf" works for darwin instead of "echo -n"
2022-01-24 12:31:39 -05:00
go install github.com/google/go-licenses@latest
2023-09-28 13:59:52 -05:00
@for tag in " $( BUILD_LABELS) ,containers_image_openpgp " "containers_image_openpgp" ; do \
2022-01-24 12:31:39 -05:00
echo Evaluating tag: $$ tag; \
for mod in $$ ( go list -m -f '{{if not (or .Indirect .Main)}}{{.Path}}{{end}}' all) ; do \
while [ x$$ mod != x ] ; do \
2023-09-28 13:59:52 -05:00
printf " Checking $$ mod ... " ; \
2022-01-24 12:31:39 -05:00
result = $$ ( GOFLAGS = " -tags= $$ {tag} " go-licenses check $$ mod 2>& 1) ; \
if [ $$ ? -eq 0 ] ; then \
echo OK; \
break; \
fi ; \
echo " $$ {result} " | grep -q "Forbidden" ; \
if [ $$ ? -eq 0 ] ; then \
echo FAIL; \
exit 1; \
fi ; \
2022-10-04 15:36:19 -05:00
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" ; \
2022-01-24 12:31:39 -05:00
if [ $$ ? -eq 0 ] ; then \
echo UNKNOWN; \
break; \
fi ; \
done ; \
done ; \
done
2020-12-03 14:33:38 -05:00
2019-06-20 18:36:40 -05:00
.PHONY : clean
clean :
2021-12-10 17:27:40 -05:00
rm -f bin/z*
2021-12-13 14:23:31 -05:00
rm -rf hack
2022-05-10 03:28:26 -05:00
rm -rf test/data/zot-test
rm -rf test/data/zot-cve-test
2023-05-31 16:37:46 -05:00
rm -rf test/data/zot-cve-java-test
2023-02-10 17:52:54 -05:00
rm -rf pkg/extensions/build
2019-06-20 18:36:40 -05:00
.PHONY : run
2023-10-27 12:40:12 -05:00
run : binary
2022-01-24 00:19:01 -05:00
./bin/zot-$( OS) -$( ARCH) serve examples/config-test.json
2019-08-14 14:35:51 -05:00
2022-01-07 07:58:02 -05:00
.PHONY : verify -config
2022-03-30 08:02:03 -05:00
verify-config : _verify -config verify -config -warnings verify -config -commited
.PHONY : _verify -config
_verify-config : binary
2023-08-15 15:07:56 -05:00
rm -f output.txt
2024-03-21 12:23:37 -05:00
$( foreach file, $( filter-out examples/config-ldap-credentials.json, $( wildcard examples/config-*) ) , ./bin/zot-$( OS) -$( ARCH) verify $( file) 2>& 1 | tee -a output.txt || exit 1; )
2022-03-30 08:02:03 -05:00
.PHONY : verify -config -warnings
verify-config-warnings : _verify -config
$( eval WARNINGS = $( shell cat output.txt | grep -c '"warn"' ) )
$( eval ERRORS = $( shell cat output.txt | grep -c '"error"' ) )
@if [ $( WARNINGS) != 0 ] || [ $( ERRORS) != 0 ] ; then \
echo "verify-config-warnings: warnings or errors found while verifying configs" ; \
rm output.txt; \
exit 1; \
fi
rm -f output.txt
.PHONY : verify -config -commited
verify-config-commited : _verify -config
$( eval UNCOMMITED_FILES = $( shell git status --porcelain | grep -c examples/config-) )
@if [ $( UNCOMMITED_FILES) != 0 ] ; then \
echo "Uncommited config files, make sure all config files are commited. Verify might have changed a config file." ; \
exit 1; \
fi ; \
2022-01-07 07:58:02 -05:00
2022-07-15 06:10:51 -05:00
.PHONY : gqlgen
gqlgen :
cd pkg/extensions/search; \
go run github.com/99designs/gqlgen version; \
go run github.com/99designs/gqlgen generate
.PHONY : verify -gql -committed
verify-gql-committed :
$( eval UNCOMMITED_FILES = $( shell git status --porcelain | grep -c extensions/search) )
@if [ $( UNCOMMITED_FILES) != 0 ] ; then \
echo "Updated gql files uncommitted, make sure all gql files are committed:" ; \
git status; \
exit 1; \
fi ; \
2019-08-14 14:35:51 -05:00
.PHONY : binary -container
binary-container :
2022-11-10 15:09:39 -05:00
${ CONTAINER_RUNTIME } build ${ BUILD_ARGS } -f build/Dockerfile -t zot-build:latest .
2020-11-05 20:39:14 -05:00
.PHONY : run -container
run-container :
2021-12-03 22:50:58 -05:00
${ CONTAINER_RUNTIME } run --rm --security-opt label = disable -v $$ ( pwd ) :/go/src/github.com/project-zot/zot \
2023-08-15 15:07:56 -05:00
zot-build:latest
2019-08-14 18:26:25 -05:00
2023-10-16 03:51:00 -05:00
.PHONY : binary -minimal -container
binary-minimal-container :
${ CONTAINER_RUNTIME } build ${ BUILD_ARGS } -f build/Dockerfile-minimal -t zot-minimal:latest .
.PHONY : run -minimal -container
run-minimal-container :
${ CONTAINER_RUNTIME } run --rm --security-opt label = disable -v $$ ( pwd ) :/go/src/github.com/project-zot/zot \
zot-minimal:latest
.PHONY : binary -exporter -container
binary-exporter-container :
${ CONTAINER_RUNTIME } build ${ BUILD_ARGS } -f build/Dockerfile-zxp -t zxp:latest .
.PHONY : run -exporter -container
run-exporter-container :
${ CONTAINER_RUNTIME } run --rm --security-opt label = disable zxp:latest
2023-10-04 11:12:56 -05:00
.PHONY : oci -image
oci-image : $( STACKER )
2023-02-10 17:52:54 -05:00
${ STACKER } --debug build \
2022-11-10 15:09:39 -05:00
-f build/stacker.yaml \
2023-08-10 14:39:56 -05:00
--substitute COMMIT = $( COMMIT) \
--substitute ARCH = $( ARCH) \
--substitute OS = $( OS) \
--substitute RELEASE_TAG = $( RELEASE_TAG) \
--substitute REPO_NAME = zot-$( OS) -$( ARCH)
2020-01-24 12:54:38 -05:00
2023-10-04 11:12:56 -05:00
.PHONY : docker -image
docker-image :
${ CONTAINER_RUNTIME } buildx build --platform $( OS) /$( ARCH) -f build/Dockerfile .
2022-03-22 17:13:10 -05:00
$(BATS) :
rm -rf bats-core; \
git clone https://github.com/bats-core/bats-core.git; \
cd bats-core; ./install.sh $( TOOLSDIR) ; cd ..; \
rm -rf bats-core
2023-09-07 13:06:21 -05:00
.PHONY : check -blackbox -prerequisites
check-blackbox-prerequisites : check -linux check -skopeo $( BATS ) $( REGCLIENT ) $( ORAS ) $( HELM ) $( CRICTL ) $( NOTATION ) $( COSIGN ) $( STACKER )
which skopeo && skopeo --version; \
which stacker && stacker --version; \
which regctl && regctl version; \
which oras && oras version; \
which helm && helm version; \
which crictl && crictl version; \
which notation && notation version; \
which cosign && cosign version;
.PHONY : run -blackbox -tests
run-blackbox-tests : $( BATS_TEST_FILE_PATH ) check -blackbox -prerequisites binary binary -minimal cli bench
echo running bats test " $( BATS_TEST_FILE_PATH) " ; \
$( BATS) $( BATS_FLAGS) $( BATS_TEST_FILE_PATH)
2024-05-20 11:05:21 -05:00
.PHONY : run -cloud -scale -out -tests
run-cloud-scale-out-tests : check -blackbox -prerequisites check -awslocal binary bench test -prereq
echo running scale out bats test; \
$( BATS) $( BATS_FLAGS) test/scale-out/cloud_scale_out_no_auth.bats; \
$( BATS) $( BATS_FLAGS) test/scale-out/cloud_scale_out_basic_auth_tls.bats
.PHONY : run -cloud -scale -out -high -scale -tests
run-cloud-scale-out-high-scale-tests : check -blackbox -prerequisites check -awslocal binary bench test -prereq
echo running cloud scale out bats high scale test; \
$( BATS) $( BATS_FLAGS) test/scale-out/cloud_scale_out_basic_auth_tls_scale.bats
2023-09-07 13:06:21 -05:00
.PHONY : run -blackbox -ci
run-blackbox-ci : check -blackbox -prerequisites binary binary -minimal cli
2023-11-15 13:44:31 -05:00
echo running CI bats tests concurently
BATS_FLAGS = " $( BATS_FLAGS) " test/blackbox/ci.sh
2023-09-07 13:06:21 -05:00
.PHONY : run -blackbox -cloud -ci
run-blackbox-cloud-ci : check -blackbox -prerequisites check -awslocal binary $( BATS )
echo running cloud CI bats tests; \
$( BATS) $( BATS_FLAGS) test/blackbox/cloud_only.bats
2023-11-28 15:08:15 -05:00
$( BATS) $( BATS_FLAGS) test/blackbox/sync_cloud.bats
2023-09-07 13:06:21 -05:00
.PHONY : run -blackbox -dedupe -nightly
run-blackbox-dedupe-nightly : check -blackbox -prerequisites check -awslocal binary binary -minimal
echo running nightly dedupe tests; \
$( BATS) $( BATS_FLAGS) test/blackbox/restore_s3_blobs.bats && \
$( BATS) $( BATS_FLAGS) test/blackbox/pushpull_running_dedupe.bats
.PHONY : run -blackbox -sync -nightly
run-blackbox-sync-nightly : check -blackbox -prerequisites binary binary -minimal bench
echo running nightly sync tests; \
$( BATS) $( BATS_FLAGS) test/blackbox/sync_harness.bats
2022-11-18 12:35:28 -05:00
2022-07-27 12:37:55 -05:00
.PHONY : fuzz -all
fuzz-all : fuzztime =${1}
fuzz-all :
rm -rf test-data; \
rm -rf pkg/storage/testdata; \
git clone https://github.com/project-zot/test-data.git; \
mv test-data/storage pkg/storage/testdata; \
rm -rf test-data; \
bash test/scripts/fuzzAll.sh ${ fuzztime } ; \
rm -rf pkg/storage/testdata; \
2022-07-14 10:13:46 -05:00
2023-10-04 11:12:56 -05:00
$(STACKER) : check -linux
2022-10-18 22:47:41 -05:00
mkdir -p $( TOOLSDIR) /bin; \
curl -fsSL https://github.com/project-stacker/stacker/releases/latest/download/stacker -o $@ ; \
chmod +x $@
2022-11-01 11:16:14 -05:00
$(COSIGN) :
mkdir -p $( TOOLSDIR) /bin
2023-04-27 11:35:10 -05:00
curl -fsSL https://github.com/sigstore/cosign/releases/download/v$( COSIGN_VERSION) /cosign-linux-amd64 -o $@ ; \
2022-11-01 11:16:14 -05:00
chmod +x $@
2023-02-10 17:52:54 -05:00
2023-02-13 15:55:05 -05:00
# set ZUI_VERSION to empty string in order to clone zui locally and build default branch
2023-02-10 17:52:54 -05:00
.PHONY : ui
ui :
2023-05-12 11:43:14 -05:00
echo $( BUILD_LABELS) ; \
2023-12-07 08:02:29 -05:00
if [ -n $( ZUI_BUILD_PATH) ] ; then \
rm -rf ./pkg/extensions/build; \
cp -R $( ZUI_BUILD_PATH) ./pkg/extensions/; \
exit 0; \
fi ; \
2023-02-13 15:55:05 -05:00
if [ -z $( ZUI_VERSION) ] ; then \
pwd = $$ ( pwd ) ; \
tdir = $$ ( mktemp -d) ; \
cd $$ tdir; \
2023-11-13 12:57:51 -05:00
git clone https://github.com/$( ZUI_REPO_OWNER) /$( ZUI_REPO_NAME) .git zui; \
2023-02-13 15:55:05 -05:00
cd zui; \
npm install; \
npm run build; \
cd $$ pwd; \
rm -rf ./pkg/extensions/build; \
cp -R $$ tdir/zui/build ./pkg/extensions/; \
2023-02-10 17:52:54 -05:00
else \
2023-11-13 12:57:51 -05:00
curl --fail --head https://github.com/$( ZUI_REPO_OWNER) /$( ZUI_REPO_NAME) /releases/download/$( ZUI_VERSION) /zui.tgz; \
2023-03-30 05:15:48 -05:00
if [ $$ ? -ne 0 ] ; then \
pwd = $$ ( pwd ) ; \
tdir = $$ ( mktemp -d) ; \
cd $$ tdir; \
2023-11-13 12:57:51 -05:00
git clone --depth= 1 --branch $( ZUI_VERSION) https://github.com/$( ZUI_REPO_OWNER) /$( ZUI_REPO_NAME) .git zui; \
2023-03-30 05:15:48 -05:00
cd zui; \
git checkout $( ZUI_VERSION) ; \
npm install; \
npm run build; \
cd $$ pwd; \
rm -rf ./pkg/extensions/build; \
cp -R $$ tdir/zui/build ./pkg/extensions/; \
else \
2023-11-13 12:57:51 -05:00
curl -fsSL https://github.com/$( ZUI_REPO_OWNER) /$( ZUI_REPO_NAME) /releases/download/$( ZUI_VERSION) /zui.tgz -o zui.tgz; \
2023-03-30 05:15:48 -05:00
tar xvzf zui.tgz -C ./pkg/extensions/; \
rm zui.tgz; \
fi ; \
2023-02-10 17:52:54 -05:00
fi ; \
2023-02-13 15:55:05 -05:00
2023-08-30 14:24:28 -05:00
.PHONY : check -linux
check-linux :
i f n e q ( $( shell go env GOOS ) , l i n u x )
$( error makefile target can be run only on linux)
e n d i f
2023-09-28 13:59:52 -05:00
2023-10-30 15:06:04 -05:00
.PHONY : check -not -freebds
check-not-freebds :
2023-11-01 11:16:18 -05:00
i f e q ( $( shell go env GOOS ) , f r e e b s d )
$( error makefile target can' t be run on freebsd)
2023-10-30 15:06:04 -05:00
e n d i f
2023-09-28 13:59:52 -05:00
.PHONY : check -compatibility
check-compatibility :
i f e q ( $( OS ) , f r e e b s d )
$( error makefile target can' t be run on freebsd)
e n d i f
i f n e q ( $( OS ) , $( shell go env GOOS ) )
$( error target can' t be run on $( shell go env GOOS) as binary is compiled for $( OS) )
e n d i f
i f n e q ( $( ARCH ) , $( shell go env GOARCH ) )
$( error target can' t be run on $( shell go env GOARCH) ( binary is for $( ARCH) ) )
e n d i f