This guide provides instructions for developers to build and run Harbor from source code.

Step 1: Prepare for a build environment for Harbor

Harbor is deployed as several Docker containers and most of the code is written in Go language. The build environment requires Docker, Docker Compose and golang development environment. Please install the below prerequisites:

SoftwareRequired Version
docker17.05 +
docker-compose1.18.0 +
python2.7 +
git1.9.1 +
make3.81 +
golang*1.15.6 +

*optional, required if you use your own Golang environment.

Step 2: Getting the source code

  1. git clone https://github.com/goharbor/harbor

Step 3: Building and installing Harbor

Configuration

Copy the file make/harbor.yml.tmp to make/harbor.yml, and make necessary configuration changes such as hostname, admin password and mail server. Refer to Harbor Installation and Configuration for more info.

  1. cd harbor
  2. vi make/harbor.yml

Compiling and Running

You can compile the code by one of the two approaches:

I. Build with official Golang image

  • Build, install and bring up Harbor without Notary:

    1. make install COMPILETAG=compile_golangimage
  • Build, install and bring up Harbor with Notary:

    1. make install COMPILETAG=compile_golangimage NOTARYFLAG=true

II. Compile code with your own Golang environment, then build Harbor

  • Move source code to $GOPATH

    1. mkdir $GOPATH/src/github.com/goharbor/
    2. cd ..
    3. mv harbor $GOPATH/src/github.com/goharbor/.
  • Build, install and run Harbor without Notary:

    1. cd $GOPATH/src/github.com/goharbor/harbor
    2. $ make install
  • Build, install and run Harbor with Notary:

    1. cd $GOPATH/src/github.com/goharbor/harbor
    2. make install -e NOTARYFLAG=true

Verify your installation

If everything works properly, you will see this message:

  1. ...
  2. Start complete. You can visit harbor now.

Refer to Reconfigure Harbor and Manage the Harbor Lifecycle for more information about managing your Harbor instance.

Appendix

  • Using the Makefile

The Makefile contains these configurable parameters:

VariableDescription
BASEIMAGEContainer base image, default: photon
DEVFLAGBuild model flag, default: dev
COMPILETAGCompile model flag, default: compile_normal (local golang build)
NOTARYFLAGNotary mode flag, default: false
TRIVYFLAGTrivy mode flag, default: false
HTTPPROXYNPM http proxy for Clarity UI builder
REGISTRYSERVERRemote registry server IP address
REGISTRYUSERRemote registry server user name
REGISTRYPASSWORDRemote registry server user password
REGISTRYPROJECTNAMEProject name on remote registry server
VERSIONTAGHarbor images tag, default: dev
PKGVERSIONTAGHarbor online and offline version tag, default:dev
  • Predefined targets:
TargetDescription
allprepare env, compile binaries, build images and install images
prepareprepare env
compilecompile ui and jobservice code
compile_portalcompile portal code
compile_uicompile ui binary
compile_jobservicecompile jobservice binary
buildbuild Harbor docker images (default: using build_photon)
build_photonbuild Harbor docker images from Photon OS base image
installcompile binaries, build images, prepare specific version of compose file and startup Harbor instance
startstartup Harbor instance (set NOTARYFLAG=true when with Notary)
downshutdown Harbor instance (set NOTARYFLAG=true when with Notary)
package_onlineprepare online install package
package_offlineprepare offline install package
pushimagepush Harbor images to specific registry server
cleanallremove binary, Harbor images, specific version docker-compose file, specific version tag and online/offline install package
cleanbinaryremove ui and jobservice binary
cleanimageremove Harbor images
cleandockercomposefileremove specific version docker-compose
cleanversiontagremove specific version tag
cleanpackageremove online/offline install package

EXAMPLE:

Push Harbor images to specific registry server

  1. make pushimage -e DEVFLAG=false REGISTRYSERVER=[$SERVERADDRESS] REGISTRYUSER=[$USERNAME] REGISTRYPASSWORD=[$PASSWORD] REGISTRYPROJECTNAME=[$PROJECTNAME]

Note: need to add “/” at the end of REGISTRYSERVER. If REGISTRYSERVER is not set, images will be pushed directly to Docker Hub.

  1. make pushimage -e DEVFLAG=false REGISTRYUSER=[$USERNAME] REGISTRYPASSWORD=[$PASSWORD] REGISTRYPROJECTNAME=[$PROJECTNAME]

Clean up binaries and images of a specific version

  1. make clean -e VERSIONTAG=[TAG]

If new code has been added to Github, the git commit TAG will change. Better use this command to clean up images and files of the previous TAG.

By default, the make process creates a development build. To create a release build of Harbor, set the below flag to false.

  1. make XXXX -e DEVFLAG=false