build_docker.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env sh
  2. #
  3. # This script builds Tailscale container images using
  4. # github.com/tailscale/mkctr.
  5. # By default the images will be tagged with the current version and git
  6. # hash of this repository as produced by ./cmd/mkversion.
  7. # This is the image build mechanim used to build the official Tailscale
  8. # container images.
  9. set -eu
  10. # Use the "go" binary from the "tool" directory (which is github.com/tailscale/go)
  11. export PATH="$PWD"/tool:"$PATH"
  12. eval "$(./build_dist.sh shellvars)"
  13. DEFAULT_TARGET="client"
  14. DEFAULT_TAGS="v${VERSION_SHORT},v${VERSION_MINOR}"
  15. DEFAULT_BASE="tailscale/alpine-base:3.18"
  16. PUSH="${PUSH:-false}"
  17. TARGET="${TARGET:-${DEFAULT_TARGET}}"
  18. TAGS="${TAGS:-${DEFAULT_TAGS}}"
  19. BASE="${BASE:-${DEFAULT_BASE}}"
  20. PLATFORM="${PLATFORM:-}" # default to all platforms
  21. case "$TARGET" in
  22. client)
  23. DEFAULT_REPOS="tailscale/tailscale"
  24. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  25. go run github.com/tailscale/mkctr \
  26. --gopaths="\
  27. tailscale.com/cmd/tailscale:/usr/local/bin/tailscale, \
  28. tailscale.com/cmd/tailscaled:/usr/local/bin/tailscaled, \
  29. tailscale.com/cmd/containerboot:/usr/local/bin/containerboot" \
  30. --ldflags="\
  31. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  32. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  33. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  34. --base="${BASE}" \
  35. --tags="${TAGS}" \
  36. --gotags="ts_kube,ts_package_container" \
  37. --repos="${REPOS}" \
  38. --push="${PUSH}" \
  39. --target="${PLATFORM}" \
  40. /usr/local/bin/containerboot
  41. ;;
  42. operator)
  43. DEFAULT_REPOS="tailscale/k8s-operator"
  44. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  45. go run github.com/tailscale/mkctr \
  46. --gopaths="tailscale.com/cmd/k8s-operator:/usr/local/bin/operator" \
  47. --ldflags="\
  48. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  49. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  50. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  51. --base="${BASE}" \
  52. --tags="${TAGS}" \
  53. --repos="${REPOS}" \
  54. --push="${PUSH}" \
  55. --target="${PLATFORM}" \
  56. /usr/local/bin/operator
  57. ;;
  58. k8s-nameserver)
  59. DEFAULT_REPOS="tailscale/k8s-nameserver"
  60. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  61. go run github.com/tailscale/mkctr \
  62. --gopaths="tailscale.com/cmd/k8s-nameserver:/usr/local/bin/k8s-nameserver" \
  63. --ldflags=" \
  64. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  65. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  66. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  67. --base="${BASE}" \
  68. --tags="${TAGS}" \
  69. --repos="${REPOS}" \
  70. --push="${PUSH}" \
  71. --target="${PLATFORM}" \
  72. /usr/local/bin/k8s-nameserver
  73. ;;
  74. *)
  75. echo "unknown target: $TARGET"
  76. exit 1
  77. ;;
  78. esac