From 797b1e392751608b03d1d17083fd04a52712dbed Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Mon, 25 Sep 2023 23:42:46 +0100 Subject: [PATCH 01/12] Add make targets to allow starting local cloud storage environment. Requirements: * docker deamon * docker compose installed Signed-off-by: Milos Gajdos --- .gitignore | 2 ++ BUILDING.md | 34 ++++++++++++++++++++++++---- Makefile | 31 +++++++++++++++++++++++++- README.md | 2 -- cmd/registry/config-dev.yml | 2 +- tests/conf-local-cloud.yml | 38 ++++++++++++++++++++++++++++++++ tests/docker-compose-storage.yml | 31 ++++++++++++++++++++++++++ 7 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 tests/conf-local-cloud.yml create mode 100644 tests/docker-compose-storage.yml diff --git a/.gitignore b/.gitignore index 4cf7888e92..dcda068a68 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ bin/* *.sublime-project *.sublime-workspace .idea/* + +tests/miniodata diff --git a/BUILDING.md b/BUILDING.md index 75487bbc11..a80f1da542 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -11,13 +11,13 @@ Most people should use the [official Registry docker image](https://hub.docker.c People looking for advanced operational use cases might consider rolling their own image with a custom Dockerfile inheriting `FROM registry:2`. -OS X users who want to run natively can do so following [the instructions here](https://github.com/docker/docker.github.io/blob/master/registry/recipes/osx-setup-guide.md). +The latest updates to `main` branch are automatically pushed to [distribution Docker Hub repository](https://hub.docker.com/r/distribution/distribution) with `edge` tag. ### Gotchas -You are expected to know your way around with go & git. +You are expected to know your way around with `Go` & `git`. -If you are a casual user with no development experience, and no preliminary knowledge of go, building from source is probably not a good solution for you. +If you are a casual user with no development experience, and no preliminary knowledge of `Go`, building from source is probably not a good solution for you. ## Configure the development environment @@ -31,7 +31,7 @@ Next, fetch the code from the repository using git: git clone https://github.com/distribution/distribution cd distribution -If you are planning to create a pull request with changes, you may want to clone directly from your [fork](https://help.github.com/en/articles/about-forks). +If you are planning to create a pull request with changes, you may want to clone directly from your [fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks). ## Build and run from source @@ -105,3 +105,29 @@ the environment variable `BUILDTAGS`.
include_gcs
Adds support for Google Cloud Storage
+ +### Local cloud storage environment + +You can run an S3 API compatible storage locally with [minio](https://min.io/). + +You must have [docker compose](https://docs.docker.com/compose/) installed on your workstation. + +Start the local cloud environment: +``` +make start-cloud-storage +``` +There is a sample registry configuration file that lets you point the registry to the started storage: +``` +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 \ +./bin/registry serve tests/conf-local-cloud.yml +``` +Stop the local storage when done: +``` +make stop-cloud-storage +``` diff --git a/Makefile b/Makefile index d2059afe9c..84338fe9ef 100644 --- a/Makefile +++ b/Makefile @@ -117,6 +117,35 @@ coverage: ## generate coverprofiles from the unit tests fi; \ done ) +.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/... + ##@ Validate lint: ## run all linters @@ -133,7 +162,7 @@ validate-vendor: ## validate vendor .PHONY: help help: - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_\/%-]+:.*?##/ { printf " \033[36m%-27s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + @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) @echo "" @echo "Go binaries: $(BINARIES)" @echo "Docker image: $(IMAGE_NAME)" diff --git a/README.md b/README.md index 9654b7978e..01c3da29dd 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ [![OCI Conformance](https://github.com/distribution/distribution/workflows/conformance/badge.svg)](https://github.com/distribution/distribution/actions?query=workflow%3Aconformance) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/distribution/distribution/badge)](https://securityscorecards.dev/viewer/?uri=github.com/distribution/distribution) - - The toolset to pack, ship, store, and deliver content. This repository's main product is the Open Source Registry implementation diff --git a/cmd/registry/config-dev.yml b/cmd/registry/config-dev.yml index 8acf92ea2d..985892b144 100644 --- a/cmd/registry/config-dev.yml +++ b/cmd/registry/config-dev.yml @@ -63,7 +63,7 @@ notifications: timeout: 1s threshold: 10 backoff: 1s - disabled: true + disabled: true health: storagedriver: enabled: true diff --git a/tests/conf-local-cloud.yml b/tests/conf-local-cloud.yml new file mode 100644 index 0000000000..5e82f8cf32 --- /dev/null +++ b/tests/conf-local-cloud.yml @@ -0,0 +1,38 @@ +version: 0.1 +http: + addr: :5000 + debug: + addr: :5001 + prometheus: + enabled: true + path: /metrics + draintimeout: 5s + secret: hmacsecret +log: + accesslog: + disabled: false + fields: + environment: local + service: registry + formatter: text + level: debug +storage: + delete: + enabled: true + cache: + blobdescriptor: inmemory + maintenance: + uploadpurging: + enabled: false + s3: + region: us-east-1 + accesskey: distribution + secretkey: password + bucket: images-local + rootdirectory: /registry-v2 + regionendpoint: http://127.0.0.1:9000 + encrypt: false + secure: false + chunksize: 33554432 + secure: true + v4auth: true diff --git a/tests/docker-compose-storage.yml b/tests/docker-compose-storage.yml new file mode 100644 index 0000000000..b420fa815f --- /dev/null +++ b/tests/docker-compose-storage.yml @@ -0,0 +1,31 @@ +services: + minio: + image: minio/minio:RELEASE.2023-09-20T22-49-55Z + command: server /data --console-address ":9001" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 5s + timeout: 5s + retries: 10 + ports: + - "9000:9000" + - "9001:9001" + environment: + MINIO_ROOT_USER: distribution + MINIO_ROOT_PASSWORD: password + volumes: + - ./miniodata/distribution:/data + + minio-init: + image: minio/mc:RELEASE.2023-02-16T19-20-11Z + depends_on: + minio: + condition: service_healthy + entrypoint: > + /bin/bash -c " + /usr/bin/mc config host add minio http://minio:9000 $${MINIO_ROOT_USER} $${MINIO_ROOT_PASSWORD} && ( + /usr/bin/mc stat minio/images-local || /usr/bin/mc mb minio/images-local + ) && /usr/bin/mc anonymous set public minio/images-local && /usr/bin/mc admin trace --path " + environment: + MINIO_ROOT_USER: distribution + MINIO_ROOT_PASSWORD: password From 6b0c391865feeb5be5ad0ae50b53442ad624e38d Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:17:28 +0100 Subject: [PATCH 02/12] Update Makefile Co-authored-by: James Hewitt Signed-off-by: Milos Gajdos --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 84338fe9ef..de9b1dd230 100644 --- a/Makefile +++ b/Makefile @@ -144,7 +144,7 @@ run-s3-tests: ## run S3 storage driver integration tests S3_ENCRYPT=false \ REGION_ENDPOINT=http://127.0.0.1:9000 \ S3_SECURE=false \ - go test -v -count=1 ./registry/storage/driver/s3-aws/... + go test ${TESTFLAGS} -count=1 ./registry/storage/driver/s3-aws/... ##@ Validate From 075d81d7bf0fdca8dc8f0b652c2507181755f33b Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:17:48 +0100 Subject: [PATCH 03/12] Update Makefile Co-authored-by: James Hewitt Signed-off-by: Milos Gajdos --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index de9b1dd230..d7663d8fd3 100644 --- a/Makefile +++ b/Makefile @@ -122,7 +122,7 @@ test-cloud-storage: start-cloud-storage run-s3-tests stop-cloud-storage ## run c .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 + $(COMPOSE) -f tests/docker-compose-storage.yml up minio minio-init -d .PHONY: stop-cloud-storage stop-cloud-storage: ## stop local cloud storage (minio) From 8af25245f37fc1cd39a3a5bcfc594937bc3b609c Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:18:10 +0100 Subject: [PATCH 04/12] Update tests/docker-compose-storage.yml Co-authored-by: James Hewitt Signed-off-by: Milos Gajdos --- tests/docker-compose-storage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker-compose-storage.yml b/tests/docker-compose-storage.yml index b420fa815f..08e5ddb7f1 100644 --- a/tests/docker-compose-storage.yml +++ b/tests/docker-compose-storage.yml @@ -1,6 +1,6 @@ services: minio: - image: minio/minio:RELEASE.2023-09-20T22-49-55Z + image: docker.io/minio/minio:RELEASE.2023-09-20T22-49-55Z command: server /data --console-address ":9001" healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] From 6f05474fe057e92e54ea00685c4e756eb240acf5 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:18:21 +0100 Subject: [PATCH 05/12] Update tests/docker-compose-storage.yml Co-authored-by: James Hewitt Signed-off-by: Milos Gajdos --- tests/docker-compose-storage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker-compose-storage.yml b/tests/docker-compose-storage.yml index 08e5ddb7f1..48339ab0ed 100644 --- a/tests/docker-compose-storage.yml +++ b/tests/docker-compose-storage.yml @@ -17,7 +17,7 @@ services: - ./miniodata/distribution:/data minio-init: - image: minio/mc:RELEASE.2023-02-16T19-20-11Z + image: docker.io/minio/mc:RELEASE.2023-02-16T19-20-11Z depends_on: minio: condition: service_healthy From dfb8514a9f41c0a153feca18ad1d4dfc7960d4c2 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:21:56 +0100 Subject: [PATCH 06/12] Update Makefile Co-authored-by: James Hewitt Signed-off-by: Milos Gajdos --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index d7663d8fd3..a76a3e3604 100644 --- a/Makefile +++ b/Makefile @@ -144,6 +144,8 @@ run-s3-tests: ## run S3 storage driver integration tests S3_ENCRYPT=false \ REGION_ENDPOINT=http://127.0.0.1:9000 \ S3_SECURE=false \ + S3_ACCELERATE=false \ + AWS_S3_FORCE_PATH_STYLE=true \ go test ${TESTFLAGS} -count=1 ./registry/storage/driver/s3-aws/... ##@ Validate From ecf492ab5c61f2c9c2c847c00239dc5a95092bb0 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:29:06 +0100 Subject: [PATCH 07/12] Update tests/docker-compose-storage.yml Co-authored-by: James Hewitt Signed-off-by: Milos Gajdos --- tests/docker-compose-storage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker-compose-storage.yml b/tests/docker-compose-storage.yml index 48339ab0ed..1bb454abf3 100644 --- a/tests/docker-compose-storage.yml +++ b/tests/docker-compose-storage.yml @@ -14,7 +14,7 @@ services: MINIO_ROOT_USER: distribution MINIO_ROOT_PASSWORD: password volumes: - - ./miniodata/distribution:/data + - ./miniodata/distribution:/data:Z minio-init: image: docker.io/minio/mc:RELEASE.2023-02-16T19-20-11Z From 8e630ae2a5906330b41f4736f90851cf57349a04 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:36:23 +0100 Subject: [PATCH 08/12] Update BUILDING.md readme file. Signed-off-by: Milos Gajdos --- BUILDING.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index a80f1da542..f0102871e9 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -11,20 +11,18 @@ Most people should use the [official Registry docker image](https://hub.docker.c People looking for advanced operational use cases might consider rolling their own image with a custom Dockerfile inheriting `FROM registry:2`. -The latest updates to `main` branch are automatically pushed to [distribution Docker Hub repository](https://hub.docker.com/r/distribution/distribution) with `edge` tag. +The latest updates to `main` branch are automatically pushed to [distribution Docker Hub repository](https://hub.docker.com/r/distribution/distribution) and tagged with `edge` tag. ### Gotchas -You are expected to know your way around with `Go` & `git`. +You are expected to know your way around with `go` & `git`. -If you are a casual user with no development experience, and no preliminary knowledge of `Go`, building from source is probably not a good solution for you. +If you are a casual user with no development experience, and no preliminary knowledge of Go, building from source is probably not a good solution for you. ## Configure the development environment The first prerequisite of properly building distribution targets is to have a Go -development environment setup. Please follow [How to Write Go Code](https://golang.org/doc/code.html) -for proper setup. If done correctly, you should have a GOROOT and GOPATH set in the -environment. +development environment setup. Please follow [How to Write Go Code](https://go.dev/doc/code) for proper setup. Next, fetch the code from the repository using git: @@ -110,7 +108,7 @@ the environment variable `BUILDTAGS`. You can run an S3 API compatible storage locally with [minio](https://min.io/). -You must have [docker compose](https://docs.docker.com/compose/) installed on your workstation. +You must have [docker compose](https://docs.docker.com/compose/) compatible tool installed on your workstation. Start the local cloud environment: ``` From 14361b3ab5f5b724f2ee153ab9fa697a62cd86dc Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:41:42 +0100 Subject: [PATCH 09/12] Update Makefile and docker-compose * make COMPOSE overrideable * remove minio trace command from minio init Signed-off-by: Milos Gajdos --- Makefile | 8 +++++--- tests/docker-compose-storage.yml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a76a3e3604..43fd246379 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 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) +# default compose command +COMPOSE=docker compose PKG=github.com/distribution/distribution/v3 @@ -126,14 +128,14 @@ start-cloud-storage: ## start local cloud storage (minio) .PHONY: stop-cloud-storage stop-cloud-storage: ## stop local cloud storage (minio) - docker compose -f tests/docker-compose-storage.yml down + $(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 + $(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 + $(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 diff --git a/tests/docker-compose-storage.yml b/tests/docker-compose-storage.yml index 1bb454abf3..7377abcd72 100644 --- a/tests/docker-compose-storage.yml +++ b/tests/docker-compose-storage.yml @@ -25,7 +25,7 @@ services: /bin/bash -c " /usr/bin/mc config host add minio http://minio:9000 $${MINIO_ROOT_USER} $${MINIO_ROOT_PASSWORD} && ( /usr/bin/mc stat minio/images-local || /usr/bin/mc mb minio/images-local - ) && /usr/bin/mc anonymous set public minio/images-local && /usr/bin/mc admin trace --path " + ) && /usr/bin/mc anonymous set public minio/images-local" environment: MINIO_ROOT_USER: distribution MINIO_ROOT_PASSWORD: password From 98ffc56af7428651c0e1f7cb79c641c515113ee9 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 14:44:10 +0100 Subject: [PATCH 10/12] Only set COMPOSE if it doesnt have a value Signed-off-by: Milos Gajdos --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 43fd246379..5f0edee48e 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ 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) # default compose command -COMPOSE=docker compose +COMPOSE ?= docker compose PKG=github.com/distribution/distribution/v3 From cf95610635126d4814996044b5c4a9ea9d1d4d55 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 15:33:43 +0100 Subject: [PATCH 11/12] Update BUILDING.md Co-authored-by: James Hewitt Signed-off-by: Milos Gajdos --- BUILDING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILDING.md b/BUILDING.md index f0102871e9..aa1bcff00f 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -108,7 +108,7 @@ the environment variable `BUILDTAGS`. You can run an S3 API compatible storage locally with [minio](https://min.io/). -You must have [docker compose](https://docs.docker.com/compose/) compatible tool installed on your workstation. +You must have a [docker compose](https://docs.docker.com/compose/) compatible tool installed on your workstation. Start the local cloud environment: ``` From a5c04b3688ec65cc8713a4e53810f98e6b1f0d92 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 26 Sep 2023 17:24:04 +0100 Subject: [PATCH 12/12] Update Makefile Co-authored-by: James Hewitt Signed-off-by: Milos Gajdos --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5f0edee48e..2800cdd57c 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ reset-cloud-storage: ## reset (stop, delete, start) local cloud storage (minio) $(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 +run-s3-tests: start-cloud-storage ## run S3 storage driver integration tests AWS_ACCESS_KEY=distribution \ AWS_SECRET_KEY=password \ AWS_REGION=us-east-1 \