github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/hack/make/build-deb (about) 1 #!/bin/bash 2 set -e 3 4 # subshell so that we can export PATH and TZ without breaking other things 5 ( 6 export TZ=UTC # make sure our "date" variables are UTC-based 7 bundle .integration-daemon-start 8 bundle .detect-daemon-osarch 9 10 # TODO consider using frozen images for the dockercore/builder-deb tags 11 12 tilde='~' # ouch Bash 4.2 vs 4.3, you keel me 13 debVersion="${VERSION//-/$tilde}" # using \~ or '~' here works in 4.3, but not 4.2; just ~ causes $HOME to be inserted, hence the $tilde 14 # if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better 15 if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then 16 gitUnix="$(git log -1 --pretty='%at')" 17 gitDate="$(date --date "@$gitUnix" +'%Y%m%d.%H%M%S')" 18 gitCommit="$(git log -1 --pretty='%h')" 19 gitVersion="git${gitDate}.0.${gitCommit}" 20 # gitVersion is now something like 'git20150128.112847.0.17e840a' 21 debVersion="$debVersion~$gitVersion" 22 23 # $ dpkg --compare-versions 1.5.0 gt 1.5.0~rc1 && echo true || echo false 24 # true 25 # $ dpkg --compare-versions 1.5.0~rc1 gt 1.5.0~git20150128.112847.17e840a && echo true || echo false 26 # true 27 # $ dpkg --compare-versions 1.5.0~git20150128.112847.17e840a gt 1.5.0~dev~git20150128.112847.17e840a && echo true || echo false 28 # true 29 30 # ie, 1.5.0 > 1.5.0~rc1 > 1.5.0~git20150128.112847.17e840a > 1.5.0~dev~git20150128.112847.17e840a 31 fi 32 33 debSource="$(awk -F ': ' '$1 == "Source" { print $2; exit }' hack/make/.build-deb/control)" 34 debMaintainer="$(awk -F ': ' '$1 == "Maintainer" { print $2; exit }' hack/make/.build-deb/control)" 35 debDate="$(date --rfc-2822)" 36 37 # if go-md2man is available, pre-generate the man pages 38 ./man/md2man-all.sh -q || true 39 # TODO decide if it's worth getting go-md2man in _each_ builder environment to avoid this 40 41 builderDir="contrib/builder/deb/${PACKAGE_ARCH}" 42 pkgs=( $(find "${builderDir}/"*/ -type d) ) 43 if [ ! -z "$DOCKER_BUILD_PKGS" ]; then 44 pkgs=() 45 for p in $DOCKER_BUILD_PKGS; do 46 pkgs+=( "$builderDir/$p" ) 47 done 48 fi 49 for dir in "${pkgs[@]}"; do 50 [ -d "$dir" ] || { echo >&2 "skipping nonexistent $dir"; continue; } 51 version="$(basename "$dir")" 52 suite="${version##*-}" 53 54 image="dockercore/builder-deb:$version" 55 if ! docker inspect "$image" &> /dev/null; then 56 ( set -x && docker build ${DOCKER_BUILD_ARGS} -t "$image" "$dir" ) 57 fi 58 59 mkdir -p "$DEST/$version" 60 cat > "$DEST/$version/Dockerfile.build" <<-EOF 61 FROM $image 62 WORKDIR /usr/src/docker 63 COPY . /usr/src/docker 64 ENV DOCKER_GITCOMMIT $GITCOMMIT 65 RUN mkdir -p /go/src/github.com/docker && mkdir -p /go/src/github.com/opencontainers \ 66 && ln -snf /usr/src/docker /go/src/github.com/docker/docker 67 EOF 68 69 # get the RUNC and CONTAINERD commit from the root Dockerfile, this keeps the commits in sync 70 awk '$1 == "ENV" && $2 == "RUNC_COMMIT" { print; exit }' Dockerfile >> "$DEST/$version/Dockerfile.build" 71 awk '$1 == "ENV" && $2 == "CONTAINERD_COMMIT" { print; exit }' Dockerfile >> "$DEST/$version/Dockerfile.build" 72 73 # add runc and containerd compile and install 74 cat >> "$DEST/$version/Dockerfile.build" <<-EOF 75 # Install runc 76 RUN git clone https://github.com/opencontainers/runc.git "/go/src/github.com/opencontainers/runc" \ 77 && cd "/go/src/github.com/opencontainers/runc" \ 78 && git checkout -q "\$RUNC_COMMIT" 79 RUN set -x && export GOPATH="/go" && cd "/go/src/github.com/opencontainers/runc" \ 80 && make BUILDTAGS="\$RUNC_BUILDTAGS" && make install 81 # Install containerd 82 RUN git clone https://github.com/docker/containerd.git "/go/src/github.com/docker/containerd" \ 83 && cd "/go/src/github.com/docker/containerd" \ 84 && git checkout -q "\$CONTAINERD_COMMIT" 85 RUN set -x && export GOPATH="/go" && cd "/go/src/github.com/docker/containerd" && make && make install 86 EOF 87 if [ "$DOCKER_EXPERIMENTAL" ]; then 88 echo 'ENV DOCKER_EXPERIMENTAL 1' >> "$DEST/$version/Dockerfile.build" 89 fi 90 cat >> "$DEST/$version/Dockerfile.build" <<-EOF 91 RUN cp -aL hack/make/.build-deb debian 92 RUN { echo '$debSource (${debVersion}-0~${suite}) $suite; urgency=low'; echo; echo ' * Version: $VERSION'; echo; echo " -- $debMaintainer $debDate"; } > debian/changelog && cat >&2 debian/changelog 93 EOF 94 # Remove the following case-based substitution when none of these are supported, and the TasksMax value is uncommented in docker.service 95 case "$version" in 96 debian-jessie|debian-wheezy|ubuntu-precise|ubuntu-trusty|ubuntu-wily) 97 ;; 98 *) 99 echo "RUN sed -i -- 's/#TasksMax=infinity/TasksMax=infinity/' contrib/init/systemd/docker.service" >> "$DEST/$version/Dockerfile.build" 100 ;; 101 esac 102 cat >> "$DEST/$version/Dockerfile.build" <<-EOF 103 RUN dpkg-buildpackage -uc -us -I.git 104 EOF 105 tempImage="docker-temp/build-deb:$version" 106 ( set -x && docker build -t "$tempImage" -f "$DEST/$version/Dockerfile.build" . ) 107 docker run --rm "$tempImage" bash -c 'cd .. && tar -c *_*' | tar -xvC "$DEST/$version" 108 docker rmi "$tempImage" 109 done 110 111 bundle .integration-daemon-stop 112 ) 2>&1 | tee -a "$DEST/test.log"