harbor/docs/compile_guide.md

210 lines
6.4 KiB
Markdown
Raw Normal View History

## Introduction
2016-11-10 09:10:39 +01:00
This guide provides instructions for developers to build and run Harbor from source code.
2016-11-10 09:10:39 +01:00
## Step 1: Prepare for a build environment for Harbor
2016-11-10 09:10:39 +01:00
Harbor is deployed as several Docker containers and most of the code is written in Go language. The build host requires Python, Docker, Docker Compose and golang development environment. Please install the below prerequisites:
Software | Required Version
----------------------|--------------------------
docker | 1.10.0 +
docker-compose | 1.7.1 +
python | 2.7 +
git | 1.9.1 +
make | 3.81 +
golang* | 1.6.0 +
*optional
2016-11-10 09:10:39 +01:00
## Step 2: Getting the source code
```sh
$ git clone https://github.com/vmware/harbor
```
2016-11-10 09:10:39 +01:00
## Step 3: Resolving dependencies of Go language
You can compile the source code by using a Golang dev image. In this case, you can skip this step.
If you are building Harbor using your own Go compiling environment. You need to install LDAP packages manually.
For PhotonOS:
```sh
$ tdnf install -y sed apr-util-ldap
```
For Ubuntu:
```sh
$ apt-get update && apt-get install -y libldap2-dev
```
2016-11-10 09:10:39 +01:00
For other platforms, please consult the relevant documentation of installing LDAP package.
2016-11-10 09:10:39 +01:00
## Step 4: Building and installing Harbor
2016-11-03 10:50:40 +01:00
### Configuration
2016-11-10 09:10:39 +01: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.
```sh
$ cd harbor
$ vi make/harbor.cfg
```
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
2016-11-10 09:10:39 +01:00
#### I. Create a Golang dev image, then build Harbor
2016-11-10 09:10:39 +01:00
* Build Golang dev image:
```sh
2016-11-03 10:50:40 +01:00
$ make compile_buildgolangimage -e GOBUILDIMAGE=harborgo:1.6.2
```
2016-11-10 09:10:39 +01:00
* Build, install and bring up Harbor:
```sh
2016-11-03 10:50:40 +01:00
$ make install -e GOBUILDIMAGE=harborgo:1.6.2 COMPILETAG=compile_golangimage
```
2016-11-10 09:10:39 +01:00
#### II. Compile code with your own Golang environment, then build Harbor
2016-11-10 09:10:39 +01:00
* Move source code to $GOPATH
```sh
$ mkdir $GOPATH/src/github.com/vmware/
$ cd ..
$ mv harbor $GOPATH/src/github.com/vmware/.
```
2016-11-10 09:10:39 +01:00
* Build, install and run Harbor
```sh
$ cd $GOPATH/src/github.com/vmware/harbor
$ make install
```
2016-11-10 09:10:39 +01:00
#### III. Manual build process (compatible with previous versions)
```sh
$ cd make
$ ./prepare
Generated configuration file: ./config/ui/env
Generated configuration file: ./config/ui/app.conf
Generated configuration file: ./config/registry/config.yml
Generated configuration file: ./config/db/env
...
$ cd dev
$ docker-compose up -d
```
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
2016-11-10 09:10:39 +01:00
If everyting worked properly, you can get the below message:
2016-11-03 10:50:40 +01:00
```sh
...
2016-11-10 09:10:39 +01:00
a?<3F><> ----Harbor has been installed and started successfully.----
2016-11-03 10:50:40 +01:00
Now you should be able to visit the admin portal at http://$YOURIP.
For more details, please visit https://github.com/vmware/harbor .
```
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
* Using the Makefile
2016-11-10 09:10:39 +01:00
The `Makefile` contains these configurable parameters:
Variable | Description
-------------------|-------------
BASEIMAGE | Container base image, default: photon
DEVFLAG | Build model flag, default: dev
COMPILETAG | Compile model flag, default: compile_normal (local golang build)
REGISTRYSERVER | Remote registry server address
REGISTRYUSER | Remote registry server user name
REGISTRYPASSWORD | Remote registry server user password
REGISTRYPROJECTNAME| Project name on remote registry server
2016-11-10 09:10:39 +01:00
Predefined targets:
2016-11-10 09:10:39 +01:00
Target | Description
--------------------|-------------
all | prepare env, compile binarys, build images and install images
prepare | prepare env
compile | compile ui and jobservice code
compile_golangimage | compile local golang image
compile_ui | compile ui binary
compile_jobservice | compile jobservice binary
build | build Harbor docker images (defuault | build_photon)
build_photon | build Harbor docker images from photon bsaeimage
build_ubuntu | build Harbor docker images from ubuntu baseimage
install | compile binarys, build images, prepare specific version composefile and startup Harbor instance
start | startup Harbor instance
down | shutdown Harbor instance
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
cleanimage | remove Harbor images
cleandockercomposefile | remove specific version docker-compose
cleanversiontag | remove specific version tag
cleanpackage | remove online/offline install package
#### EXAMPLE:
2016-11-10 09:10:39 +01:00
#### Build a golang dev image (for building Harbor):
```sh
$ make compile_golangimage -e GOBUILDIMAGE= [$YOURIMAGE]
```
2016-11-10 09:10:39 +01:00
#### Build Harbor images based on Ubuntu
```sh
$ make build -e BASEIMAGE=ubuntu
```
2016-11-10 09:10:39 +01:00
#### Push Harbor images to specific registry server
```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.
```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
```sh
$ make clean -e VERSIONTAG=[TAG]
```
2016-11-10 09:10:39 +01: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-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.
```sh
$ make XXXX -e DEVFLAG=false
```
2016-11-03 10:50:40 +01:00