ubuntu 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/bin/bash
  2. PKGVERSION="${VERSION//-/'~'}"
  3. # if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better
  4. if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then
  5. GIT_UNIX="$(git log -1 --pretty='%at')"
  6. GIT_DATE="$(date --date "@$GIT_UNIX" +'%Y%m%d.%H%M%S')"
  7. GIT_COMMIT="$(git log -1 --pretty='%h')"
  8. GIT_VERSION="git${GIT_DATE}.0.${GIT_COMMIT}"
  9. # GIT_VERSION is now something like 'git20150128.112847.0.17e840a'
  10. PKGVERSION="$PKGVERSION~$GIT_VERSION"
  11. fi
  12. # $ dpkg --compare-versions 1.5.0 gt 1.5.0~rc1 && echo true || echo false
  13. # true
  14. # $ dpkg --compare-versions 1.5.0~rc1 gt 1.5.0~git20150128.112847.17e840a && echo true || echo false
  15. # true
  16. # $ dpkg --compare-versions 1.5.0~git20150128.112847.17e840a gt 1.5.0~dev~git20150128.112847.17e840a && echo true || echo false
  17. # true
  18. # ie, 1.5.0 > 1.5.0~rc1 > 1.5.0~git20150128.112847.17e840a > 1.5.0~dev~git20150128.112847.17e840a
  19. PACKAGE_ARCHITECTURE="$(dpkg-architecture -qDEB_HOST_ARCH)"
  20. PACKAGE_URL="https://www.docker.com/"
  21. PACKAGE_MAINTAINER="support@docker.com"
  22. PACKAGE_DESCRIPTION="Linux container runtime
  23. Docker complements LXC with a high-level API which operates at the process
  24. level. It runs unix processes with strong guarantees of isolation and
  25. repeatability across servers.
  26. Docker is a great building block for automating distributed systems:
  27. large-scale web deployments, database clusters, continuous deployment systems,
  28. private PaaS, service-oriented architectures, etc."
  29. PACKAGE_LICENSE="Apache-2.0"
  30. # Build docker as an ubuntu package using FPM and REPREPRO (sue me).
  31. # bundle_binary must be called first.
  32. bundle_ubuntu() {
  33. DIR="$ABS_DEST/build"
  34. # Include our udev rules
  35. mkdir -p "$DIR/etc/udev/rules.d"
  36. cp contrib/udev/80-docker.rules "$DIR/etc/udev/rules.d/"
  37. # Include our init scripts
  38. mkdir -p "$DIR/etc/init"
  39. cp contrib/init/upstart/docker.conf "$DIR/etc/init/"
  40. mkdir -p "$DIR/etc/init.d"
  41. cp contrib/init/sysvinit-debian/docker "$DIR/etc/init.d/"
  42. mkdir -p "$DIR/etc/default"
  43. cp contrib/init/sysvinit-debian/docker.default "$DIR/etc/default/docker"
  44. mkdir -p "$DIR/lib/systemd/system"
  45. cp contrib/init/systemd/docker.{service,socket} "$DIR/lib/systemd/system/"
  46. # Include contributed completions
  47. mkdir -p "$DIR/etc/bash_completion.d"
  48. cp contrib/completion/bash/docker "$DIR/etc/bash_completion.d/"
  49. mkdir -p "$DIR/usr/share/zsh/vendor-completions"
  50. cp contrib/completion/zsh/_docker "$DIR/usr/share/zsh/vendor-completions/"
  51. mkdir -p "$DIR/etc/fish/completions"
  52. cp contrib/completion/fish/docker.fish "$DIR/etc/fish/completions/"
  53. # Include man pages
  54. make manpages
  55. manRoot="$DIR/usr/share/man"
  56. mkdir -p "$manRoot"
  57. for manDir in man/man?; do
  58. manBase="$(basename "$manDir")" # "man1"
  59. for manFile in "$manDir"/*; do
  60. manName="$(basename "$manFile")" # "docker-build.1"
  61. mkdir -p "$manRoot/$manBase"
  62. gzip -c "$manFile" > "$manRoot/$manBase/$manName.gz"
  63. done
  64. done
  65. # Copy the binary
  66. # This will fail if the binary bundle hasn't been built
  67. mkdir -p "$DIR/usr/bin"
  68. cp "$DEST/../binary/docker-$VERSION" "$DIR/usr/bin/docker"
  69. # Generate postinst/prerm/postrm scripts
  70. cat > "$DEST/postinst" <<'EOF'
  71. #!/bin/sh
  72. set -e
  73. set -u
  74. if [ "$1" = 'configure' ] && [ -z "$2" ]; then
  75. if ! getent group docker > /dev/null; then
  76. groupadd --system docker
  77. fi
  78. fi
  79. if ! { [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; }; then
  80. # we only need to do this if upstart isn't in charge
  81. update-rc.d docker defaults > /dev/null || true
  82. fi
  83. if [ -n "$2" ]; then
  84. _dh_action=restart
  85. else
  86. _dh_action=start
  87. fi
  88. service docker $_dh_action 2>/dev/null || true
  89. #DEBHELPER#
  90. EOF
  91. cat > "$DEST/prerm" <<'EOF'
  92. #!/bin/sh
  93. set -e
  94. set -u
  95. service docker stop 2>/dev/null || true
  96. #DEBHELPER#
  97. EOF
  98. cat > "$DEST/postrm" <<'EOF'
  99. #!/bin/sh
  100. set -e
  101. set -u
  102. if [ "$1" = "purge" ] ; then
  103. update-rc.d docker remove > /dev/null || true
  104. fi
  105. # In case this system is running systemd, we make systemd reload the unit files
  106. # to pick up changes.
  107. if [ -d /run/systemd/system ] ; then
  108. systemctl --system daemon-reload > /dev/null || true
  109. fi
  110. #DEBHELPER#
  111. EOF
  112. # TODO swaths of these were borrowed from debhelper's auto-inserted stuff, because we're still using fpm - we need to use debhelper instead, and somehow reconcile Ubuntu that way
  113. chmod +x "$DEST/postinst" "$DEST/prerm" "$DEST/postrm"
  114. (
  115. # switch directories so we create *.deb in the right folder
  116. cd "$DEST"
  117. # create lxc-docker-VERSION package
  118. fpm -s dir -C "$DIR" \
  119. --name "lxc-docker-$VERSION" --version "$PKGVERSION" \
  120. --after-install "$ABS_DEST/postinst" \
  121. --before-remove "$ABS_DEST/prerm" \
  122. --after-remove "$ABS_DEST/postrm" \
  123. --architecture "$PACKAGE_ARCHITECTURE" \
  124. --prefix / \
  125. --depends iptables \
  126. --deb-recommends aufs-tools \
  127. --deb-recommends ca-certificates \
  128. --deb-recommends git \
  129. --deb-recommends xz-utils \
  130. --deb-recommends 'cgroupfs-mount | cgroup-lite' \
  131. --deb-suggests apparmor \
  132. --description "$PACKAGE_DESCRIPTION" \
  133. --maintainer "$PACKAGE_MAINTAINER" \
  134. --conflicts docker \
  135. --conflicts docker.io \
  136. --conflicts lxc-docker-virtual-package \
  137. --provides lxc-docker \
  138. --provides lxc-docker-virtual-package \
  139. --replaces lxc-docker \
  140. --replaces lxc-docker-virtual-package \
  141. --url "$PACKAGE_URL" \
  142. --license "$PACKAGE_LICENSE" \
  143. --config-files /etc/udev/rules.d/80-docker.rules \
  144. --config-files /etc/init/docker.conf \
  145. --config-files /etc/init.d/docker \
  146. --config-files /etc/default/docker \
  147. --deb-compression gz \
  148. -t deb .
  149. # TODO replace "Suggests: cgroup-lite" with "Recommends: cgroupfs-mount | cgroup-lite" once cgroupfs-mount is available
  150. # create empty lxc-docker wrapper package
  151. fpm -s empty \
  152. --name lxc-docker --version "$PKGVERSION" \
  153. --architecture "$PACKAGE_ARCHITECTURE" \
  154. --depends lxc-docker-$VERSION \
  155. --description "$PACKAGE_DESCRIPTION" \
  156. --maintainer "$PACKAGE_MAINTAINER" \
  157. --url "$PACKAGE_URL" \
  158. --license "$PACKAGE_LICENSE" \
  159. --deb-compression gz \
  160. -t deb
  161. )
  162. # clean up after ourselves so we have a clean output directory
  163. rm "$DEST/postinst" "$DEST/prerm" "$DEST/postrm"
  164. rm -r "$DIR"
  165. }
  166. bundle_ubuntu