build_docker.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env sh
  2. #
  3. # Runs `go build` with flags configured for docker distribution. All
  4. # it does differently from `go build` is burn git commit and version
  5. # information into the binaries inside docker, so that we can track down user
  6. # issues.
  7. #
  8. ############################################################################
  9. #
  10. # WARNING: Tailscale is not yet officially supported in container
  11. # environments, such as Docker and Kubernetes. Though it should work, we
  12. # don't regularly test it, and we know there are some feature limitations.
  13. #
  14. # See current bugs tagged "containers":
  15. # https://github.com/tailscale/tailscale/labels/containers
  16. #
  17. ############################################################################
  18. set -eu
  19. # Use the "go" binary from the "tool" directory (which is github.com/tailscale/go)
  20. export PATH=$PWD/tool:$PATH
  21. eval $(./build_dist.sh shellvars)
  22. DEFAULT_TARGET="client"
  23. DEFAULT_TAGS="v${VERSION_SHORT},v${VERSION_MINOR}"
  24. DEFAULT_BASE="tailscale/alpine-base:3.16"
  25. PUSH="${PUSH:-false}"
  26. TARGET="${TARGET:-${DEFAULT_TARGET}}"
  27. TAGS="${TAGS:-${DEFAULT_TAGS}}"
  28. BASE="${BASE:-${DEFAULT_BASE}}"
  29. case "$TARGET" in
  30. client)
  31. DEFAULT_REPOS="tailscale/tailscale"
  32. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  33. go run github.com/tailscale/mkctr \
  34. --gopaths="\
  35. tailscale.com/cmd/tailscale:/usr/local/bin/tailscale, \
  36. tailscale.com/cmd/tailscaled:/usr/local/bin/tailscaled, \
  37. tailscale.com/cmd/containerboot:/usr/local/bin/containerboot" \
  38. --ldflags="\
  39. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  40. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  41. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  42. --base="${BASE}" \
  43. --tags="${TAGS}" \
  44. --repos="${REPOS}" \
  45. --push="${PUSH}" \
  46. /usr/local/bin/containerboot
  47. ;;
  48. operator)
  49. DEFAULT_REPOS="tailscale/k8s-operator"
  50. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  51. go run github.com/tailscale/mkctr \
  52. --gopaths="tailscale.com/cmd/k8s-operator:/usr/local/bin/operator" \
  53. --ldflags="\
  54. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  55. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  56. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  57. --base="${BASE}" \
  58. --tags="${TAGS}" \
  59. --repos="${REPOS}" \
  60. --push="${PUSH}" \
  61. /usr/local/bin/operator
  62. ;;
  63. *)
  64. echo "unknown target: $TARGET"
  65. exit 1
  66. ;;
  67. esac