2
0

build_docker.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. --gotags="ts_kube" \
  46. --repos="${REPOS}" \
  47. --push="${PUSH}" \
  48. --target="${PLATFORM}" \
  49. /usr/local/bin/containerboot
  50. ;;
  51. operator)
  52. DEFAULT_REPOS="tailscale/k8s-operator"
  53. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  54. go run github.com/tailscale/mkctr \
  55. --gopaths="tailscale.com/cmd/k8s-operator:/usr/local/bin/operator" \
  56. --ldflags="\
  57. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  58. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  59. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  60. --base="${BASE}" \
  61. --tags="${TAGS}" \
  62. --repos="${REPOS}" \
  63. --push="${PUSH}" \
  64. --target="${PLATFORM}" \
  65. /usr/local/bin/operator
  66. ;;
  67. k8s-nameserver)
  68. DEFAULT_REPOS="tailscale/k8s-nameserver"
  69. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  70. go run github.com/tailscale/mkctr \
  71. --gopaths="tailscale.com/cmd/k8s-nameserver:/usr/local/bin/k8s-nameserver" \
  72. --ldflags=" \
  73. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  74. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  75. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  76. --base="${BASE}" \
  77. --tags="${TAGS}" \
  78. --repos="${REPOS}" \
  79. --push="${PUSH}" \
  80. --target="${PLATFORM}" \
  81. /usr/local/bin/k8s-nameserver
  82. ;;
  83. *)
  84. echo "unknown target: $TARGET"
  85. exit 1
  86. ;;
  87. esac