diff --git a/build.sh b/build.sh index 50dfded97..a02bcad13 100755 --- a/build.sh +++ b/build.sh @@ -2,6 +2,8 @@ set -euo pipefail IFS=$'\n\t' +DOCKERIMGV=1.3.3-1 + case "${1:-default}" in default) go run build.go @@ -102,6 +104,18 @@ case "${1:-default}" in fi ;; + docker-init) + docker build -q -t syncthing/build:$DOCKERIMGV docker + ;; + + docker) + docker run --rm -h syncthing-builder -u $(id -u) -t \ + -v $(pwd):/go/src/github.com/syncthing/syncthing \ + -w /go/src/github.com/syncthing/syncthing \ + syncthing/build:$DOCKERIMGV \ + sh -c './build.sh clean && ./build.sh && STTRACE=all ./build.sh test-cov && ./build.sh all' + ;; + *) echo "Unknown build command $1" ;; diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..823d21fbc --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,56 @@ +FROM debian:jessie + +# SCMs for "go get", gcc for cgo +RUN apt-get update && apt-get install -y \ + ca-certificates curl gcc libc6-dev make \ + bzr git mercurial unzip \ + --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* + +ENV GOLANG_VERSION 1.3.3 + +# Get the binary dist of Go to be able to bootstrap gonative. + +RUN curl -sSL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz \ + | tar -v -C /usr/local -xz + +ENV PATH /usr/local/go/bin:$PATH +RUN mkdir /go +ENV GOPATH /go +ENV PATH /go/bin:$PATH +WORKDIR /go + +# Use gonative to install native Go for most arch/OS combos + +RUN go get github.com/calmh/gonative +RUN cd /usr/local \ + && rm -rf go \ + && gonative -version $GOLANG_VERSION + +# Random build users needs to be able to create stuff in /go/pkg + +RUN chmod -R 777 /go/pkg + +# Rebuild the special and missing versions + +RUN bash -xec '\ + cd /usr/local/go/src; \ + for platform in linux/386 freebsd/386 windows/386 linux/arm openbsd/amd64 openbsd/386; do \ + GOOS=${platform%/*} \ + GOARCH=${platform##*/} \ + GOARM=5 \ + GO386=387 \ + CGO_ENABLED=0 \ + ./make.bash --no-clean 2>&1; \ + done \ + ' + +# And rebuild native without the flags above + +RUN cd /usr/local/go/src \ + && ./make.bash --no-clean + +# Install packages needed for test coverage + +RUN go get github.com/tools/godep && go get code.google.com/p/go.tools/cmd/cover && go get github.com/axw/gocov/gocov && go get github.com/AlekSi/gocov-xml + diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..26f4917fc --- /dev/null +++ b/docker/README.md @@ -0,0 +1,29 @@ +Docker Build +============ + +Official builds are produced using a Docker image specified by the +Dockerfile in this directory. The following commands exactly reproduce +the official build process. + +Create an image called `syncthing/build` with the build environment. + +``` +./build.sh docker-init +``` + +> This is a Debian based image containing the latest stable version of +> Go set up for cross compilation. The cross compilation uses the +> dynamically linked standard libraries and SSE instructions for amd64 +> builds, but static linking and minimal instruction set for the 386 and +> arm builds. The command should be run in the main repo directory, as a +> user with permission to perform Docker operations. + +Build the full set of supported binaries. + +``` +./build.sh docker +``` + +> This uses a temporary container with the image from above and a volume +> mapped to the directory containing the source. Tests are run and +> binary packages created.