dynbinary 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. set -e
  3. DEST=$1
  4. if [ -z "$DOCKER_CLIENTONLY" ]; then
  5. # dockerinit still needs to be a static binary, even if docker is dynamic
  6. go build \
  7. -o "$DEST/dockerinit-$VERSION" \
  8. "${BUILDFLAGS[@]}" \
  9. -ldflags "
  10. $LDFLAGS
  11. $LDFLAGS_STATIC
  12. -extldflags \"$EXTLDFLAGS_STATIC\"
  13. " \
  14. ./dockerinit
  15. echo "Created binary: $DEST/dockerinit-$VERSION"
  16. ln -sf "dockerinit-$VERSION" "$DEST/dockerinit"
  17. hash_files "$DEST/dockerinit-$VERSION"
  18. sha1sum=
  19. if command -v sha1sum &> /dev/null; then
  20. sha1sum=sha1sum
  21. elif command -v shasum &> /dev/null; then
  22. # Mac OS X - why couldn't they just use the same command name and be happy?
  23. sha1sum=shasum
  24. else
  25. echo >&2 'error: cannot find sha1sum command or equivalent'
  26. exit 1
  27. fi
  28. # sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another
  29. export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
  30. else
  31. # DOCKER_CLIENTONLY must be truthy, so we don't need to bother with dockerinit :)
  32. export DOCKER_INITSHA1=""
  33. fi
  34. # exported so that "dyntest" can easily access it later without recalculating it
  35. (
  36. export LDFLAGS_STATIC_DOCKER="-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X $DOCKER_PKG/dockerversion.INITPATH \"$DOCKER_INITPATH\""
  37. export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary
  38. source "$(dirname "$BASH_SOURCE")/binary"
  39. )