2016-11-02 10:29:12 +01:00
## Introduction
2017-04-16 14:44:19 +02:00
This guide provides instructions for developers to build and run Harbor from source code.
2016-11-02 10:29:12 +01:00
2016-11-10 09:10:39 +01:00
## Step 1: Prepare for a build environment for Harbor
2016-11-04 08:25:06 +01:00
2017-04-16 14:44:19 +02:00
Harbor is deployed as several Docker containers and most of the code is written in Go language. The build environment requires Python, Docker, Docker Compose and golang development environment. Please install the below prerequisites:
2016-11-02 10:29:12 +01:00
Software | Required Version
----------------------|--------------------------
2017-04-18 06:47:43 +02:00
docker | 1.12.0 +
docker-compose | 1.11.0 +
2016-11-04 08:25:06 +01:00
python | 2.7 +
2016-11-02 10:29:12 +01:00
git | 1.9.1 +
make | 3.81 +
2017-04-16 14:44:19 +02:00
golang* | 1.7.3 +
*optional, required only if you use your own Golang environment.
2016-11-02 10:29:12 +01:00
2016-11-10 09:10:39 +01:00
## Step 2: Getting the source code
2016-11-02 10:29:12 +01:00
```sh
$ git clone https://github.com/vmware/harbor
```
2017-01-04 07:10:13 +01:00
## Step 3: Building and installing Harbor
2016-11-02 10:29:12 +01:00
2016-11-03 10:50:40 +01:00
### Configuration
2017-04-16 14:44:19 +02:00
Edit the file **make/harbor.cfg** and make necessary configuration changes such as hostname, admin password and mail server. Refer to ** [Installation and Configuration Guide ](installation_guide.md#configuring-harbor )** for more info.
2016-11-02 10:29:12 +01:00
```sh
$ cd harbor
$ vi make/harbor.cfg
```
2017-04-16 14:44:19 +02:00
2016-11-10 09:10:39 +01:00
### Compiling and Running
2016-11-03 10:50:40 +01:00
2016-11-10 09:10:39 +01:00
You can compile the code by one of the three approaches:
2016-11-03 10:50:40 +01:00
2017-01-04 07:10:13 +01:00
#### I. Build with offical Golang image
2016-11-02 10:29:12 +01:00
2017-01-04 07:10:13 +01:00
* Get offcial Golang image from docker hub:
2016-11-02 10:29:12 +01:00
```sh
2017-01-04 07:10:13 +01:00
$ docker pull golang:1.7.3
2016-11-02 10:29:12 +01:00
```
2017-04-16 14:44:19 +02:00
* Build, install and bring up Harbor without Notary:
```sh
2017-05-14 10:11:02 +02:00
$ make install GOBUILDIMAGE=golang:1.7.3 COMPILETAG=compile_golangimage CLARITYIMAGE=vmware/harbor-clarity-ui-builder:1.1.1
2017-04-16 14:44:19 +02:00
```
* Build, install and bring up Harbor with Notary:
2016-11-02 10:29:12 +01:00
```sh
2017-05-14 10:11:02 +02:00
$ make install GOBUILDIMAGE=golang:1.7.3 COMPILETAG=compile_golangimage CLARITYIMAGE=vmware/harbor-clarity-ui-builder:1.1.1 NOTARYFLAG=true
2016-11-02 10:29:12 +01:00
```
2016-11-10 09:10:39 +01:00
#### II. Compile code with your own Golang environment, then build Harbor
2016-11-02 10:29:12 +01:00
2016-11-10 09:10:39 +01:00
* Move source code to $GOPATH
2016-11-02 10:29:12 +01:00
```sh
$ mkdir $GOPATH/src/github.com/vmware/
$ cd ..
$ mv harbor $GOPATH/src/github.com/vmware/.
```
2017-04-16 14:44:19 +02:00
* Build, install and run Harbor without Notary:
2016-11-02 10:29:12 +01:00
```sh
$ cd $GOPATH/src/github.com/vmware/harbor
$ make install
```
2017-04-16 14:44:19 +02:00
* Build, install and run Harbor with Notary:
2016-11-02 10:29:12 +01:00
```sh
2017-04-16 14:44:19 +02:00
$ cd $GOPATH/src/github.com/vmware/harbor
$ make install -e NOTARYFLAG=true
```
2016-11-03 10:50:40 +01:00
2016-11-10 09:10:39 +01:00
### Verify your installation
2016-11-03 10:50:40 +01:00
2017-04-16 14:44:19 +02:00
If everything worked properly, you can get the below message:
2016-11-03 10:50:40 +01:00
```sh
...
2017-04-16 14:44:19 +02:00
Start complete. You can visit harbor now.
2016-11-03 10:50:40 +01:00
```
2016-11-04 08:25:06 +01:00
2016-11-10 09:10:39 +01:00
Refer to [Installation and Configuration Guide ](installation_guide.md#managing-harbors-lifecycle ) for more information about managing your Harbor instance.
2016-11-03 10:50:40 +01:00
2016-11-10 09:10:39 +01:00
## Appendix
2016-11-02 10:29:12 +01:00
* Using the Makefile
2016-11-10 09:10:39 +01:00
The `Makefile` contains these configurable parameters:
2016-11-02 10:29:12 +01:00
Variable | Description
-------------------|-------------
BASEIMAGE | Container base image, default: photon
2017-04-16 14:44:19 +02:00
CLARITYIMAGE | Clarity UI builder image, default: harbor-clarity-ui-builder
2016-11-02 10:29:12 +01:00
DEVFLAG | Build model flag, default: dev
COMPILETAG | Compile model flag, default: compile_normal (local golang build)
2017-04-16 14:44:19 +02:00
NOTARYFLAG | Notary mode flag, default: false
HTTPPROXY | NPM http proxy for Clarity UI builder
2016-11-10 09:22:08 +01:00
REGISTRYSERVER | Remote registry server IP address
2016-11-02 10:29:12 +01:00
REGISTRYUSER | Remote registry server user name
REGISTRYPASSWORD | Remote registry server user password
REGISTRYPROJECTNAME| Project name on remote registry server
2016-11-10 09:16:36 +01:00
* Predefined targets:
2016-11-02 10:29:12 +01:00
2016-11-10 09:10:39 +01:00
Target | Description
2016-11-02 10:29:12 +01:00
--------------------|-------------
2017-04-16 14:44:19 +02:00
all | prepare env, compile binaries, build images and install images
2016-11-02 10:29:12 +01:00
prepare | prepare env
compile | compile ui and jobservice code
compile_ui | compile ui binary
compile_jobservice | compile jobservice binary
2017-04-16 14:44:19 +02:00
compile_clarity | compile Clarity binary
2016-11-10 09:22:08 +01:00
build | build Harbor docker images (default: using build_photon)
build_photon | build Harbor docker images from Photon OS base image
install | compile binaries, build images, prepare specific version of compose file and startup Harbor instance
2017-04-16 14:44:19 +02:00
start | startup Harbor instance (set NOTARYFLAG=true when with Notary)
down | shutdown Harbor instance (set NOTARYFLAG=true when with Notary)
2016-11-02 10:29:12 +01:00
package_online | prepare online install package
package_offline | prepare offline install package
pushimage | push Harbor images to specific registry server
clean all | remove binary, Harbor images, specific version docker-compose file, specific version tag and online/offline install package
cleanbinary | remove ui and jobservice binary
2017-04-16 14:44:19 +02:00
cleanimage | remove Harbor images
cleandockercomposefile | remove specific version docker-compose
2016-11-04 08:25:06 +01:00
cleanversiontag | remove specific version tag
2016-11-02 10:29:12 +01:00
cleanpackage | remove online/offline install package
#### EXAMPLE:
2016-11-10 09:10:39 +01:00
#### Push Harbor images to specific registry server
2016-11-02 10:29:12 +01:00
```sh
$ make pushimage -e DEVFLAG=false REGISTRYSERVER=[$SERVERADDRESS] REGISTRYUSER=[$USERNAME] REGISTRYPASSWORD=[$PASSWORD] REGISTRYPROJECTNAME=[$PROJECTNAME]
```
2016-11-10 09:10:39 +01:00
**Note** : need add "/" on end of REGISTRYSERVER. If REGISTRYSERVER is not set, images will be pushed directly to Docker Hub.
2016-11-02 10:29:12 +01:00
```sh
$ make pushimage -e DEVFLAG=false REGISTRYUSER=[$USERNAME] REGISTRYPASSWORD=[$PASSWORD] REGISTRYPROJECTNAME=[$PROJECTNAME]
```
2016-11-10 09:10:39 +01:00
#### Clean up binaries and images of a specific version
2016-11-02 10:29:12 +01:00
```sh
$ make clean -e VERSIONTAG=[TAG]
```
2017-04-16 14:44:19 +02:00
**Note** : If new code had been added to Github, the git commit TAG will change. Better use this command to clean up images and files of previous TAG.
2016-11-02 10:29:12 +01:00
2016-11-10 09:10:39 +01:00
#### By default, the make process create a development build. To create a release build of Harbor, set the below flag to false.
2016-11-02 10:29:12 +01:00
```sh
$ make XXXX -e DEVFLAG=false
```