build_docker.sh 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.19"
  16. # Set a few pre-defined OCI annotations. The source annotation is used by tools such as Renovate that scan the linked
  17. # Github repo to find release notes for any new image tags. Note that for official Tailscale images the default
  18. # annotations defined here will be overriden by release scripts that call this script.
  19. # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
  20. DEFAULT_ANNOTATIONS="org.opencontainers.image.source=https://github.com/tailscale/tailscale/blob/main/build_docker.sh,org.opencontainers.image.vendor=Tailscale"
  21. PUSH="${PUSH:-false}"
  22. TARGET="${TARGET:-${DEFAULT_TARGET}}"
  23. TAGS="${TAGS:-${DEFAULT_TAGS}}"
  24. BASE="${BASE:-${DEFAULT_BASE}}"
  25. PLATFORM="${PLATFORM:-}" # default to all platforms
  26. # OCI annotations that will be added to the image.
  27. # https://github.com/opencontainers/image-spec/blob/main/annotations.md
  28. ANNOTATIONS="${ANNOTATIONS:-${DEFAULT_ANNOTATIONS}}"
  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. --gotags="ts_kube,ts_package_container" \
  45. --repos="${REPOS}" \
  46. --push="${PUSH}" \
  47. --target="${PLATFORM}" \
  48. --annotations="${ANNOTATIONS}" \
  49. /usr/local/bin/containerboot
  50. ;;
  51. k8s-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. --gotags="ts_kube,ts_package_container" \
  63. --repos="${REPOS}" \
  64. --push="${PUSH}" \
  65. --target="${PLATFORM}" \
  66. --annotations="${ANNOTATIONS}" \
  67. /usr/local/bin/operator
  68. ;;
  69. k8s-nameserver)
  70. DEFAULT_REPOS="tailscale/k8s-nameserver"
  71. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  72. go run github.com/tailscale/mkctr \
  73. --gopaths="tailscale.com/cmd/k8s-nameserver:/usr/local/bin/k8s-nameserver" \
  74. --ldflags=" \
  75. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  76. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  77. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  78. --base="${BASE}" \
  79. --tags="${TAGS}" \
  80. --gotags="ts_kube,ts_package_container" \
  81. --repos="${REPOS}" \
  82. --push="${PUSH}" \
  83. --target="${PLATFORM}" \
  84. --annotations="${ANNOTATIONS}" \
  85. /usr/local/bin/k8s-nameserver
  86. ;;
  87. *)
  88. echo "unknown target: $TARGET"
  89. exit 1
  90. ;;
  91. esac