build_docker.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #
  10. # If you want to build local images for testing, you can use make, which provides few convenience wrappers around this script.
  11. #
  12. # To build a Tailscale image and push to the local docker registry:
  13. # $ REPO=local/tailscale TAGS=v0.0.1 PLATFORM=local make publishdevimage
  14. #
  15. # To build a Tailscale image and push to a remote docker registry:
  16. #
  17. # $ REPO=<your-registry>/<your-repo>/tailscale TAGS=v0.0.1 make publishdevimage
  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.22"
  25. # Set a few pre-defined OCI annotations. The source annotation is used by tools such as Renovate that scan the linked
  26. # Github repo to find release notes for any new image tags. Note that for official Tailscale images the default
  27. # annotations defined here will be overriden by release scripts that call this script.
  28. # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
  29. DEFAULT_ANNOTATIONS="org.opencontainers.image.source=https://github.com/tailscale/tailscale/blob/main/build_docker.sh,org.opencontainers.image.vendor=Tailscale"
  30. PUSH="${PUSH:-false}"
  31. TARGET="${TARGET:-${DEFAULT_TARGET}}"
  32. TAGS="${TAGS:-${DEFAULT_TAGS}}"
  33. BASE="${BASE:-${DEFAULT_BASE}}"
  34. PLATFORM="${PLATFORM:-}" # default to all platforms
  35. FILES="${FILES:-}" # default to no extra files
  36. # OCI annotations that will be added to the image.
  37. # https://github.com/opencontainers/image-spec/blob/main/annotations.md
  38. ANNOTATIONS="${ANNOTATIONS:-${DEFAULT_ANNOTATIONS}}"
  39. case "$TARGET" in
  40. client)
  41. DEFAULT_REPOS="tailscale/tailscale"
  42. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  43. go run github.com/tailscale/mkctr \
  44. --gopaths="\
  45. tailscale.com/cmd/tailscale:/usr/local/bin/tailscale, \
  46. tailscale.com/cmd/tailscaled:/usr/local/bin/tailscaled, \
  47. tailscale.com/cmd/containerboot:/usr/local/bin/containerboot" \
  48. --ldflags="\
  49. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  50. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  51. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  52. --base="${BASE}" \
  53. --tags="${TAGS}" \
  54. --gotags="ts_kube,ts_package_container" \
  55. --repos="${REPOS}" \
  56. --push="${PUSH}" \
  57. --target="${PLATFORM}" \
  58. --annotations="${ANNOTATIONS}" \
  59. --files="${FILES}" \
  60. /usr/local/bin/containerboot
  61. ;;
  62. k8s-operator)
  63. DEFAULT_REPOS="tailscale/k8s-operator"
  64. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  65. go run github.com/tailscale/mkctr \
  66. --gopaths="tailscale.com/cmd/k8s-operator:/usr/local/bin/operator" \
  67. --ldflags="\
  68. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  69. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  70. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  71. --base="${BASE}" \
  72. --tags="${TAGS}" \
  73. --gotags="ts_kube,ts_package_container" \
  74. --repos="${REPOS}" \
  75. --push="${PUSH}" \
  76. --target="${PLATFORM}" \
  77. --annotations="${ANNOTATIONS}" \
  78. --files="${FILES}" \
  79. /usr/local/bin/operator
  80. ;;
  81. k8s-nameserver)
  82. DEFAULT_REPOS="tailscale/k8s-nameserver"
  83. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  84. go run github.com/tailscale/mkctr \
  85. --gopaths="tailscale.com/cmd/k8s-nameserver:/usr/local/bin/k8s-nameserver" \
  86. --ldflags=" \
  87. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  88. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  89. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  90. --base="${BASE}" \
  91. --tags="${TAGS}" \
  92. --gotags="ts_kube,ts_package_container" \
  93. --repos="${REPOS}" \
  94. --push="${PUSH}" \
  95. --target="${PLATFORM}" \
  96. --annotations="${ANNOTATIONS}" \
  97. --files="${FILES}" \
  98. /usr/local/bin/k8s-nameserver
  99. ;;
  100. tsidp)
  101. DEFAULT_REPOS="tailscale/tsidp"
  102. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  103. go run github.com/tailscale/mkctr \
  104. --gopaths="tailscale.com/cmd/tsidp:/usr/local/bin/tsidp" \
  105. --ldflags=" \
  106. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  107. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  108. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  109. --base="${BASE}" \
  110. --tags="${TAGS}" \
  111. --gotags="ts_package_container" \
  112. --repos="${REPOS}" \
  113. --push="${PUSH}" \
  114. --target="${PLATFORM}" \
  115. --annotations="${ANNOTATIONS}" \
  116. --files="${FILES}" \
  117. /usr/local/bin/tsidp
  118. ;;
  119. k8s-proxy)
  120. DEFAULT_REPOS="tailscale/k8s-proxy"
  121. REPOS="${REPOS:-${DEFAULT_REPOS}}"
  122. go run github.com/tailscale/mkctr \
  123. --gopaths="tailscale.com/cmd/k8s-proxy:/usr/local/bin/k8s-proxy" \
  124. --ldflags=" \
  125. -X tailscale.com/version.longStamp=${VERSION_LONG} \
  126. -X tailscale.com/version.shortStamp=${VERSION_SHORT} \
  127. -X tailscale.com/version.gitCommitStamp=${VERSION_GIT_HASH}" \
  128. --base="${BASE}" \
  129. --tags="${TAGS}" \
  130. --gotags="ts_kube,ts_package_container" \
  131. --repos="${REPOS}" \
  132. --push="${PUSH}" \
  133. --target="${PLATFORM}" \
  134. --annotations="${ANNOTATIONS}" \
  135. --files="${FILES}" \
  136. /usr/local/bin/k8s-proxy
  137. ;;
  138. *)
  139. echo "unknown target: $TARGET"
  140. exit 1
  141. ;;
  142. esac