If you want to contribute to swarm, then build swarm by yourself is required.

Prerequisites:

  • Install golang.

    Note: beginning with Swarm 0.4 golang 1.4.x or later is required for building Swarm. 

  • Install Git.

  • Install godep


Build step:

  • Run following commands to check the required softwares have been installed well on your machine:

 # git version
 git version 1.9.1
 # go version
 go version go1.5.2 linux/amd64
 # godep version
 godep v37 (linux/amd64/go1.5.2)
  • Set GOPATH, download swarm source code and it's all dependencies:

 # export GOPATH=/opt/go
 # godep get github.com/docker/swarm

    Note: If some packages can not be downloaded due to the network issue, you can configure the network proxy to download them manually, and copy them to $GOPATH/src, for example:

# godep get github.com/docker/swarm
package golang.org/x/net/context: unrecognized import path "golang.org/x/net/context"
godep: exit status 1

    Address this issue: configure network proxy to download "golang.org/x/net/context" and copy downloaded files to /opt/go/src/golang.org/x/net/context

    Note: swich to the corresponding docker branch that the current developing swarm is required:

# godep get github.com/docker/swarm
package github.com/docker/docker/pkg/parsers/filters: cannot find package "github.com/docker/docker/pkg/parsers/filters" in any of:
	/usr/local/go/src/github.com/docker/docker/pkg/parsers/filters (from $GOROOT)
	/opt/go/src/github.com/docker/docker/pkg/parsers/filters (from $GOPATH)
godep: exit status 1

    Address this issue:

# cd /opt/go/src/github.com/docker/docker
# git branch
* master
# git checkout release/v1.9

  Run godep again to check whether all dependencies are downloaded:

# godep get github.com/docker/swarm

 Then you can find the swam binary are located in your GOPATH

# ll /opt/go/bin/swarm
-rwxr-xr-x 1 root root 22577112 Dec 16 15:38 /opt/go/bin/swarm*
  • Rebuild the swarm binary manually after your change the swam code:

    Note: the swam source code also has be downloaded and located in your GOPATH:

# cd /opt/go/src/github.com/docker/swarm/
# git branch
* master
# git remote -v
origin	https://github.com/docker/swarm (fetch)
origin	https://github.com/docker/swarm (push)
# git checkout -b forYourChanges
-- Do your changes
# rm -rf /opt/go/bin/swarm
# go build
# go install
# ll /opt/go/bin/swarm
-rwxr-xr-x 1 root root 24180448 Dec 16 16:02 /opt/go/bin/swarm*

The above steps have be verified on Utuntu 14.04.