Use a docker container for full builds

This commit is contained in:
Jakob Borg 2014-11-19 15:02:47 +04:00
parent ce948fc512
commit ba019efaf1
3 changed files with 99 additions and 0 deletions

View File

@ -2,6 +2,8 @@
set -euo pipefail set -euo pipefail
IFS=$'\n\t' IFS=$'\n\t'
DOCKERIMGV=1.3.3-1
case "${1:-default}" in case "${1:-default}" in
default) default)
go run build.go go run build.go
@ -102,6 +104,18 @@ case "${1:-default}" in
fi 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" echo "Unknown build command $1"
;; ;;

56
docker/Dockerfile Normal file
View File

@ -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

29
docker/README.md Normal file
View File

@ -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.