build-deb 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env 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. (
  47. # Add the APT_MIRROR args only if the consuming Dockerfile uses it
  48. # Otherwise this will cause the build to fail
  49. if [ "$(grep 'ARG APT_MIRROR=' $dir/Dockerfile)" ] && [ "$BUILD_APT_MIRROR" ]; then
  50. DOCKER_BUILD_ARGS="$DOCKER_BUILD_ARGS $BUILD_APT_MIRROR"
  51. fi
  52. set -x && docker build ${DOCKER_BUILD_ARGS} -t "$image" "$dir"
  53. )
  54. fi
  55. mkdir -p "$DEST/$version"
  56. cat > "$DEST/$version/Dockerfile.build" <<-EOF
  57. FROM $image
  58. WORKDIR /usr/src/docker
  59. COPY . /usr/src/docker
  60. ENV DOCKER_GITCOMMIT $GITCOMMIT
  61. RUN mkdir -p /go/src/github.com/docker && mkdir -p /go/src/github.com/opencontainers \
  62. && ln -snf /usr/src/docker /go/src/github.com/docker/docker
  63. EOF
  64. cat >> "$DEST/$version/Dockerfile.build" <<-EOF
  65. # Install runc, containerd, proxy and tini
  66. RUN ./hack/dockerfile/install-binaries.sh runc-dynamic containerd-dynamic proxy-dynamic tini
  67. EOF
  68. cat >> "$DEST/$version/Dockerfile.build" <<-EOF
  69. RUN cp -aL hack/make/.build-deb debian
  70. RUN { echo '$debSource (${debVersion}-0~${version}) $suite; urgency=low'; echo; echo ' * Version: $VERSION'; echo; echo " -- $debMaintainer $debDate"; } > debian/changelog && cat >&2 debian/changelog
  71. RUN dpkg-buildpackage -uc -us -I.git
  72. EOF
  73. tempImage="docker-temp/build-deb:$version"
  74. ( set -x && docker build ${DOCKER_BUILD_ARGS} -t "$tempImage" -f "$DEST/$version/Dockerfile.build" . )
  75. docker run --rm "$tempImage" bash -c 'cd .. && tar -c *_*' | tar -xvC "$DEST/$version"
  76. docker rmi "$tempImage"
  77. done
  78. bundle .integration-daemon-stop
  79. ) 2>&1 | tee -a "$DEST/test.log"