dynbinary 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. cat > dockerversion/static.go <<EOF
  7. // AUTOGENERATED FILE; see hack/make/binary and hack/make/dynbinary
  8. package dockerversion
  9. func init() {
  10. IAMSTATIC = true
  11. }
  12. EOF
  13. go build \
  14. -o "$DEST/dockerinit-$VERSION" \
  15. "${BUILDFLAGS[@]}" \
  16. -ldflags "
  17. $LDFLAGS
  18. $LDFLAGS_STATIC
  19. -extldflags \"$EXTLDFLAGS_STATIC\"
  20. " \
  21. ./dockerinit
  22. echo "Created binary: $DEST/dockerinit-$VERSION"
  23. ln -sf "dockerinit-$VERSION" "$DEST/dockerinit"
  24. hash_files "$DEST/dockerinit-$VERSION"
  25. sha1sum=
  26. if command -v sha1sum &> /dev/null; then
  27. sha1sum=sha1sum
  28. elif command -v shasum &> /dev/null; then
  29. # Mac OS X - why couldn't they just use the same command name and be happy?
  30. sha1sum=shasum
  31. else
  32. echo >&2 'error: cannot find sha1sum command or equivalent'
  33. exit 1
  34. fi
  35. # sha1 our new dockerinit to ensure separate docker and dockerinit always run in a perfect pair compiled for one another
  36. export DOCKER_INITSHA1="$($sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
  37. else
  38. # DOCKER_CLIENTONLY must be truthy, so we don't need to bother with dockerinit :)
  39. export DOCKER_INITSHA1=""
  40. fi
  41. # exported so that "dyntest" can easily access it later without recalculating it
  42. (
  43. export LDFLAGS_STATIC_DOCKER="-X $DOCKER_PKG/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X $DOCKER_PKG/dockerversion.INITPATH \"$DOCKER_INITPATH\""
  44. export IAMSTATIC=false
  45. export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary
  46. source "$(dirname "$BASH_SOURCE")/binary"
  47. )