2019-06-21 02:36:40 +03:00
export GO111MODULE = on
2019-07-21 03:30:58 +03:00
TOP_LEVEL = $( shell git rev-parse --show-toplevel)
2019-09-16 21:01:59 +03:00
COMMIT_HASH = $( shell git describe --always --tags --long)
2021-10-15 18:05:00 +03:00
GO_VERSION = $( shell go version | awk '{print $$3}' )
2021-12-16 01:47:53 +03:00
COMMIT ?= $( if $( shell git status --porcelain --untracked-files= no) ,$( COMMIT_HASH) -dirty,$( COMMIT_HASH) )
2019-08-14 22:35:51 +03:00
CONTAINER_RUNTIME := $( shell command -v podman 2> /dev/null || echo docker)
2020-07-09 10:10:11 +03:00
TMPDIR := $( shell mktemp -d)
2022-03-23 01:13:10 +03:00
TOOLSDIR := $( shell pwd ) /hack/tools
PATH := bin:$( TOOLSDIR) /bin:$( PATH)
2020-11-06 04:57:06 +03:00
STACKER := $( shell which stacker)
2021-12-13 22:23:31 +03:00
GOLINTER := $( TOOLSDIR) /bin/golangci-lint
2021-12-07 16:07:22 +03:00
NOTATION := $( TOOLSDIR) /bin/notation
2022-03-23 01:13:10 +03:00
BATS := $( TOOLSDIR) /bin/bats
2021-12-03 20:42:03 +03:00
OS ?= linux
ARCH ?= amd64
2022-01-14 01:06:35 +03:00
BENCH_OUTPUT ?= stdout
2019-06-21 02:36:40 +03:00
.PHONY : all
2022-03-03 00:20:35 +03:00
all : modcheck swagger binary binary -minimal binary -debug cli bench exporter -minimal verify -config test covhtml test -clean check
.PHONY : modcheck
modcheck :
go mod tidy
2022-01-24 08:19:01 +03:00
.PHONY : binary -debug
2022-03-03 00:20:35 +03:00
binary-debug : modcheck swagger
2022-02-17 01:03:03 +03:00
env CGO_ENABLED = 0 GOOS = $( OS) GOARCH = $( ARCH) go build -o bin/zot-$( OS) -$( ARCH) -debug -buildmode= pie -tags extended,containers_image_openpgp -v -gcflags all = '-N -l' -ldflags " -X zotregistry.io/zot/pkg/api/config.Commit= ${ COMMIT } -X zotregistry.io/zot/pkg/api/config.BinaryType=extended -X zotregistry.io/zot/pkg/api/config.GoVersion= ${ GO_VERSION } " ./cmd/zot
2020-10-15 00:47:20 +03:00
.PHONY : binary -minimal
2022-03-03 00:20:35 +03:00
binary-minimal : modcheck swagger
2022-02-17 01:03:03 +03:00
env CGO_ENABLED = 0 GOOS = $( OS) GOARCH = $( ARCH) go build -o bin/zot-$( OS) -$( ARCH) -minimal -buildmode= pie -tags minimal,containers_image_openpgp -v -trimpath -ldflags " -X zotregistry.io/zot/pkg/api/config.Commit= ${ COMMIT } -X zotregistry.io/zot/pkg/api/config.BinaryType=minimal -X zotregistry.io/zot/pkg/api/config.GoVersion= ${ GO_VERSION } -s -w " ./cmd/zot
2019-06-21 02:36:40 +03:00
.PHONY : binary
2022-03-03 00:20:35 +03:00
binary : modcheck swagger
2022-02-17 01:03:03 +03:00
env CGO_ENABLED = 0 GOOS = $( OS) GOARCH = $( ARCH) go build -o bin/zot-$( OS) -$( ARCH) -buildmode= pie -tags extended,containers_image_openpgp -v -trimpath -ldflags " -X zotregistry.io/zot/pkg/api/config.Commit= ${ COMMIT } -X zotregistry.io/zot/pkg/api/config.BinaryType=extended -X zotregistry.io/zot/pkg/api/config.GoVersion= ${ GO_VERSION } -s -w " ./cmd/zot
2021-12-16 01:14:53 +03:00
2022-01-11 04:15:35 +03:00
.PHONY : cli
2022-03-03 00:20:35 +03:00
cli : modcheck
2022-02-17 01:03:03 +03:00
env CGO_ENABLED = 0 GOOS = $( OS) GOARCH = $( ARCH) go build -o bin/zli-$( OS) -$( ARCH) -buildmode= pie -tags extended,containers_image_openpgp -v -trimpath -ldflags " -X zotregistry.io/zot/pkg/api/config.Commit= ${ COMMIT } -X zotregistry.io/zot/pkg/api/config.BinaryType=extended -X zotregistry.io/zot/pkg/api/config.GoVersion= ${ GO_VERSION } -s -w " ./cmd/zli
2022-01-11 04:15:35 +03:00
2021-12-11 01:27:40 +03:00
.PHONY : bench
2022-03-03 00:20:35 +03:00
bench : modcheck
2022-02-17 01:03:03 +03:00
env CGO_ENABLED = 0 GOOS = $( OS) GOARCH = $( ARCH) go build -o bin/zb-$( OS) -$( ARCH) -buildmode= pie -tags extended,containers_image_openpgp -v -trimpath -ldflags " -X zotregistry.io/zot/pkg/api/config.Commit= ${ COMMIT } -X zotregistry.io/zot/pkg/api/config.BinaryType=extended -X zotregistry.io/zot/pkg/api/config.GoVersion= ${ GO_VERSION } -s -w " ./cmd/zb
2021-12-11 01:27:40 +03:00
2021-10-15 18:05:00 +03:00
.PHONY : exporter -minimal
2022-03-03 00:20:35 +03:00
exporter-minimal : modcheck
2022-02-17 01:03:03 +03:00
env CGO_ENABLED = 0 GOOS = $( OS) GOARCH = $( ARCH) go build -o bin/zxp-$( OS) -$( ARCH) -buildmode= pie -tags minimal,containers_image_openpgp -v -trimpath ./cmd/zxp
2019-06-21 02:36:40 +03:00
.PHONY : test
2021-12-07 16:07:22 +03:00
test : check -skopeo $( NOTATION )
2022-03-07 12:58:28 +03:00
$( shell mkdir -p test/data; cd test/data; ../scripts/gen_certs.sh; cd ${ TOP_LEVEL } ; skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:7 oci:${ TOP_LEVEL } /test/data/zot-test:0.0.1; skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:8 oci:${ TOP_LEVEL } /test/data/zot-cve-test:0.0.1)
2021-12-07 16:07:22 +03:00
$( shell sudo mkdir -p /etc/containers/certs.d/127.0.0.1:8089/; sudo cp test/data/client.* test/data/ca.* /etc/containers/certs.d/127.0.0.1:8089/; )
2021-07-06 19:50:46 +03:00
$( shell sudo chmod a = rwx /etc/containers/certs.d/127.0.0.1:8089/*.key)
2021-11-22 11:12:01 +03:00
go test -tags extended,containers_image_openpgp -v -trimpath -race -timeout 15m -cover -coverpkg ./... -coverprofile= coverage-extended.txt -covermode= atomic ./...
2021-10-15 18:05:00 +03:00
go test -tags minimal,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile= coverage-minimal.txt -covermode= atomic ./...
2021-12-21 07:18:13 +03:00
# development-mode unit tests possibly using failure injection
2022-01-23 23:26:02 +03:00
go test -tags dev,extended,containers_image_openpgp -v -trimpath -race -timeout 15m -cover -coverpkg ./... -coverprofile= coverage-dev-extended.txt -covermode= atomic ./pkg/test/... ./pkg/api/... ./pkg/storage/... ./pkg/extensions/sync/... -run ^TestInject
2022-02-18 14:36:50 +03:00
go test -tags dev,minimal,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile= coverage-dev-minimal.txt -covermode= atomic ./pkg/test/... ./pkg/storage/... ./pkg/extensions/sync/... -run ^TestInject
2022-01-23 23:26:02 +03:00
go test -tags stress,extended,containers_image_openpgp -v -trimpath -race -timeout 15m ./pkg/cli/stress_test.go
2019-06-21 02:36:40 +03:00
2022-01-14 01:06:35 +03:00
.PHONY : run -bench
run-bench : binary bench
2022-03-24 20:52:39 +03:00
bin/zot-$( OS) -$( ARCH) serve examples/config-bench.json &
2022-01-14 01:06:35 +03:00
sleep 5
2022-01-24 08:19:01 +03:00
bin/zb-$( OS) -$( ARCH) -c 10 -n 100 -o $( BENCH_OUTPUT) http://localhost:8080
killall -r zot-*
2022-01-14 01:06:35 +03:00
2021-07-06 19:50:46 +03:00
.PHONY : test -clean
test-clean :
$( shell sudo rm -rf /etc/containers/certs.d/127.0.0.1:8089/)
2021-12-07 16:07:22 +03:00
.PHONY : check -skopeo
check-skopeo :
skopeo -v || ( echo "You need skopeo to be installed in order to run tests" ; exit 1)
$(NOTATION) :
mkdir -p $( TOOLSDIR) /bin
curl -Lo notation.tar.gz https://github.com/notaryproject/notation/releases/download/v0.7.1-alpha.1/notation_0.7.1-alpha.1_linux_amd64.tar.gz
tar xvzf notation.tar.gz -C $( TOOLSDIR) /bin notation
rm notation.tar.gz
2020-01-25 00:32:38 +03:00
.PHONY : covhtml
covhtml :
2021-12-21 07:18:13 +03:00
go install github.com/wadey/gocovmerge@latest
gocovmerge coverage-minimal.txt coverage-extended.txt coverage-dev-minimal.txt coverage-dev-extended.txt > coverage.txt
2020-01-25 00:32:38 +03:00
go tool cover -html= coverage.txt -o coverage.html
2021-12-13 22:23:31 +03:00
$(GOLINTER) :
mkdir -p $( TOOLSDIR) /bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $( TOOLSDIR) /bin v1.43.0
$( GOLINTER) version
2019-06-21 02:36:40 +03:00
.PHONY : check
2021-12-13 22:23:31 +03:00
check : ./golangcilint .yaml $( GOLINTER )
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags minimal,containers_image_openpgp ./...
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags extended,containers_image_openpgp ./...
2021-12-21 07:18:13 +03:00
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags dev,minimal,containers_image_openpgp ./...
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags dev,extended,containers_image_openpgp ./...
2022-01-23 23:26:02 +03:00
$( GOLINTER) --config ./golangcilint.yaml run --enable-all --out-format= colored-line-number --build-tags stress,extended,containers_image_openpgp ./...
2019-06-21 02:36:40 +03:00
2021-10-21 00:01:06 +03:00
swagger/docs.go :
2019-09-03 23:21:05 +03:00
swag -v || go install github.com/swaggo/swag/cmd/swag
2021-10-21 00:01:06 +03:00
swag init -o swagger -g pkg/api/routes.go
2019-06-21 02:36:40 +03:00
2021-10-21 00:01:06 +03:00
.PHONY : swagger
swagger : swagger /docs .go
2019-08-29 01:58:00 +03:00
2020-12-03 22:33:38 +03:00
.PHONY : update -licenses
update-licenses :
2022-01-24 20:31:39 +03:00
@echo "Detecting and updating licenses ... please be patient!"
go install github.com/google/go-licenses@latest
$( shell echo "Module | License URL | License" > THIRD-PARTY-LICENSES.md; echo "---|---|---" >> THIRD-PARTY-LICENSES.md; for i in $$ ( go list -m all | awk '{print $$1}' ) ; do l = $$ ( go-licenses csv $$ i 2>/dev/null) ; if [ $$ ? -ne 0 ] ; then continue ; fi ; echo $$ l | tr \, \| | tr ' ' '\n' ; done | sort -u >> THIRD-PARTY-LICENSES.md)
.PHONY : check -licenses
check-licenses :
go install github.com/google/go-licenses@latest
@for tag in "extended,containers_image_openpgp" "minimal,containers_image_openpgp" ; do \
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 \
echo -n " Checking $$ mod ... " ; \
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 ; \
echo " $$ {result} " | egrep -q "missing go.sum entry|no required module provides package|build constraints exclude all|updates to go.mod needed" ; \
if [ $$ ? -eq 0 ] ; then \
echo UNKNOWN; \
break; \
fi ; \
done ; \
done ; \
done
2020-12-03 22:33:38 +03:00
2019-06-21 02:36:40 +03:00
.PHONY : clean
clean :
2021-12-11 01:27:40 +03:00
rm -f bin/z*
2021-12-13 22:23:31 +03:00
rm -rf hack
2019-06-21 02:36:40 +03:00
.PHONY : run
run : binary test
2022-01-24 08:19:01 +03:00
./bin/zot-$( OS) -$( ARCH) serve examples/config-test.json
2019-08-14 22:35:51 +03:00
2022-01-07 15:58:02 +03:00
.PHONY : verify -config
verify-config : binary
2022-02-09 08:01:00 +03:00
$( foreach file, $( wildcard examples/config-*) , ./bin/zot-$( OS) -$( ARCH) verify $( file) || exit 1; )
2022-01-07 15:58:02 +03:00
2019-08-14 22:35:51 +03:00
.PHONY : binary -container
binary-container :
2020-11-06 04:39:14 +03:00
${ CONTAINER_RUNTIME } build ${ BUILD_ARGS } -f Dockerfile -t zot-build:latest .
.PHONY : run -container
run-container :
2021-12-04 06:50:58 +03:00
${ CONTAINER_RUNTIME } run --rm --security-opt label = disable -v $$ ( pwd ) :/go/src/github.com/project-zot/zot \
2020-11-06 04:39:14 +03:00
zot-build:latest
2019-08-15 02:26:25 +03:00
.PHONY : binary -stacker
binary-stacker :
2020-11-06 04:57:06 +03:00
sudo ${ STACKER } build --substitute PWD = $$ PWD
2020-01-24 20:54:38 +03:00
.PHONY : image
image :
${ CONTAINER_RUNTIME } build ${ BUILD_ARGS } -f Dockerfile -t zot:latest .
2022-03-23 01:13:10 +03: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
.PHONY : push -pull
push-pull : binary check -skopeo $( BATS )
$( BATS) --trace --print-output-on-failure test/blackbox
.PHONY : push -pull -verbose
push-pull-verbose : binary check -skopeo $( BATS )
$( BATS) --trace --verbose-run --print-output-on-failure --show-output-of-passing-tests test/blackbox