2015-06-08 00:58:53 +00:00
<!-- [metadata]>
+++
2015-08-26 18:08:13 +00:00
title = "Build instructions"
description = "Explains how to build & hack on the registry"
keywords = ["registry, on-prem, images, tags, repository, distribution, build, recipe, advanced"]
2016-05-19 12:52:58 +00:00
[menu.main]
parent="smn_recipes"
2015-06-08 00:58:53 +00:00
+++
<![end-metadata]-->
2015-12-12 00:39:51 +00:00
# Building the registry source
2015-08-26 18:08:13 +00:00
## Use-case
This is useful if you intend to actively work on the registry.
2015-12-12 00:39:51 +00:00
### Alternatives
2015-08-26 18:08:13 +00:00
Most people should use the [official Registry docker image ](https://hub.docker.com/r/library/registry/ ).
People looking for advanced operational use cases might consider rolling their own image with a custom Dockerfile inheriting `FROM registry:2` .
2015-08-28 19:46:09 +00:00
OS X users who want to run natively can do so following [the instructions here ](osx-setup-guide.md ).
2015-08-26 18:08:13 +00:00
### Gotchas
2015-08-28 19:46:09 +00:00
You are expected to know your way around with go & git.
2015-08-26 18:08:13 +00: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.
## Build the development environment
2015-04-02 15:11:19 +00:00
2015-07-31 12:36:43 +00:00
The first prerequisite of properly building distribution targets is to have a Go
2015-06-03 18:59:56 +00:00
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.
If a Go development environment is setup, one can use `go get` to install the
2015-08-28 19:46:09 +00:00
`registry` command from the current latest:
2015-04-02 15:11:19 +00:00
2015-08-26 18:08:13 +00:00
go get github.com/docker/distribution/cmd/registry
2015-04-02 15:11:19 +00:00
2015-06-11 18:08:16 +00:00
The above will install the source repository into the `GOPATH` .
Now create the directory for the registry data (this might require you to set permissions properly)
2015-08-26 18:08:13 +00:00
mkdir -p /var/lib/registry
2015-06-11 18:08:16 +00:00
... or alternatively `export REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/somewhere` if you want to store data into another location.
The `registry`
2015-04-02 15:11:19 +00:00
binary can then be run with the following:
2015-10-07 10:08:13 +00:00
$ $GOPATH/bin/registry --version
2015-08-26 18:08:13 +00:00
$GOPATH/bin/registry github.com/docker/distribution v2.0.0-alpha.1+unknown
2015-04-02 15:11:19 +00:00
2015-06-03 18:59:56 +00:00
> __NOTE:__ While you do not need to use `go get` to checkout the distribution
> project, for these build instructions to work, the project must be checked
> out in the correct location in the `GOPATH`. This should almost always be
> `$GOPATH/src/github.com/docker/distribution`.
2015-04-02 15:11:19 +00:00
The registry can be run with the default config using the following
2015-07-31 12:36:43 +00:00
incantation:
2015-04-02 15:11:19 +00:00
2016-03-07 02:36:34 +00:00
$ $GOPATH/bin/registry serve $GOPATH/src/github.com/docker/distribution/cmd/registry/config-example.yml
2015-08-26 18:08:13 +00:00
INFO[0000] endpoint local-5003 disabled, skipping app.id=34bbec38-a91a-494a-9a3f-b72f9010081f version=v2.0.0-alpha.1+unknown
INFO[0000] endpoint local-8083 disabled, skipping app.id=34bbec38-a91a-494a-9a3f-b72f9010081f version=v2.0.0-alpha.1+unknown
INFO[0000] listening on :5000 app.id=34bbec38-a91a-494a-9a3f-b72f9010081f version=v2.0.0-alpha.1+unknown
INFO[0000] debug server listening localhost:5001
2015-04-02 15:11:19 +00:00
If it is working, one should see the above log messages.
### Repeatable Builds
For the full development experience, one should `cd` into
`$GOPATH/src/github.com/docker/distribution` . From there, the regular `go`
commands, such as `go test` , should work per package (please see
[Developing ](#developing ) if they don't work).
A `Makefile` has been provided as a convenience to support repeatable builds.
Please install the following into `GOPATH` for it to work:
2015-08-26 18:08:13 +00:00
go get github.com/tools/godep github.com/golang/lint/golint
2015-04-02 15:11:19 +00:00
**TODO(stevvooe):** Add a `make setup` command to Makefile to run this. Have to think about how to interact with Godeps properly.
Once these commands are available in the `GOPATH` , run `make` to get a full
build:
2016-03-31 17:46:02 +00:00
$ make
2015-08-26 18:08:13 +00:00
+ clean
+ fmt
+ vet
+ lint
+ build
github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar
github.com/Sirupsen/logrus
github.com/docker/libtrust
...
github.com/yvasiyarov/gorelic
github.com/docker/distribution/registry/handlers
github.com/docker/distribution/cmd/registry
+ test
...
ok github.com/docker/distribution/digest 7.875s
ok github.com/docker/distribution/manifest 0.028s
ok github.com/docker/distribution/notifications 17.322s
? github.com/docker/distribution/registry [no test files]
ok github.com/docker/distribution/registry/api/v2 0.101s
? github.com/docker/distribution/registry/auth [no test files]
ok github.com/docker/distribution/registry/auth/silly 0.011s
...
+ /Users/sday/go/src/github.com/docker/distribution/bin/registry
+ /Users/sday/go/src/github.com/docker/distribution/bin/registry-api-descriptor-template
+ binaries
2015-04-02 15:11:19 +00:00
The above provides a repeatable build using the contents of the vendored
Godeps directory. This includes formatting, vetting, linting, building,
testing and generating tagged binaries. We can verify this worked by running
the registry binary generated in the "./bin" directory:
2015-08-26 18:08:13 +00:00
$ ./bin/registry -version
./bin/registry github.com/docker/distribution v2.0.0-alpha.2-80-g16d8b2c.m
2015-04-02 15:11:19 +00:00
2015-04-23 16:13:52 +00:00
### Optional build tags
Optional [build tags ](http://golang.org/pkg/go/build/ ) can be provided using
the environment variable `DOCKER_BUILDTAGS` .