make.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # This script builds various binary artifacts from a checkout of the docker
  3. # source code.
  4. #
  5. # Requirements:
  6. # - The current directory should be a checkout of the docker source code
  7. # (http://github.com/dotcloud/docker). Whatever version is checked out
  8. # will be built.
  9. # - The VERSION file, at the root of the repository, should exist, and
  10. # will be used as Docker binary version and package version.
  11. # - The hash of the git commit will also be included in the Docker binary,
  12. # with the suffix -dirty if the repository isn't clean.
  13. # - The script is intented to be run inside the docker container specified
  14. # in the Dockerfile at the root of the source. In other words:
  15. # DO NOT CALL THIS SCRIPT DIRECTLY.
  16. # - The right way to call this script is to invoke "docker build ." from
  17. # your checkout of the Docker repository, and then
  18. # "docker run hack/make.sh" in the resulting container image.
  19. #
  20. set -e
  21. # We're a nice, sexy, little shell script, and people might try to run us;
  22. # but really, they shouldn't. We want to be in a container!
  23. RESOLVCONF=$(readlink --canonicalize /etc/resolv.conf)
  24. grep -q "$RESOLVCONF" /proc/mounts || {
  25. echo >&2 "# WARNING! I don't seem to be running in a docker container."
  26. echo >&2 "# The result of this command might be an incorrect build, and will not be officially supported."
  27. echo >&2 "# Try this: 'docker build -t docker . && docker run docker ./hack/make.sh'"
  28. }
  29. # List of bundles to create when no argument is passed
  30. DEFAULT_BUNDLES=(
  31. test
  32. binary
  33. ubuntu
  34. )
  35. VERSION=$(cat ./VERSION)
  36. GITCOMMIT=$(git rev-parse --short HEAD)
  37. if [ -n "$(git status --porcelain)" ]; then
  38. GITCOMMIT="$GITCOMMIT-dirty"
  39. fi
  40. # Use these flags when compiling the tests and final binary
  41. LDFLAGS='-X main.GITCOMMIT "'$GITCOMMIT'" -X main.VERSION "'$VERSION'" -w -linkmode external -extldflags "-static -Wl,--unresolved-symbols=ignore-in-shared-libs"'
  42. BUILDFLAGS='-tags netgo'
  43. bundle() {
  44. bundlescript=$1
  45. bundle=$(basename $bundlescript)
  46. echo "---> Making bundle: $bundle (in bundles/$VERSION/$bundle)"
  47. mkdir -p bundles/$VERSION/$bundle
  48. source $bundlescript $(pwd)/bundles/$VERSION/$bundle
  49. }
  50. main() {
  51. # We want this to fail if the bundles already exist and cannot be removed.
  52. # This is to avoid mixing bundles from different versions of the code.
  53. mkdir -p bundles
  54. if [ -e "bundles/$VERSION" ]; then
  55. echo "bundles/$VERSION already exists. Removing."
  56. rm -fr bundles/$VERSION && mkdir bundles/$VERSION || exit 1
  57. echo
  58. fi
  59. SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  60. if [ $# -lt 1 ]; then
  61. bundles=($DEFAULT_BUNDLES)
  62. else
  63. bundles=($@)
  64. fi
  65. for bundle in ${bundles[@]}; do
  66. bundle $SCRIPTDIR/make/$bundle
  67. echo
  68. done
  69. }
  70. main "$@"