2015-06-08 02:58:53 +02:00
2015-12-12 01:39:51 +01:00
# Building the registry source
2015-08-26 20:08:13 +02:00
## Use-case
This is useful if you intend to actively work on the registry.
2015-12-12 01:39:51 +01:00
### Alternatives
2015-08-26 20:08:13 +02:00
2023-10-12 12:39:36 +02:00
Most people should use prebuilt images, for example, the [Registry docker image ](https://hub.docker.com/r/library/registry/ ) provided by Docker.
2015-08-26 20:08:13 +02:00
People looking for advanced operational use cases might consider rolling their own image with a custom Dockerfile inheriting `FROM registry:2` .
2023-09-26 15:36:23 +02:00
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.
2015-08-26 20:08:13 +02:00
### Gotchas
2023-09-26 15:36:23 +02:00
You are expected to know your way around with `go` & `git` .
2015-08-26 20:08:13 +02:00
2023-09-26 15:36:23 +02:00
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.
2015-08-26 20:08:13 +02:00
2022-07-05 15:08:59 +02:00
## Configure the development environment
2015-04-02 17:11:19 +02:00
2015-07-31 14:36:43 +02:00
The first prerequisite of properly building distribution targets is to have a Go
2023-09-26 15:36:23 +02:00
development environment setup. Please follow [How to Write Go Code ](https://go.dev/doc/code ) for proper setup.
2015-06-03 20:59:56 +02:00
2022-07-05 15:08:59 +02:00
Next, fetch the code from the repository using git:
2015-04-02 17:11:19 +02:00
2022-11-07 16:06:46 +01:00
git clone https://github.com/distribution/distribution
2022-07-05 15:08:59 +02:00
cd distribution
2015-04-02 17:11:19 +02:00
2023-09-26 00:42:46 +02:00
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 ).
2022-07-05 15:08:59 +02:00
## Build and run from source
First, build the binaries:
$ make
+ bin/registry
+ bin/digest
+ bin/registry-api-descriptor-template
+ binaries
2015-06-11 20:08:16 +02:00
Now create the directory for the registry data (this might require you to set permissions properly)
2015-08-26 20:08:13 +02:00
mkdir -p /var/lib/registry
2015-06-11 20:08:16 +02:00
... or alternatively `export REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/somewhere` if you want to store data into another location.
The `registry`
2015-04-02 17:11:19 +02:00
binary can then be run with the following:
2022-07-05 15:08:59 +02:00
$ ./bin/registry --version
./bin/registry github.com/distribution/distribution/v3 v2.7.0-1993-g8857a194
2015-06-03 20:59:56 +02:00
2022-07-05 15:08:59 +02:00
The registry can be run with a development config using the following
2015-07-31 14:36:43 +02:00
incantation:
2015-04-02 17:11:19 +02:00
2022-07-05 15:08:59 +02:00
$ ./bin/registry serve cmd/registry/config-dev.yml
INFO[0000] debug server listening :5001
WARN[0000] No HTTP secret provided - generated random secret. This may cause problems with uploads if multiple registries are behind a load-balancer. To provide a shared secret, fill in http.secret in the configuration file or set the REGISTRY_HTTP_SECRET environment variable. environment=development go.version=go1.18.3 instance.id=e837df62-a66c-4e04-a014-b063546e82e0 service=registry version=v2.7.0-1993-g8857a194
INFO[0000] endpoint local-5003 disabled, skipping environment=development go.version=go1.18.3 instance.id=e837df62-a66c-4e04-a014-b063546e82e0 service=registry version=v2.7.0-1993-g8857a194
INFO[0000] endpoint local-8083 disabled, skipping environment=development go.version=go1.18.3 instance.id=e837df62-a66c-4e04-a014-b063546e82e0 service=registry version=v2.7.0-1993-g8857a194
INFO[0000] using inmemory blob descriptor cache environment=development go.version=go1.18.3 instance.id=e837df62-a66c-4e04-a014-b063546e82e0 service=registry version=v2.7.0-1993-g8857a194
INFO[0000] providing prometheus metrics on /metrics
INFO[0000] listening on [::]:5000 environment=development go.version=go1.18.3 instance.id=e837df62-a66c-4e04-a014-b063546e82e0 service=registry version=v2.7.0-1993-g8857a194
2015-04-02 17:11:19 +02:00
If it is working, one should see the above log messages.
2022-07-05 15:08:59 +02:00
### Build reference
2015-04-02 17:11:19 +02:00
2022-07-05 15:08:59 +02:00
The regular `go` commands, such as `go test` , should work per package.
2015-04-02 17:11:19 +02:00
A `Makefile` has been provided as a convenience to support repeatable builds.
2022-07-05 15:08:59 +02:00
Run `make` to build the binaries:
2015-04-02 17:11:19 +02:00
2016-03-31 19:46:02 +02:00
$ make
2022-07-05 15:08:59 +02:00
+ bin/registry
+ bin/digest
+ bin/registry-api-descriptor-template
2015-08-26 20:08:13 +02:00
+ binaries
2015-04-02 17:11:19 +02:00
2016-11-24 00:45:04 +01:00
The above provides a repeatable build using the contents of the vendor
2022-07-05 15:08:59 +02:00
directory. We can verify this worked by running
2015-04-02 17:11:19 +02:00
the registry binary generated in the "./bin" directory:
2018-02-27 23:46:06 +01:00
$ ./bin/registry --version
2020-08-24 13:18:39 +02:00
./bin/registry github.com/distribution/distribution v2.0.0-alpha.2-80-g16d8b2c.m
2015-04-02 17:11:19 +02:00
2022-07-05 15:08:59 +02:00
Run `make test` to run all of the tests.
Run `make validate` to run the validators, including the linter and vendor validation. You must have docker with the buildx plugin installed to run the validators.
2015-04-23 18:13:52 +02:00
### Optional build tags
Optional [build tags ](http://golang.org/pkg/go/build/ ) can be provided using
2023-06-28 12:41:22 +02:00
the environment variable `BUILDTAGS` .
2022-07-12 15:54:34 +02:00
< dl >
< dt > noresumabledigest< / dt >
< dd > Compiles without resumable digest support< / dd >
< / dl >
2023-09-26 00:42:46 +02:00
### Local cloud storage environment
You can run an S3 API compatible storage locally with [minio ](https://min.io/ ).
2023-09-26 16:33:43 +02:00
You must have a [docker compose ](https://docs.docker.com/compose/ ) compatible tool installed on your workstation.
2023-09-26 00:42:46 +02:00
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
```