build_docker.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.18"
  25. PUSH="${PUSH:-false}"
  26. TARGET="${TARGET:-${DEFAULT_TARGET}}"
  27. TAGS="${TAGS:-${DEFAULT_TAGS}}"
  28. BASE="${BASE:-${DEFAULT_BASE}}"
  29. PLATFORM="${PLATFORM:-}" # default to all platforms
  30. case "$TARGET" in
  31. client)
  32. DEFAULT_REPOS="tailscale/tailscale"
  33. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  34. go run github.com/tailscale/mkctr \
  35. --gopaths="\
  36. tailscale.com/cmd/tailscale:/usr/local/bin/tailscale, \
  37. tailscale.com/cmd/tailscaled:/usr/local/bin/tailscaled, \
  38. tailscale.com/cmd/containerboot:/usr/local/bin/containerboot" \
  39. --ldflags="\
  40. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  41. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  42. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  43. --base="${BASE}" \
  44. --tags="${TAGS}" \
  45. --repos="${REPOS}" \
  46. --push="${PUSH}" \
  47. --target="${PLATFORM}" \
  48. /usr/local/bin/containerboot
  49. ;;
  50. operator)
  51. DEFAULT_REPOS="tailscale/k8s-operator"
  52. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  53. go run github.com/tailscale/mkctr \
  54. --gopaths="tailscale.com/cmd/k8s-operator:/usr/local/bin/operator" \
  55. --ldflags="\
  56. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  57. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  58. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  59. --base="${BASE}" \
  60. --tags="${TAGS}" \
  61. --repos="${REPOS}" \
  62. --push="${PUSH}" \
  63. --target="${PLATFORM}" \
  64. /usr/local/bin/operator
  65. ;;
  66. *)
  67. echo "unknown target: $TARGET"
  68. exit 1
  69. ;;
  70. esac