build-deb 4.4 KB

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