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
|
|
|
|
2023-09-26 13:41:42 +00:00
|
|
|
# default compose command
|
2023-09-26 13:44:10 +00:00
|
|
|
COMPOSE ?= docker compose
|
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)",)
|
2023-12-19 18:02:44 +00:00
|
|
|
GO_LDFLAGS=-ldflags '-extldflags "-Wl,-z,now" -s -w -X $(PKG)/version.version=$(VERSION) -X $(PKG)/version.revision=$(REVISION) -X $(PKG)/version.mainpkg=$(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-12-24 10:37:38 +00:00
|
|
|
.PHONY: all build binaries clean test test-race test-full integration test-coverage validate lint validate-git validate-vendor vendor mod-outdated image validate-authors authors
|
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 $@
|
|
|
|
|
2023-12-24 10:37:38 +00:00
|
|
|
authors: ## generate authors
|
|
|
|
docker buildx bake $@
|
|
|
|
|
2023-08-25 19:02:37 +00:00
|
|
|
##@ 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}
|
|
|
|
|
2023-10-23 13:52:57 +00:00
|
|
|
test-coverage: ## run unit tests and generate test coverprofiles
|
2018-08-01 22:37:21 +00:00
|
|
|
@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)
|
2023-09-26 13:17:48 +00:00
|
|
|
$(COMPOSE) -f tests/docker-compose-storage.yml up minio minio-init -d
|
2023-09-25 22:42:46 +00:00
|
|
|
|
|
|
|
.PHONY: stop-cloud-storage
|
|
|
|
stop-cloud-storage: ## stop local cloud storage (minio)
|
2023-09-26 13:41:42 +00:00
|
|
|
$(COMPOSE) -f tests/docker-compose-storage.yml down
|
2023-09-25 22:42:46 +00:00
|
|
|
|
|
|
|
.PHONY: reset-cloud-storage
|
|
|
|
reset-cloud-storage: ## reset (stop, delete, start) local cloud storage (minio)
|
2023-09-26 13:41:42 +00:00
|
|
|
$(COMPOSE) -f tests/docker-compose-storage.yml down
|
2023-09-25 22:42:46 +00:00
|
|
|
@mkdir -p tests/miniodata/distribution
|
|
|
|
@rm -rf tests/miniodata/distribution/* tests/miniodata/.minio.sys
|
2023-09-26 13:41:42 +00:00
|
|
|
$(COMPOSE) -f tests/docker-compose-storage.yml up minio minio-init -d
|
2023-09-25 22:42:46 +00:00
|
|
|
|
|
|
|
.PHONY: run-s3-tests
|
2023-09-26 16:24:04 +00:00
|
|
|
run-s3-tests: start-cloud-storage ## run S3 storage driver integration tests
|
2023-09-25 22:42:46 +00:00
|
|
|
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 \
|
2023-09-26 13:21:56 +00:00
|
|
|
S3_ACCELERATE=false \
|
|
|
|
AWS_S3_FORCE_PATH_STYLE=true \
|
2023-09-26 13:17:28 +00:00
|
|
|
go test ${TESTFLAGS} -count=1 ./registry/storage/driver/s3-aws/...
|
2023-09-25 22:42:46 +00:00
|
|
|
|
2023-10-23 13:52:57 +00:00
|
|
|
.PHONY: start-e2e-s3-env
|
|
|
|
start-e2e-s3-env: ## starts E2E S3 storage test environment (S3, Redis, registry)
|
|
|
|
$(COMPOSE) -f tests/docker-compose-e2e-cloud-storage.yml up -d
|
|
|
|
|
|
|
|
.PHONY: stop-e2e-s3-env
|
|
|
|
stop-e2e-s3-env: ## stops E2E S3 storage test environment (S3, Redis, registry)
|
|
|
|
$(COMPOSE) -f tests/docker-compose-e2e-cloud-storage.yml down
|
|
|
|
|
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-12-24 10:37:38 +00:00
|
|
|
validate-authors: ## validate authors
|
|
|
|
docker buildx bake $@
|
|
|
|
|
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)"
|