.drone.jsonnet 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. //
  2. // tweakables
  3. //
  4. local registry = "084037375216.dkr.ecr.us-east-2.amazonaws.com";
  5. local build_channel = "zerotier-builds";
  6. local release_channel = "zerotier-releases";
  7. local targets = [
  8. { "os": "linux", distro: "redhat", "name": "el9", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "tag", "custom" ] },
  9. { "os": "linux", distro: "redhat", "name": "el8", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "tag" ] },
  10. { "os": "linux", distro: "redhat", "name": "el7", "isas": [ "386", "amd64", "ppc64le"], "events": [ "tag" ] },
  11. { "os": "linux", distro: "amazon", "name": "amzn2", "isas": [ "amd64", "arm64" ], "events": [ "tag" ] },
  12. { "os": "linux", distro: "amazon", "name": "amzn2022", "isas": [ "amd64", "arm64" ], "events": [ "tag" ] },
  13. { "os": "linux", distro: "fedora", "name": "fc38", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "tag" ] },
  14. { "os": "linux", distro: "fedora", "name": "fc37", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "tag" ] },
  15. { "os": "linux", distro: "fedora", "name": "fc36", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "tag" ] },
  16. { "os": "linux", distro: "ubuntu", "name": "jammy", "isas": [ "armv7", "amd64", "arm64", "ppc64le", "s390x", "riscv64" ], "events": [ "tag" ] },
  17. { "os": "linux", distro: "ubuntu", "name": "focal", "isas": [ "armv7", "amd64", "arm64", "ppc64le", "s390x", "riscv64" ], "events": [ "tag" ] },
  18. { "os": "linux", distro: "ubuntu", "name": "bionic", "isas": [ "386", "armv7", "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "tag" ] },
  19. { "os": "linux", distro: "ubuntu", "name": "xenial", "isas": [ "386", "armv7", "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "tag" ] },
  20. { "os": "linux", distro: "ubuntu", "name": "trusty", "isas": [ "386", "armv7", "amd64", "arm64" ], "events": [ "tag" ] },
  21. { "os": "linux", distro: "debian", "name": "bookworm", "isas": [ "386", "armv7", "amd64", "arm64", "mips64le", "ppc64le", "s390x" ], "events": [ "tag"] },
  22. { "os": "linux", distro: "debian", "name": "bullseye", "isas": [ "386", "armv7", "amd64", "arm64", "mips64le", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  23. { "os": "linux", distro: "debian", "name": "buster", "isas": [ "386", "armv7", "amd64", "arm64" ], "events": [ "tag" ] },
  24. { "os": "linux", distro: "debian", "name": "stretch", "isas": [ "386", "armv7", "amd64", "arm64" ], "events": [ "tag" ] },
  25. { "os": "linux", distro: "debian", "name": "jessie", "isas": [ "386", "armv7", "amd64" ], "events": [ "tag" ] },
  26. // { "os": "windows", distro: "windows", "name": "windows", "isas": [ "amd64" ], "events": [ "push", "tag", "custom" ] },
  27. // { "os": "darwin", distro: "darwin", "name": "darwin", "isas": [ "amd64" ], "events": [ "push", "tag", "custom" ] },
  28. ];
  29. local less_targets = [
  30. { "os": "linux", distro: "redhat", "name": "el9", "isas": [ "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  31. { "os": "linux", distro: "redhat", "name": "el8", "isas": [ "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  32. { "os": "linux", distro: "ubuntu", "name": "jammy", "isas": [ "armv7", "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  33. { "os": "linux", distro: "ubuntu", "name": "focal", "isas": [ "armv7", "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  34. ];
  35. local native_targets = [
  36. { "os": "linux", distro: "debian", "name": "bullseye", "isas": [ "386", "armv7", "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  37. ];
  38. local master_targets = [
  39. //
  40. // copypasta from here
  41. //
  42. { "os": "linux", distro: "redhat", "name": "el9", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  43. { "os": "linux", distro: "redhat", "name": "el8", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  44. { "os": "linux", distro: "redhat", "name": "el7", "isas": [ "386", "amd64", "ppc64le"], "events": [ "push", "tag", "custom" ] },
  45. { "os": "linux", distro: "amazon", "name": "amzn2", "isas": [ "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  46. { "os": "linux", distro: "amazon", "name": "amzn2022", "isas": [ "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  47. { "os": "linux", distro: "fedora", "name": "fc38", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  48. { "os": "linux", distro: "fedora", "name": "fc37", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  49. { "os": "linux", distro: "fedora", "name": "fc36", "isas": [ "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  50. { "os": "linux", distro: "ubuntu", "name": "jammy", "isas": [ "armv7", "amd64", "arm64", "ppc64le", "s390x", "riscv64" ], "events": [ "push", "tag", "custom" ] },
  51. { "os": "linux", distro: "ubuntu", "name": "focal", "isas": [ "armv7", "amd64", "arm64", "ppc64le", "s390x", "riscv64" ], "events": [ "push", "tag", "custom" ] },
  52. { "os": "linux", distro: "ubuntu", "name": "bionic", "isas": [ "386", "armv7", "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  53. { "os": "linux", distro: "ubuntu", "name": "xenial", "isas": [ "386", "armv7", "amd64", "arm64", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  54. { "os": "linux", distro: "ubuntu", "name": "trusty", "isas": [ "386", "armv7", "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  55. { "os": "linux", distro: "debian", "name": "sid", "isas": [ "386", "armv7", "amd64", "arm64", "mips64le", "ppc64le", "s390x", "riscv64" ], "events": [ "push", "tag", "custom" ] },
  56. { "os": "linux", distro: "debian", "name": "bookworm", "isas": [ "386", "armv7", "amd64", "arm64", "mips64le", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  57. { "os": "linux", distro: "debian", "name": "bullseye", "isas": [ "386", "armv7", "amd64", "arm64", "mips64le", "ppc64le", "s390x" ], "events": [ "push", "tag", "custom" ] },
  58. { "os": "linux", distro: "debian", "name": "buster", "isas": [ "386", "armv7", "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  59. { "os": "linux", distro: "debian", "name": "stretch", "isas": [ "386", "armv7", "amd64", "arm64" ], "events": [ "push", "tag", "custom" ] },
  60. { "os": "linux", distro: "debian", "name": "jessie", "isas": [ "386", "armv7", "amd64" ], "events": [ "push", "tag", "custom" ] },
  61. { "os": "windows", distro: "windows", "name": "win2k22", "isas": [ "amd64" ], "events": [ "push", "tag", "custom" ] }
  62. ];
  63. //
  64. // functions
  65. //
  66. local pipeline_type(os) = if os == "darwin" then "exec" else "docker";
  67. local builder_image(os) = if os == "linux" then registry + "/honda-builder" else registry + "/windows-builder";
  68. local tester_image(os) = if os == "linux" then registry + "/honda-builder" else registry + "/windows-tester";
  69. local build_step_volumes(os) = if os == "linux" then [ { name: "zerotier-builds", path: "/zerotier-builds" } ] else [];
  70. local release_step_volumes(os) = if os == "linux" then [ { name: "zerotier-releases", path: "/zerotier-releases" } ] else [];
  71. local host_volumes(os) = if os == "linux" then [
  72. { name: "zerotier-builds", host: { path: "/zerotier-builds" } },
  73. { name: "zerotier-releases", host: { path: "/zerotier-releases" } },
  74. ] else [];
  75. local index_image(distro) =
  76. if distro == "debian" || distro == "ubuntu" then
  77. registry + "/apt-builder"
  78. else if distro == "redhat" || distro == "fedora" || distro == "amazon" then
  79. registry + "/dnf-builder"
  80. else if distro == "windows" then
  81. registry + "/msi-builder"
  82. ;
  83. local copy_commands(os, distro, name, isa, version) =
  84. if os == "linux" then [
  85. std.join(" ", [ "./ci/scripts/publish.sh", name, distro, isa, version, "${DRONE_BUILD_EVENT}" ])
  86. ]
  87. else if os == "windows" then [
  88. "C:\\scripts\\fix-ec2-metadata.ps1",
  89. "Get-ChildItem windows",
  90. // "aws s3 cp windows\\bytey-SetupFiles\\bytey.msi s3://zerotier-builds/windows/" + version + "/bytey.msi",
  91. ] else if os == "darwin" then [
  92. "echo hello"
  93. ]
  94. ;
  95. local index_commands(os, channel, distro, name, isas) =
  96. if os == "linux" then
  97. [ "/usr/local/bin/index " + channel + " " + distro + " " + name + " " + std.join(" ", isas) ]
  98. else if os == "windows" then
  99. [ "Get-ChildItem -Recurse windows" ]
  100. ;
  101. local build_commands(os, distro, name, isa, version) =
  102. if os == "linux" then
  103. [ std.join(" ", [ "./ci/scripts/build.sh", name, distro, isa, version, "${DRONE_BUILD_EVENT}" ]) ]
  104. else
  105. if os == "windows" then
  106. [ "windows/build.ps1", "windows/package.ps1" ]
  107. else
  108. if os == "darwin" then
  109. [ "whoami" ]
  110. ;
  111. local test_commands(os, distro, name, isa, version) =
  112. if os == "linux" then
  113. [ std.join(" ", [ "./ci/scripts/test.sh", name, distro, isa, version, "${DRONE_BUILD_EVENT}" ]) ]
  114. else
  115. if os == "windows" then
  116. [ "windows/testpackage.ps1 " + version ]
  117. ;
  118. //
  119. // render
  120. //
  121. local Build(os, distro, name, isa, events) = {
  122. "kind": "pipeline",
  123. "type": pipeline_type(os),
  124. "name": std.join(" ", [ name, isa, "build" ]),
  125. "pull": "always",
  126. "clone": { "depth": 1, [ if os == "darwin" then "disable" ]: true },
  127. "steps": [
  128. {
  129. "name": "build",
  130. "image": builder_image(os),
  131. "commands": build_commands(os, distro, name, isa, "100.0.0+${DRONE_COMMIT_SHA:0:8}"),
  132. "when": { "event": [ "push" ]},
  133. },
  134. {
  135. "name": "release",
  136. "image": builder_image(os),
  137. "commands": build_commands(os, distro, name, isa, "${DRONE_TAG}"),
  138. "when": { "event": [ "tag" ]},
  139. },
  140. {
  141. "name": "copy build",
  142. "image": builder_image(os),
  143. "commands": copy_commands(os, distro, name, isa, "100.0.0+${DRONE_COMMIT_SHA:0:8}"),
  144. "volumes": build_step_volumes(os),
  145. "when": { "event": [ "push" ]},
  146. },
  147. {
  148. "name": "copy relase",
  149. "image": builder_image(os),
  150. "commands": copy_commands(os, distro, name, isa, "${DRONE_TAG}"),
  151. "volumes": release_step_volumes(os),
  152. "when": { "event": [ "tag" ]},
  153. },
  154. ],
  155. "volumes": host_volumes(os),
  156. "platform": { "os": os, [ if isa == "arm64" || isa == "armv7" then "arch" ]: "arm64" },
  157. "trigger": { "event": events }
  158. };
  159. local Test(os, distro, name, isa, events) = {
  160. "kind": "pipeline",
  161. "type": pipeline_type(os),
  162. "name": std.join(" ", [ name, isa, "test"]),
  163. "pull": "always",
  164. "clone": { "depth": 1 },
  165. "steps": [
  166. {
  167. "name": "test build",
  168. "image": tester_image(os),
  169. "volumes": build_step_volumes(os),
  170. "commands": test_commands(os, distro, name, isa, "100.0.0+${DRONE_COMMIT_SHA:0:8}"),
  171. "when": { "event": [ "push" ]},
  172. },
  173. {
  174. "name": "test release",
  175. "image": tester_image(os),
  176. "volumes": release_step_volumes(os),
  177. "commands": test_commands(os, distro, name, isa, "${DRONE_TAG}"),
  178. "when": { "event": [ "tag" ]},
  179. },
  180. ],
  181. "volumes": host_volumes(os),
  182. "platform": { "os": os, [ if isa == "arm64" || isa == "armv7" then "arch" ]: "arm64" },
  183. "depends_on": [ std.join(" ", [ name, "index" ]) ],
  184. "trigger": { "event": events }
  185. };
  186. local Index(p) = {
  187. "kind": "pipeline",
  188. "type": pipeline_type(p.os),
  189. "name": std.join(" ", [ p.name, "index" ]),
  190. "pull": "always",
  191. "clone": { "depth": 1 },
  192. "steps": [
  193. {
  194. "name": "index build",
  195. "image": index_image(p.distro),
  196. "commands": index_commands(p.os, "zerotier-builds", p.distro, p.name, p.isas),
  197. "volumes": build_step_volumes(p.os),
  198. "environment":{ "GPG_PRIVATE_KEY": { from_secret: "gpg-private-key" }},
  199. "when": { "event": [ "push" ]},
  200. },
  201. {
  202. "name": "index release",
  203. "image": index_image(p.distro),
  204. "commands": index_commands(p.os, "zerotier-releases", p.distro, p.name, p.isas),
  205. "volumes": release_step_volumes(p.os),
  206. "environment":{ "GPG_PRIVATE_KEY": { from_secret: "gpg-private-key" }},
  207. "when": { "event": [ "tag" ]},
  208. },
  209. ],
  210. "volumes": host_volumes(p.os),
  211. "platform": { "os": p.os },
  212. depends_on: std.flattenArrays([ [ std.join(" ", [ p.name, isa, "build" ]) ] for isa in p.isas ]),
  213. "trigger": { "event": p.events }
  214. };
  215. //
  216. // print
  217. //
  218. std.flattenArrays([
  219. [
  220. Build(p.os, p.distro, p.name, isa, p.events)
  221. for isa in p.isas
  222. ] +
  223. [
  224. Index(p)
  225. ]
  226. for p in native_targets
  227. ]) +
  228. std.flattenArrays([
  229. [
  230. Test(p.os, p.distro, p.name, isa, p.events)
  231. for isa in p.isas
  232. ]
  233. for p in native_targets
  234. ])