2023-08-25 19:02:37 +00:00
|
|
|
.DEFAULT_GOAL := help
|
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
# Root directory of the project (absolute path).
|
|
|
|
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
2015-06-10 17:48:33 +00:00
|
|
|
|
2015-01-29 23:32:49 +00:00
|
|
|
# Used to populate version variable in main package.
|
2019-06-26 21:50:29 +00:00
|
|
|
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
|
|
|
|
REVISION ?= $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
|
2018-08-01 22:37:21 +00:00
|
|
|
|
|
|
|
|
2020-08-24 11:18:39 +00:00
|
|
|
PKG=github.com/distribution/distribution/v3
|
2018-08-01 22:37:21 +00:00
|
|
|
|
|
|
|
# Project packages.
|
|
|
|
PACKAGES=$(shell go list -tags "${BUILDTAGS}" ./... | grep -v /vendor/)
|
|
|
|
INTEGRATION_PACKAGE=${PKG}
|
|
|
|
COVERAGE_PACKAGES=$(filter-out ${PKG}/registry/storage/driver/%,${PACKAGES})
|
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
IMAGE_REPO ?= distribution/distribution
|
|
|
|
IMAGE_TAG ?= latest
|
|
|
|
IMAGE_NAME ?= $(IMAGE_REPO):$(IMAGE_TAG)
|
2018-08-01 22:37:21 +00:00
|
|
|
|
|
|
|
# Project binaries.
|
|
|
|
COMMANDS=registry digest registry-api-descriptor-template
|
2015-06-10 17:48:33 +00:00
|
|
|
|
|
|
|
# Allow turning off function inlining and variable registerization
|
|
|
|
ifeq (${DISABLE_OPTIMIZATION},true)
|
|
|
|
GO_GCFLAGS=-gcflags "-N -l"
|
|
|
|
VERSION:="$(VERSION)-noopt"
|
|
|
|
endif
|
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
WHALE = "+"
|
2016-03-18 21:07:13 +00:00
|
|
|
|
2016-10-11 00:30:47 +00:00
|
|
|
# Go files
|
2018-08-01 22:37:21 +00:00
|
|
|
#
|
|
|
|
TESTFLAGS_RACE=
|
2016-10-11 00:30:47 +00:00
|
|
|
GOFILES=$(shell find . -type f -name '*.go')
|
2018-08-01 22:37:21 +00:00
|
|
|
GO_TAGS=$(if $(BUILDTAGS),-tags "$(BUILDTAGS)",)
|
2022-04-02 02:07:42 +00:00
|
|
|
GO_LDFLAGS=-ldflags '-extldflags "-Wl,-z,now" -s -w -X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) $(EXTRA_LDFLAGS)'
|
2016-10-11 00:30:47 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
BINARIES=$(addprefix bin/,$(COMMANDS))
|
2016-03-18 21:07:13 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
# Flags passed to `go test`
|
|
|
|
TESTFLAGS ?= -v $(TESTFLAGS_RACE)
|
|
|
|
TESTFLAGS_PARALLEL ?= 8
|
2016-03-21 19:08:47 +00:00
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
.PHONY: all build binaries clean test test-race test-full integration coverage validate lint validate-git validate-vendor vendor mod-outdated image
|
2018-08-01 22:37:21 +00:00
|
|
|
.DEFAULT: all
|
2015-02-16 22:25:17 +00:00
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
.PHONY: FORCE
|
|
|
|
FORCE:
|
|
|
|
|
|
|
|
##@ Build
|
2015-02-07 01:49:50 +00:00
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
# This only needs to be generated by hand when cutting full releases.
|
|
|
|
version/version.go:
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
./version/version.sh > $@
|
2015-02-06 23:39:11 +00:00
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
bin/%: cmd/% FORCE ## build individual binary
|
|
|
|
@echo "$(WHALE) $@${BINARY_SUFFIX}"
|
|
|
|
@go build -buildmode=pie ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} --ldflags '-extldflags "-Wl,-z,now" -s' ${GO_TAGS} ./$<
|
|
|
|
|
|
|
|
binaries: $(BINARIES) ## build binaries
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
|
|
|
|
build: ## build go packages
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go build -buildmode=pie ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${GO_LDFLAGS} --ldflags '-extldflags "-Wl,-z,now" -s' ${GO_TAGS} $(PACKAGES)
|
|
|
|
|
|
|
|
image: ## build docker image IMAGE_NAME=<name>
|
|
|
|
docker buildx bake --set "*.tags=${IMAGE_NAME}" image-local
|
|
|
|
|
|
|
|
clean: ## clean up binaries
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@rm -f $(BINARIES)
|
|
|
|
|
|
|
|
vendor: ## update vendor
|
|
|
|
$(eval $@_TMP_OUT := $(shell mktemp -d -t buildx-output.XXXXXXXXXX))
|
|
|
|
docker buildx bake --set "*.output=$($@_TMP_OUT)" update-vendor
|
|
|
|
rm -rf ./vendor
|
|
|
|
cp -R "$($@_TMP_OUT)"/out/* .
|
|
|
|
rm -rf $($@_TMP_OUT)/*
|
|
|
|
|
|
|
|
mod-outdated: ## check outdated dependencies
|
|
|
|
docker buildx bake $@
|
|
|
|
|
|
|
|
##@ Test
|
|
|
|
|
2018-08-01 22:37:21 +00:00
|
|
|
test: ## run tests, except integration test with test.short
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go test ${GO_TAGS} -test.short ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
|
|
|
|
|
|
|
|
test-race: ## run tests, except integration test with test.short and race
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go test ${GO_TAGS} -race -test.short ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
|
|
|
|
|
|
|
|
test-full: ## run tests, except integration tests
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go test ${GO_TAGS} ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES})
|
|
|
|
|
|
|
|
integration: ## run integration tests
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@go test ${TESTFLAGS} -parallel ${TESTFLAGS_PARALLEL} ${INTEGRATION_PACKAGE}
|
|
|
|
|
|
|
|
coverage: ## generate coverprofiles from the unit tests
|
|
|
|
@echo "$(WHALE) $@"
|
|
|
|
@rm -f coverage.txt
|
|
|
|
@go test ${GO_TAGS} -i ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${COVERAGE_PACKAGES}) 2> /dev/null
|
|
|
|
@( for pkg in $(filter-out ${INTEGRATION_PACKAGE},${COVERAGE_PACKAGES}); do \
|
|
|
|
go test ${GO_TAGS} ${TESTFLAGS} \
|
|
|
|
-cover \
|
|
|
|
-coverprofile=profile.out \
|
|
|
|
-covermode=atomic $$pkg || exit; \
|
|
|
|
if [ -f profile.out ]; then \
|
|
|
|
cat profile.out >> coverage.txt; \
|
|
|
|
rm profile.out; \
|
|
|
|
fi; \
|
|
|
|
done )
|
|
|
|
|
2023-09-25 22:42:46 +00:00
|
|
|
.PHONY: test-cloud-storage
|
|
|
|
test-cloud-storage: start-cloud-storage run-s3-tests stop-cloud-storage ## run cloud storage driver tests
|
|
|
|
|
|
|
|
.PHONY: start-cloud-storage
|
|
|
|
start-cloud-storage: ## start local cloud storage (minio)
|
|
|
|
docker compose -f tests/docker-compose-storage.yml up minio minio-init -d
|
|
|
|
|
|
|
|
.PHONY: stop-cloud-storage
|
|
|
|
stop-cloud-storage: ## stop local cloud storage (minio)
|
|
|
|
docker compose -f tests/docker-compose-storage.yml down
|
|
|
|
|
|
|
|
.PHONY: reset-cloud-storage
|
|
|
|
reset-cloud-storage: ## reset (stop, delete, start) local cloud storage (minio)
|
|
|
|
docker compose -f tests/docker-compose-storage.yml down
|
|
|
|
@mkdir -p tests/miniodata/distribution
|
|
|
|
@rm -rf tests/miniodata/distribution/* tests/miniodata/.minio.sys
|
|
|
|
docker compose -f tests/docker-compose-storage.yml up minio minio-init -d
|
|
|
|
|
|
|
|
.PHONY: run-s3-tests
|
|
|
|
run-s3-tests: ## run S3 storage driver integration tests
|
|
|
|
AWS_ACCESS_KEY=distribution \
|
|
|
|
AWS_SECRET_KEY=password \
|
|
|
|
AWS_REGION=us-east-1 \
|
|
|
|
S3_BUCKET=images-local \
|
|
|
|
S3_ENCRYPT=false \
|
|
|
|
REGION_ENDPOINT=http://127.0.0.1:9000 \
|
|
|
|
S3_SECURE=false \
|
|
|
|
go test -v -count=1 ./registry/storage/driver/s3-aws/...
|
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
##@ Validate
|
2022-04-22 13:32:01 +00:00
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
lint: ## run all linters
|
2022-05-03 10:51:31 +00:00
|
|
|
docker buildx bake $@
|
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
validate: ## run all validators
|
2022-05-03 10:51:31 +00:00
|
|
|
docker buildx bake $@
|
|
|
|
|
2022-07-20 12:18:18 +00:00
|
|
|
validate-git: ## validate git
|
|
|
|
docker buildx bake $@
|
|
|
|
|
2022-04-22 13:32:01 +00:00
|
|
|
validate-vendor: ## validate vendor
|
2022-05-03 10:51:31 +00:00
|
|
|
docker buildx bake $@
|
2022-04-22 13:32:01 +00:00
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
.PHONY: help
|
|
|
|
help:
|
2023-09-25 22:42:46 +00:00
|
|
|
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z0-9_\/%-]+:.*?##/ { printf " \033[36m%-27s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
|
2023-08-25 19:02:37 +00:00
|
|
|
@echo ""
|
2023-08-28 10:19:01 +00:00
|
|
|
@echo "Go binaries: $(BINARIES)"
|
2023-08-25 19:02:37 +00:00
|
|
|
@echo "Docker image: $(IMAGE_NAME)"
|