imageutils.py 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  1. import os
  2. from pathlib import Path
  3. import dagger
  4. _ALPINE_COMMON_PACKAGES = [
  5. "alpine-sdk",
  6. "autoconf",
  7. "automake",
  8. "bash",
  9. "binutils",
  10. "bison",
  11. "cmake",
  12. "curl",
  13. "curl-static",
  14. "elfutils-dev",
  15. "flex",
  16. "gcc",
  17. "git",
  18. "gnutls-dev",
  19. "gzip",
  20. "jq",
  21. "libelf-static",
  22. "libmnl-dev",
  23. "libmnl-static",
  24. "libtool",
  25. "libuv-dev",
  26. "libuv-static",
  27. "lz4-dev",
  28. "lz4-static",
  29. "make",
  30. "mongo-c-driver-dev",
  31. "mongo-c-driver-static",
  32. "musl-fts-dev",
  33. "ncurses",
  34. "ncurses-static",
  35. "netcat-openbsd",
  36. "ninja",
  37. "openssh",
  38. "pcre2-dev",
  39. "pkgconfig",
  40. "protobuf-dev",
  41. "snappy-dev",
  42. "snappy-static",
  43. "util-linux-dev",
  44. "wget",
  45. "xz",
  46. "yaml-dev",
  47. "yaml-static",
  48. "zlib-dev",
  49. "zlib-static",
  50. "zstd-dev",
  51. "zstd-static",
  52. ]
  53. def build_alpine_3_18(
  54. client: dagger.Client, platform: dagger.Platform
  55. ) -> dagger.Container:
  56. ctr = client.container(platform=platform).from_("alpine:3.18")
  57. pkgs = [pkg for pkg in _ALPINE_COMMON_PACKAGES]
  58. ctr = ctr.with_exec(["apk", "add", "--no-cache"] + pkgs)
  59. return ctr
  60. def build_alpine_3_19(
  61. client: dagger.Client, platform: dagger.Platform
  62. ) -> dagger.Container:
  63. ctr = client.container(platform=platform).from_("alpine:3.19")
  64. pkgs = [pkg for pkg in _ALPINE_COMMON_PACKAGES]
  65. ctr = ctr.with_exec(["apk", "add", "--no-cache"] + pkgs)
  66. return ctr
  67. def static_build_openssl(
  68. client: dagger.Client, ctr: dagger.Container
  69. ) -> dagger.Container:
  70. tree = (
  71. client.git(url="https://github.com/openssl/openssl", keep_git_dir=True)
  72. .tag("openssl-3.1.4")
  73. .tree()
  74. )
  75. #
  76. # TODO: verify 32-bit builds
  77. #
  78. ctr = (
  79. ctr.with_directory("/openssl", tree)
  80. .with_workdir("/openssl")
  81. .with_env_variable("CFLAGS", "-fno-lto -pipe")
  82. .with_env_variable("LDFLAGS", "-static")
  83. .with_env_variable("PKG_CONFIG", "pkg-config --static")
  84. .with_exec(
  85. [
  86. "sed",
  87. "-i",
  88. "s/disable('static', 'pic', 'threads');/disable('static', 'pic');/",
  89. "Configure",
  90. ]
  91. )
  92. .with_exec(
  93. [
  94. "./config",
  95. "-static",
  96. "threads",
  97. "no-tests",
  98. "--prefix=/openssl-static",
  99. "--openssldir=/opt/netdata/etc/ssl",
  100. ]
  101. )
  102. .with_exec(["make", "V=1", "-j", str(os.cpu_count())])
  103. .with_exec(["make", "V=1", "-j", str(os.cpu_count()), "install_sw"])
  104. .with_exec(["ln", "-s", "/openssl-static/lib", "/openssl-static/lib64"])
  105. .with_exec(["perl", "configdata.pm", "--dump"])
  106. )
  107. return ctr
  108. def static_build_bash(client: dagger.Client, ctr: dagger.Container) -> dagger.Container:
  109. tree = (
  110. client.git(url="https://git.savannah.gnu.org/git/bash.git", keep_git_dir=True)
  111. .tag("bash-5.1")
  112. .tree()
  113. )
  114. ctr = (
  115. ctr.with_directory("/bash", tree)
  116. .with_workdir("/bash")
  117. .with_env_variable("CFLAGS", "-pipe")
  118. .with_env_variable("LDFLAGS", "")
  119. .with_env_variable("PKG_CONFIG", "pkg-config --static")
  120. .with_env_variable("PKG_CONFIG_PATH", "/openssl-static/lib64/pkgconfig")
  121. .with_exec(
  122. [
  123. "./configure",
  124. "--prefix",
  125. "/opt/netdata",
  126. "--without-bash-malloc",
  127. "--enable-static-link",
  128. "--enable-net-redirections",
  129. "--enable-array-variables",
  130. "--disable-progcomp",
  131. "--disable-profiling",
  132. "--disable-nls",
  133. "--disable-dependency-tracking",
  134. ]
  135. )
  136. .with_exec(
  137. [
  138. "echo",
  139. "-e",
  140. "all:\nclean:\ninstall:\n",
  141. ">",
  142. "examples/loadables/Makefile",
  143. ]
  144. )
  145. .with_exec(["make", "clean"])
  146. # see: https://gitweb.gentoo.org/repo/gentoo.git/tree/app-shells/bash/files/bash-5.1-parallel_make.patch?id=4c2ebbf4b8bc660beb98cc2d845c73375d6e4f50
  147. .with_exec(["make", "V=1", "-j", "2", "install"])
  148. .with_exec(["strip", "/opt/netdata/bin/bash"])
  149. )
  150. return ctr
  151. def static_build_curl(client: dagger.Client, ctr: dagger.Container) -> dagger.Container:
  152. tree = (
  153. client.git(url="https://github.com/curl/curl", keep_git_dir=True)
  154. .tag("curl-8_4_0")
  155. .tree()
  156. )
  157. ctr = (
  158. ctr.with_directory("/curl", tree)
  159. .with_workdir("/curl")
  160. .with_env_variable("CFLAGS", "-I/openssl-static/include -pipe")
  161. .with_env_variable("LDFLAGS", "-static -L/openssl-static/lib64")
  162. .with_env_variable("PKG_CONFIG", "pkg-config --static")
  163. .with_env_variable("PKG_CONFIG_PATH", "/openssl-static/lib64/pkgconfig")
  164. .with_exec(["autoreconf", "-ifv"])
  165. .with_exec(
  166. [
  167. "./configure",
  168. "--prefix=/curl-static",
  169. "--enable-optimize",
  170. "--disable-shared",
  171. "--enable-static",
  172. "--enable-http",
  173. "--disable-ldap",
  174. "--disable-ldaps",
  175. "--enable-proxy",
  176. "--disable-dict",
  177. "--disable-telnet",
  178. "--disable-tftp",
  179. "--disable-pop3",
  180. "--disable-imap",
  181. "--disable-smb",
  182. "--disable-smtp",
  183. "--disable-gopher",
  184. "--enable-ipv6",
  185. "--enable-cookies",
  186. "--with-ca-fallback",
  187. "--with-openssl",
  188. "--disable-dependency-tracking",
  189. ]
  190. )
  191. .with_exec(
  192. ["sed", "-i", "-e", "s/LDFLAGS =/LDFLAGS = -all-static/", "src/Makefile"]
  193. )
  194. .with_exec(["make", "clean"])
  195. .with_exec(["make", "V=1", "-j", str(os.cpu_count()), "install"])
  196. .with_exec(["cp", "/curl-static/bin/curl", "/opt/netdata/bin/curl"])
  197. .with_exec(["strip", "/opt/netdata/bin/curl"])
  198. )
  199. return ctr
  200. def static_build_ioping(
  201. client: dagger.Client, ctr: dagger.Container
  202. ) -> dagger.Container:
  203. tree = (
  204. client.git(url="https://github.com/koct9i/ioping", keep_git_dir=True)
  205. .tag("v1.3")
  206. .tree()
  207. )
  208. ctr = (
  209. ctr.with_directory("/ioping", tree)
  210. .with_workdir("/ioping")
  211. .with_env_variable("CFLAGS", "-static -pipe")
  212. .with_exec(["mkdir", "-p", "/opt/netdata/usr/libexec/netdata/plugins.d"])
  213. .with_exec(["make", "V=1"])
  214. .with_exec(
  215. [
  216. "install",
  217. "-o",
  218. "root",
  219. "-g",
  220. "root",
  221. "-m",
  222. "4750",
  223. "ioping",
  224. "/opt/netdata/usr/libexec/netdata/plugins.d",
  225. ]
  226. )
  227. .with_exec(["strip", "/opt/netdata/usr/libexec/netdata/plugins.d/ioping"])
  228. )
  229. return ctr
  230. def static_build_libnetfilter_acct(
  231. client: dagger.Client, ctr: dagger.Container
  232. ) -> dagger.Container:
  233. tree = (
  234. client.git(url="git://git.netfilter.org/libnetfilter_acct", keep_git_dir=True)
  235. .tag("libnetfilter_acct-1.0.3")
  236. .tree()
  237. )
  238. ctr = (
  239. ctr.with_directory("/libnetfilter_acct", tree)
  240. .with_workdir("/libnetfilter_acct")
  241. .with_env_variable("CFLAGS", "-static -I/usr/include/libmnl -pipe")
  242. .with_env_variable("LDFLAGS", "-static -L/usr/lib -lmnl")
  243. .with_env_variable("PKG_CONFIG", "pkg-config --static")
  244. .with_env_variable("PKG_CONFIG_PATH", "/usr/lib/pkgconfig")
  245. .with_exec(["autoreconf", "-ifv"])
  246. .with_exec(
  247. [
  248. "./configure",
  249. "--prefix=/libnetfilter_acct-static",
  250. "--exec-prefix=/libnetfilter_acct-static",
  251. ]
  252. )
  253. .with_exec(["make", "clean"])
  254. .with_exec(["make", "V=1", "-j", str(os.cpu_count()), "install"])
  255. )
  256. return ctr
  257. def static_build_netdata(
  258. client: dagger.Client, ctr: dagger.Container
  259. ) -> dagger.Container:
  260. CFLAGS = [
  261. "-ffunction-sections",
  262. "-fdata-sections",
  263. "-static",
  264. "-O2",
  265. "-funroll-loops",
  266. "-I/openssl-static/include",
  267. "-I/libnetfilter_acct-static/include/libnetfilter_acct",
  268. "-I/curl-local/include/curl",
  269. "-I/usr/include/libmnl",
  270. "-pipe",
  271. ]
  272. LDFLAGS = [
  273. "-Wl,--gc-sections",
  274. "-static",
  275. "-L/openssl-static/lib64",
  276. "-L/libnetfilter_acct-static/lib",
  277. "-lnetfilter_acct",
  278. "-L/usr/lib",
  279. "-lmnl",
  280. "-L/usr/lib",
  281. "-lzstd",
  282. "-L/curl-local/lib",
  283. ]
  284. PKG_CONFIG = [
  285. "pkg-config",
  286. "--static",
  287. ]
  288. PKG_CONFIG_PATH = [
  289. "/openssl-static/lib64/pkgconfig",
  290. "/libnetfilter_acct-static/lib/pkgconfig",
  291. "/usr/lib/pkgconfig",
  292. "/curl-local/lib/pkgconfig",
  293. ]
  294. CMAKE_FLAGS = [
  295. "-DOPENSSL_ROOT_DIR=/openssl-static",
  296. "-DOPENSSL_LIBRARIES=/openssl-static/lib64",
  297. "-DCMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE=/openssl-static",
  298. "-DLWS_OPENSSL_INCLUDE_DIRS=/openssl-static/include",
  299. "-DLWS_OPENSSL_LIBRARIES=/openssl-static/lib64/libssl.a;/openssl-static/lib64/libcrypto.a",
  300. ]
  301. NETDATA_INSTALLER_CMD = [
  302. "./netdata-installer.sh",
  303. "--install-prefix",
  304. "/opt",
  305. "--dont-wait",
  306. "--dont-start-it",
  307. "--disable-exporting-mongodb",
  308. "--require-cloud",
  309. "--use-system-protobuf",
  310. "--dont-scrub-cflags-even-though-it-may-break-things",
  311. "--one-time-build",
  312. "--enable-lto",
  313. ]
  314. ctr = (
  315. ctr.with_workdir("/netdata")
  316. .with_env_variable("NETDATA_CMAKE_OPTIONS", "-DCMAKE_BUILD_TYPE=Debug")
  317. .with_env_variable("CFLAGS", " ".join(CFLAGS))
  318. .with_env_variable("LDFLAGS", " ".join(LDFLAGS))
  319. .with_env_variable("PKG_CONFIG", " ".join(PKG_CONFIG))
  320. .with_env_variable("PKG_CONFIG_PATH", ":".join(PKG_CONFIG_PATH))
  321. .with_env_variable("CMAKE_FLAGS", " ".join(CMAKE_FLAGS))
  322. .with_env_variable("EBPF_LIBC", "static")
  323. .with_env_variable("IS_NETDATA_STATIC_BINARY", "yes")
  324. .with_exec(NETDATA_INSTALLER_CMD)
  325. )
  326. return ctr
  327. def static_build(client, repo_path):
  328. cmake_build_release_path = os.path.join(repo_path, "cmake-build-release")
  329. ctr = build_alpine_3_18(client, dagger.Platform("linux/x86_64"))
  330. ctr = static_build_openssl(client, ctr)
  331. ctr = static_build_bash(client, ctr)
  332. ctr = static_build_curl(client, ctr)
  333. ctr = static_build_ioping(client, ctr)
  334. ctr = static_build_libnetfilter_acct(client, ctr)
  335. ctr = ctr.with_directory(
  336. "/netdata",
  337. client.host().directory(repo_path),
  338. exclude=[
  339. f"{cmake_build_release_path}/*",
  340. "fluent-bit/build",
  341. ],
  342. )
  343. # TODO: link bin/sbin
  344. ctr = static_build_netdata(client, ctr)
  345. build_dir = ctr.directory("/opt/netdata")
  346. artifact_dir = os.path.join(Path.home(), "ci/netdata-static")
  347. output_task = build_dir.export(artifact_dir)
  348. return output_task
  349. _CENTOS_COMMON_PACKAGES = [
  350. "autoconf",
  351. "autoconf-archive",
  352. "autogen",
  353. "automake",
  354. "bison",
  355. "bison-devel",
  356. "cmake",
  357. "cups-devel",
  358. "curl",
  359. "diffutils",
  360. "elfutils-libelf-devel",
  361. "findutils",
  362. "flex",
  363. "flex-devel",
  364. "freeipmi-devel",
  365. "gcc",
  366. "gcc-c++",
  367. "git-core",
  368. "golang",
  369. "json-c-devel",
  370. "libyaml-devel",
  371. "libatomic",
  372. "libcurl-devel",
  373. "libmnl-devel",
  374. "libnetfilter_acct-devel",
  375. "libtool",
  376. "libuuid-devel",
  377. "libuv-devel",
  378. "libzstd-devel",
  379. "lm_sensors",
  380. "lz4-devel",
  381. "make",
  382. "ninja-build",
  383. "openssl-devel",
  384. "openssl-perl",
  385. "patch",
  386. "pcre2-devel",
  387. "pkgconfig",
  388. "pkgconfig(libmongoc-1.0)",
  389. "procps",
  390. "protobuf-c-devel",
  391. "protobuf-compiler",
  392. "protobuf-devel",
  393. "rpm-build",
  394. "rpm-devel",
  395. "rpmdevtools",
  396. "snappy-devel",
  397. "systemd-devel",
  398. "wget",
  399. "zlib-devel",
  400. ]
  401. def build_amazon_linux_2(
  402. client: dagger.Client, platform: dagger.Platform
  403. ) -> dagger.Container:
  404. ctr = client.container(platform=platform).from_("amazonlinux:2")
  405. pkgs = [pkg for pkg in _CENTOS_COMMON_PACKAGES]
  406. ctr = (
  407. ctr.with_exec(["yum", "update", "-y"])
  408. .with_exec(["yum", "install", "-y"] + pkgs)
  409. .with_exec(["yum", "clean", "all"])
  410. .with_exec(["c_rehash"])
  411. .with_exec(
  412. [
  413. "mkdir",
  414. "-p",
  415. "/root/rpmbuild/BUILD",
  416. "/root/rpmbuild/RPMS",
  417. "/root/rpmbuild/SOURCES",
  418. "/root/rpmbuild/SPECS",
  419. "/root/rpmbuild/SRPMS",
  420. ]
  421. )
  422. )
  423. if platform == "linux/x86_64":
  424. machine = "x86_64"
  425. elif platform == "linux/arm64":
  426. machine = "aarch64"
  427. else:
  428. raise Exception(
  429. "Amaxon Linux 2 supports only linux/amd64 and linux/arm64 platforms."
  430. )
  431. checksum_path = Path(__file__).parent / f"files/cmake-{machine}.sha256"
  432. ctr = (
  433. ctr.with_file(
  434. f"cmake-{machine}.sha256",
  435. client.host().file(checksum_path.as_posix()),
  436. )
  437. .with_exec(
  438. [
  439. "curl",
  440. "--fail",
  441. "-sSL",
  442. "--connect-timeout",
  443. "20",
  444. "--retry",
  445. "3",
  446. "--output",
  447. f"cmake-{machine}.sh",
  448. f"https://github.com/Kitware/CMake/releases/download/v3.27.6/cmake-3.27.6-linux-{machine}.sh",
  449. ]
  450. )
  451. .with_exec(["sha256sum", "-c", f"cmake-{machine}.sha256"])
  452. .with_exec(["chmod", "u+x", f"./cmake-{machine}.sh"])
  453. .with_exec([f"./cmake-{machine}.sh", "--skip-license", "--prefix=/usr/local"])
  454. )
  455. return ctr
  456. def build_centos_7(
  457. client: dagger.Client, platform: dagger.Platform
  458. ) -> dagger.Container:
  459. ctr = client.container(platform=platform).from_("centos:7")
  460. pkgs = [pkg for pkg in _CENTOS_COMMON_PACKAGES] + ["bash"]
  461. ctr = (
  462. ctr.with_exec(["yum", "install", "-y", "epel-release"])
  463. .with_exec(["yum", "update", "-y"])
  464. .with_exec(["yum", "install", "-y"] + pkgs)
  465. .with_exec(["yum", "clean", "all"])
  466. .with_exec(["c_rehash"])
  467. .with_exec(
  468. [
  469. "mkdir",
  470. "-p",
  471. "/root/rpmbuild/BUILD",
  472. "/root/rpmbuild/RPMS",
  473. "/root/rpmbuild/SOURCES",
  474. "/root/rpmbuild/SPECS",
  475. "/root/rpmbuild/SRPMS",
  476. ]
  477. )
  478. )
  479. if platform == "linux/x86_64":
  480. machine = "x86_64"
  481. elif platform == "linux/arm64":
  482. machine = "aarch64"
  483. else:
  484. raise Exception("CentOS 7 supports only linux/amd64 and linux/arm64 platforms.")
  485. checksum_path = Path(__file__).parent / f"files/cmake-{machine}.sha256"
  486. ctr = (
  487. ctr.with_file(
  488. f"cmake-{machine}.sha256",
  489. client.host().file(checksum_path.as_posix()),
  490. )
  491. .with_exec(
  492. [
  493. "curl",
  494. "--fail",
  495. "-sSL",
  496. "--connect-timeout",
  497. "20",
  498. "--retry",
  499. "3",
  500. "--output",
  501. f"cmake-{machine}.sh",
  502. f"https://github.com/Kitware/CMake/releases/download/v3.27.6/cmake-3.27.6-linux-{machine}.sh",
  503. ]
  504. )
  505. .with_exec(["sha256sum", "-c", f"cmake-{machine}.sha256"])
  506. .with_exec(["chmod", "u+x", f"./cmake-{machine}.sh"])
  507. .with_exec([f"./cmake-{machine}.sh", "--skip-license", "--prefix=/usr/local"])
  508. )
  509. return ctr
  510. _ROCKY_LINUX_COMMON_PACKAGES = [
  511. "autoconf",
  512. "autoconf-archive",
  513. "automake",
  514. "bash",
  515. "bison",
  516. "cmake",
  517. "cups-devel",
  518. "curl",
  519. "libcurl-devel",
  520. "diffutils",
  521. "elfutils-libelf-devel",
  522. "findutils",
  523. "flex",
  524. "freeipmi-devel",
  525. "gcc",
  526. "gcc-c++",
  527. "git",
  528. "golang",
  529. "json-c-devel",
  530. "libatomic",
  531. "libmnl-devel",
  532. "libtool",
  533. "libuuid-devel",
  534. "libuv-devel",
  535. "libyaml-devel",
  536. "libzstd-devel",
  537. "lm_sensors",
  538. "lz4-devel",
  539. "make",
  540. "ninja-build",
  541. "nc",
  542. "openssl-devel",
  543. "openssl-perl",
  544. "patch",
  545. "pcre2-devel",
  546. "pkgconfig",
  547. "pkgconfig(libmongoc-1.0)",
  548. "procps",
  549. "protobuf-c-devel",
  550. "protobuf-compiler",
  551. "protobuf-devel",
  552. "python3",
  553. "python3-pyyaml",
  554. "rpm-build",
  555. "rpm-devel",
  556. "rpmdevtools",
  557. "snappy-devel",
  558. "systemd-devel",
  559. "wget",
  560. "zlib-devel",
  561. ]
  562. def build_rocky_linux_8(
  563. client: dagger.Client, platform: dagger.Platform
  564. ) -> dagger.Container:
  565. ctr = client.container(platform=platform).from_("rockylinux:8")
  566. pkgs = [pkg for pkg in _ROCKY_LINUX_COMMON_PACKAGES] + ["autogen"]
  567. ctr = (
  568. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  569. .with_exec(
  570. [
  571. "dnf",
  572. "install",
  573. "-y",
  574. "--nodocs",
  575. "dnf-command(config-manager)",
  576. "epel-release",
  577. ]
  578. )
  579. .with_exec(["dnf", "config-manager", "--set-enabled", "powertools"])
  580. .with_exec(["dnf", "clean", "packages"])
  581. .with_exec(
  582. [
  583. "dnf",
  584. "install",
  585. "-y",
  586. "--nodocs",
  587. "--setopt=install_weak_deps=False",
  588. "--setopt=diskspacecheck=False",
  589. ]
  590. + pkgs
  591. )
  592. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  593. .with_exec(["c_rehash"])
  594. .with_exec(
  595. [
  596. "mkdir",
  597. "-p",
  598. "/root/rpmbuild/BUILD",
  599. "/root/rpmbuild/RPMS",
  600. "/root/rpmbuild/SOURCES",
  601. "/root/rpmbuild/SPECS",
  602. "/root/rpmbuild/SRPMS",
  603. ]
  604. )
  605. )
  606. return ctr
  607. def build_rocky_linux_9(
  608. client: dagger.Client, platform: dagger.Platform
  609. ) -> dagger.Container:
  610. ctr = client.container(platform=platform).from_("rockylinux:9")
  611. pkgs = [pkg for pkg in _ROCKY_LINUX_COMMON_PACKAGES]
  612. ctr = (
  613. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  614. .with_exec(
  615. [
  616. "dnf",
  617. "install",
  618. "-y",
  619. "--nodocs",
  620. "dnf-command(config-manager)",
  621. "epel-release",
  622. ]
  623. )
  624. .with_exec(["dnf", "config-manager", "--set-enabled", "crb"])
  625. .with_exec(["dnf", "clean", "packages"])
  626. .with_exec(
  627. [
  628. "dnf",
  629. "install",
  630. "-y",
  631. "--allowerasing",
  632. "--nodocs",
  633. "--setopt=install_weak_deps=False",
  634. "--setopt=diskspacecheck=False",
  635. ]
  636. + pkgs
  637. )
  638. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  639. .with_exec(["c_rehash"])
  640. .with_exec(
  641. [
  642. "mkdir",
  643. "-p",
  644. "/root/rpmbuild/BUILD",
  645. "/root/rpmbuild/RPMS",
  646. "/root/rpmbuild/SOURCES",
  647. "/root/rpmbuild/SPECS",
  648. "/root/rpmbuild/SRPMS",
  649. ]
  650. )
  651. )
  652. return ctr
  653. _CENTOS_STREAM_COMMON_PACKAGES = [
  654. "autoconf",
  655. "autoconf-archive",
  656. "automake",
  657. "bash",
  658. "bison",
  659. "cmake",
  660. "cups-devel",
  661. "curl",
  662. "libcurl-devel",
  663. "libyaml-devel",
  664. "diffutils",
  665. "elfutils-libelf-devel",
  666. "findutils",
  667. "flex",
  668. "freeipmi-devel",
  669. "gcc",
  670. "gcc-c++",
  671. "git",
  672. "golang",
  673. "json-c-devel",
  674. "libatomic",
  675. "libmnl-devel",
  676. "libtool",
  677. "libuuid-devel",
  678. "libuv-devel",
  679. # "libzstd-devel",
  680. "lm_sensors",
  681. "lz4-devel",
  682. "make",
  683. "ninja-build",
  684. "nc",
  685. "openssl-devel",
  686. "openssl-perl",
  687. "patch",
  688. "pcre2-devel",
  689. "pkgconfig",
  690. "pkgconfig(libmongoc-1.0)",
  691. "procps",
  692. "protobuf-c-devel",
  693. "protobuf-compiler",
  694. "protobuf-devel",
  695. "python3",
  696. "python3-pyyaml",
  697. "rpm-build",
  698. "rpm-devel",
  699. "rpmdevtools",
  700. "snappy-devel",
  701. "systemd-devel",
  702. "wget",
  703. "zlib-devel",
  704. ]
  705. def build_centos_stream_8(
  706. client: dagger.Client, platform: dagger.Platform
  707. ) -> dagger.Container:
  708. ctr = client.container(platform=platform).from_("quay.io/centos/centos:stream8")
  709. pkgs = [pkg for pkg in _CENTOS_STREAM_COMMON_PACKAGES] + ["autogen"]
  710. ctr = (
  711. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  712. .with_exec(
  713. [
  714. "dnf",
  715. "install",
  716. "-y",
  717. "--nodocs",
  718. "dnf-command(config-manager)",
  719. "epel-release",
  720. ]
  721. )
  722. .with_exec(["dnf", "config-manager", "--set-enabled", "powertools"])
  723. .with_exec(["dnf", "clean", "packages"])
  724. .with_exec(
  725. [
  726. "dnf",
  727. "install",
  728. "-y",
  729. "--nodocs",
  730. "--setopt=install_weak_deps=False",
  731. "--setopt=diskspacecheck=False",
  732. ]
  733. + pkgs
  734. )
  735. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  736. .with_exec(["c_rehash"])
  737. .with_exec(
  738. [
  739. "mkdir",
  740. "-p",
  741. "/root/rpmbuild/BUILD",
  742. "/root/rpmbuild/RPMS",
  743. "/root/rpmbuild/SOURCES",
  744. "/root/rpmbuild/SPECS",
  745. "/root/rpmbuild/SRPMS",
  746. ]
  747. )
  748. )
  749. return ctr
  750. def build_centos_stream_9(
  751. client: dagger.Client, platform: dagger.Platform
  752. ) -> dagger.Container:
  753. ctr = client.container(platform=platform).from_("quay.io/centos/centos:stream9")
  754. pkgs = [pkg for pkg in _CENTOS_STREAM_COMMON_PACKAGES]
  755. ctr = (
  756. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  757. .with_exec(
  758. [
  759. "dnf",
  760. "install",
  761. "-y",
  762. "--nodocs",
  763. "dnf-command(config-manager)",
  764. "epel-release",
  765. ]
  766. )
  767. .with_exec(["dnf", "config-manager", "--set-enabled", "crb"])
  768. .with_exec(["dnf", "clean", "packages"])
  769. .with_exec(
  770. [
  771. "dnf",
  772. "install",
  773. "-y",
  774. "--allowerasing",
  775. "--nodocs",
  776. "--setopt=install_weak_deps=False",
  777. "--setopt=diskspacecheck=False",
  778. ]
  779. + pkgs
  780. )
  781. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  782. .with_exec(["c_rehash"])
  783. .with_exec(
  784. [
  785. "mkdir",
  786. "-p",
  787. "/root/rpmbuild/BUILD",
  788. "/root/rpmbuild/RPMS",
  789. "/root/rpmbuild/SOURCES",
  790. "/root/rpmbuild/SPECS",
  791. "/root/rpmbuild/SRPMS",
  792. ]
  793. )
  794. )
  795. return ctr
  796. _ORACLE_LINUX_COMMON_PACKAGES = list(_ROCKY_LINUX_COMMON_PACKAGES)
  797. def build_oracle_linux_9(
  798. client: dagger.Client, platform: dagger.Platform
  799. ) -> dagger.Container:
  800. ctr = client.container(platform=platform).from_("oraclelinux:9")
  801. pkgs = [pkg for pkg in _ORACLE_LINUX_COMMON_PACKAGES]
  802. repo_path = str(Path(__file__).parent.parent.parent)
  803. this_path = os.path.join(repo_path, "packaging/dag")
  804. ctr = (
  805. ctr.with_file(
  806. "/etc/yum.repos.d/ol9-epel.repo",
  807. client.host().file(f"{this_path}/ol9-epel.repo"),
  808. )
  809. .with_exec(["dnf", "config-manager", "--set-enabled", "ol9_codeready_builder"])
  810. .with_exec(["dnf", "config-manager", "--set-enabled", "ol9_developer_EPEL"])
  811. .with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  812. .with_exec(["dnf", "clean", "-y", "packages"])
  813. .with_exec(
  814. [
  815. "dnf",
  816. "install",
  817. "-y",
  818. "--nodocs",
  819. "--setopt=install_weak_deps=False",
  820. "--setopt=diskspacecheck=False",
  821. ]
  822. + pkgs
  823. )
  824. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  825. .with_exec(["c_rehash"])
  826. .with_exec(
  827. [
  828. "mkdir",
  829. "-p",
  830. "/root/rpmbuild/BUILD",
  831. "/root/rpmbuild/RPMS",
  832. "/root/rpmbuild/SOURCES",
  833. "/root/rpmbuild/SPECS",
  834. "/root/rpmbuild/SRPMS",
  835. ]
  836. )
  837. )
  838. return ctr
  839. def build_oracle_linux_8(
  840. client: dagger.Client, platform: dagger.Platform
  841. ) -> dagger.Container:
  842. ctr = client.container(platform=platform).from_("oraclelinux:8")
  843. pkgs = [pkg for pkg in _ORACLE_LINUX_COMMON_PACKAGES] + ["autogen"]
  844. repo_path = str(Path(__file__).parent.parent.parent)
  845. this_path = os.path.join(repo_path, "packaging/dag")
  846. ctr = (
  847. ctr.with_file(
  848. "/etc/yum.repos.d/ol8-epel.repo",
  849. client.host().file(f"{this_path}/ol8-epel.repo"),
  850. )
  851. .with_exec(["dnf", "config-manager", "--set-enabled", "ol8_codeready_builder"])
  852. .with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  853. .with_exec(["dnf", "clean", "-y", "packages"])
  854. .with_exec(
  855. [
  856. "dnf",
  857. "install",
  858. "-y",
  859. "--nodocs",
  860. "--setopt=install_weak_deps=False",
  861. "--setopt=diskspacecheck=False",
  862. ]
  863. + pkgs
  864. )
  865. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  866. .with_exec(["c_rehash"])
  867. .with_exec(
  868. [
  869. "mkdir",
  870. "-p",
  871. "/root/rpmbuild/BUILD",
  872. "/root/rpmbuild/RPMS",
  873. "/root/rpmbuild/SOURCES",
  874. "/root/rpmbuild/SPECS",
  875. "/root/rpmbuild/SRPMS",
  876. ]
  877. )
  878. )
  879. return ctr
  880. _OPENSUSE_COMMON_PACKAGES = [
  881. "autoconf",
  882. "autoconf-archive",
  883. "autogen",
  884. "automake",
  885. "bison",
  886. "cmake",
  887. "cups",
  888. "cups-devel",
  889. "curl",
  890. "diffutils",
  891. "flex",
  892. "freeipmi-devel",
  893. "gcc",
  894. "gcc-c++",
  895. "git-core",
  896. "go",
  897. "json-glib-devel",
  898. "judy-devel",
  899. "libatomic1",
  900. "libcurl-devel",
  901. "libelf-devel",
  902. "liblz4-devel",
  903. "libjson-c-devel",
  904. "libyaml-devel",
  905. "libmnl0",
  906. "libmnl-devel",
  907. "libnetfilter_acct1",
  908. "libnetfilter_acct-devel",
  909. "libpcre2-8-0",
  910. "libopenssl-devel",
  911. "libtool",
  912. "libuv-devel",
  913. "libuuid-devel",
  914. "libzstd-devel",
  915. "make",
  916. "ninja",
  917. "patch",
  918. "pkg-config",
  919. "protobuf-devel",
  920. "rpm-build",
  921. "rpm-devel",
  922. "rpmdevtools",
  923. "snappy-devel",
  924. "systemd-devel",
  925. "tar",
  926. "wget",
  927. "xen-devel",
  928. ]
  929. def build_opensuse_tumbleweed(
  930. client: dagger.Client, platform: dagger.Platform
  931. ) -> dagger.Container:
  932. ctr = client.container(platform=platform).from_("opensuse/tumbleweed:latest")
  933. pkgs = [pkg for pkg in _OPENSUSE_COMMON_PACKAGES] + ["protobuf-c"]
  934. ctr = (
  935. ctr.with_exec(["zypper", "update", "-y"])
  936. .with_exec(
  937. [
  938. "zypper",
  939. "install",
  940. "-y",
  941. "--allow-downgrade",
  942. ]
  943. + pkgs
  944. )
  945. .with_exec(["zypper", "clean"])
  946. .with_exec(["rm", "-rf", "/var/cache/zypp/*/*"])
  947. .with_exec(["c_rehash"])
  948. .with_exec(
  949. [
  950. "mkdir",
  951. "-p",
  952. "/usr/src/packages/BUILD",
  953. "/usr/src/packages/RPMS",
  954. "/usr/src/packages/SOURCES",
  955. "/usr/src/packages/SPECS",
  956. "/usr/src/packages/SRPMS",
  957. ]
  958. )
  959. )
  960. return ctr
  961. def build_opensuse_15_5(
  962. client: dagger.Client, platform: dagger.Platform
  963. ) -> dagger.Container:
  964. ctr = client.container(platform=platform).from_("opensuse/leap:15.5")
  965. pkgs = [pkg for pkg in _OPENSUSE_COMMON_PACKAGES] + ["libprotobuf-c-devel"]
  966. ctr = (
  967. ctr.with_exec(["zypper", "update", "-y"])
  968. .with_exec(
  969. [
  970. "zypper",
  971. "install",
  972. "-y",
  973. "--allow-downgrade",
  974. ]
  975. + pkgs
  976. )
  977. .with_exec(["zypper", "clean"])
  978. .with_exec(["rm", "-rf", "/var/cache/zypp/*/*"])
  979. .with_exec(["c_rehash"])
  980. .with_exec(
  981. [
  982. "mkdir",
  983. "-p",
  984. "/usr/src/packages/BUILD",
  985. "/usr/src/packages/RPMS",
  986. "/usr/src/packages/SOURCES",
  987. "/usr/src/packages/SPECS",
  988. "/usr/src/packages/SRPMS",
  989. ]
  990. )
  991. )
  992. return ctr
  993. def build_opensuse_15_4(
  994. client: dagger.Client, platform: dagger.Platform
  995. ) -> dagger.Container:
  996. crt = client.container(platform=platform).from_("opensuse/leap:15.4")
  997. pkgs = [pkg for pkg in _OPENSUSE_COMMON_PACKAGES] + ["libprotobuf-c-devel"]
  998. crt = (
  999. crt.with_exec(["zypper", "update", "-y"])
  1000. .with_exec(
  1001. [
  1002. "zypper",
  1003. "install",
  1004. "-y",
  1005. "--allow-downgrade",
  1006. ]
  1007. + pkgs
  1008. )
  1009. .with_exec(["zypper", "clean"])
  1010. .with_exec(["rm", "-rf", "/var/cache/zypp/*/*"])
  1011. .with_exec(["c_rehash"])
  1012. .with_exec(
  1013. [
  1014. "mkdir",
  1015. "-p",
  1016. "/usr/src/packages/BUILD",
  1017. "/usr/src/packages/RPMS",
  1018. "/usr/src/packages/SOURCES",
  1019. "/usr/src/packages/SPECS",
  1020. "/usr/src/packages/SRPMS",
  1021. ]
  1022. )
  1023. )
  1024. return crt
  1025. _FEDORA_COMMON_PACKAGES = [
  1026. "autoconf",
  1027. "autoconf-archive",
  1028. "autogen",
  1029. "automake",
  1030. "bash",
  1031. "bison",
  1032. "cmake",
  1033. "cups-devel",
  1034. "curl",
  1035. "diffutils",
  1036. "elfutils-libelf-devel",
  1037. "findutils",
  1038. "flex",
  1039. "freeipmi-devel",
  1040. "gcc",
  1041. "gcc-c++",
  1042. "git-core",
  1043. "golang",
  1044. "json-c-devel",
  1045. "libcurl-devel",
  1046. "libyaml-devel",
  1047. "Judy-devel",
  1048. "libatomic",
  1049. "libmnl-devel",
  1050. "libnetfilter_acct-devel",
  1051. "libtool",
  1052. "libuuid-devel",
  1053. "libuv-devel",
  1054. "libzstd-devel",
  1055. "lz4-devel",
  1056. "make",
  1057. "ninja-build",
  1058. "openssl-devel",
  1059. "openssl-perl",
  1060. "patch",
  1061. "pcre2-devel",
  1062. "pkgconfig",
  1063. ]
  1064. def build_fedora_37(
  1065. client: dagger.Client, platform: dagger.Platform
  1066. ) -> dagger.Container:
  1067. ctr = client.container(platform=platform).from_("fedora:37")
  1068. pkgs = [pkg for pkg in _FEDORA_COMMON_PACKAGES]
  1069. ctr = (
  1070. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  1071. .with_exec(["dnf", "clean", "-y", "packages"])
  1072. .with_exec(
  1073. [
  1074. "dnf",
  1075. "install",
  1076. "-y",
  1077. "--nodocs",
  1078. "--setopt=install_weak_deps=False",
  1079. "--setopt=diskspacecheck=False",
  1080. ]
  1081. + pkgs
  1082. )
  1083. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  1084. .with_exec(["c_rehash"])
  1085. .with_exec(
  1086. [
  1087. "mkdir",
  1088. "-p",
  1089. "/root/rpmbuild/BUILD",
  1090. "/root/rpmbuild/RPMS",
  1091. "/root/rpmbuild/SOURCES",
  1092. "/root/rpmbuild/SPECS",
  1093. "/root/rpmbuild/SRPMS",
  1094. ]
  1095. )
  1096. )
  1097. return ctr
  1098. def build_fedora_38(
  1099. client: dagger.Client, platform: dagger.Platform
  1100. ) -> dagger.Container:
  1101. ctr = client.container(platform=platform).from_("fedora:38")
  1102. pkgs = [pkg for pkg in _FEDORA_COMMON_PACKAGES]
  1103. ctr = (
  1104. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  1105. .with_exec(["dnf", "clean", "-y", "packages"])
  1106. .with_exec(
  1107. [
  1108. "dnf",
  1109. "install",
  1110. "-y",
  1111. "--nodocs",
  1112. "--setopt=install_weak_deps=False",
  1113. "--setopt=diskspacecheck=False",
  1114. ]
  1115. + pkgs
  1116. )
  1117. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  1118. .with_exec(["c_rehash"])
  1119. .with_exec(
  1120. [
  1121. "mkdir",
  1122. "-p",
  1123. "/root/rpmbuild/BUILD",
  1124. "/root/rpmbuild/RPMS",
  1125. "/root/rpmbuild/SOURCES",
  1126. "/root/rpmbuild/SPECS",
  1127. "/root/rpmbuild/SRPMS",
  1128. ]
  1129. )
  1130. )
  1131. return ctr
  1132. def build_fedora_39(
  1133. client: dagger.Client, platform: dagger.Platform
  1134. ) -> dagger.Container:
  1135. ctr = client.container(platform=platform).from_("fedora:39")
  1136. pkgs = [pkg for pkg in _FEDORA_COMMON_PACKAGES]
  1137. ctr = (
  1138. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  1139. .with_exec(["dnf", "clean", "-y", "packages"])
  1140. .with_exec(
  1141. [
  1142. "dnf",
  1143. "install",
  1144. "-y",
  1145. "--nodocs",
  1146. "--setopt=install_weak_deps=False",
  1147. "--setopt=diskspacecheck=False",
  1148. ]
  1149. + pkgs
  1150. )
  1151. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  1152. .with_exec(["c_rehash"])
  1153. .with_exec(
  1154. [
  1155. "mkdir",
  1156. "-p",
  1157. "/root/rpmbuild/BUILD",
  1158. "/root/rpmbuild/RPMS",
  1159. "/root/rpmbuild/SOURCES",
  1160. "/root/rpmbuild/SPECS",
  1161. "/root/rpmbuild/SRPMS",
  1162. ]
  1163. )
  1164. )
  1165. return ctr
  1166. _DEBIAN_COMMON_PACKAGES = [
  1167. "autoconf",
  1168. "autoconf-archive",
  1169. "autogen",
  1170. "automake",
  1171. "bison",
  1172. "build-essential",
  1173. "ca-certificates",
  1174. "cmake",
  1175. "curl",
  1176. "dh-autoreconf",
  1177. "dh-make",
  1178. "dpkg-dev",
  1179. "flex",
  1180. "g++",
  1181. "gcc",
  1182. "git-buildpackage",
  1183. "git-core",
  1184. "golang",
  1185. "libatomic1",
  1186. "libcurl4-openssl-dev",
  1187. "libcups2-dev",
  1188. "libdistro-info-perl",
  1189. "libelf-dev",
  1190. "libipmimonitoring-dev",
  1191. "libjson-c-dev",
  1192. "libyaml-dev",
  1193. "libjudy-dev",
  1194. "liblz4-dev",
  1195. "libmnl-dev",
  1196. "libmongoc-dev",
  1197. "libnetfilter-acct-dev",
  1198. "libpcre2-dev",
  1199. "libprotobuf-dev",
  1200. "libprotoc-dev",
  1201. "libsnappy-dev",
  1202. "libsystemd-dev",
  1203. "libssl-dev",
  1204. "libtool",
  1205. "libuv1-dev",
  1206. "libzstd-dev",
  1207. "make",
  1208. "ninja-build",
  1209. "pkg-config",
  1210. "protobuf-compiler",
  1211. "systemd",
  1212. "uuid-dev",
  1213. "wget",
  1214. "zlib1g-dev",
  1215. ]
  1216. def build_debian_10(
  1217. client: dagger.Client, platform: dagger.Platform
  1218. ) -> dagger.Container:
  1219. ctr = client.container(platform=platform).from_("debian:buster")
  1220. pkgs = [pkg for pkg in _DEBIAN_COMMON_PACKAGES] + ["dh-systemd", "libxen-dev"]
  1221. ctr = (
  1222. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1223. .with_exec(["apt-get", "update"])
  1224. .with_exec(["apt-get", "upgrade", "-y"])
  1225. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1226. .with_exec(["apt-get", "clean"])
  1227. .with_exec(["c_rehash"])
  1228. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1229. )
  1230. return ctr
  1231. def build_debian_11(
  1232. client: dagger.Client, platform: dagger.Platform
  1233. ) -> dagger.Container:
  1234. ctr = client.container(platform=platform).from_("debian:bullseye")
  1235. pkgs = [pkg for pkg in _DEBIAN_COMMON_PACKAGES] + ["libxen-dev"]
  1236. ctr = (
  1237. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1238. .with_exec(["apt-get", "update"])
  1239. .with_exec(["apt-get", "upgrade", "-y"])
  1240. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1241. .with_exec(["apt-get", "clean"])
  1242. .with_exec(["c_rehash"])
  1243. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1244. )
  1245. return ctr
  1246. def build_debian_12(
  1247. client: dagger.Client, platform: dagger.Platform
  1248. ) -> dagger.Container:
  1249. ctr = client.container(platform=platform).from_("debian:bookworm")
  1250. pkgs = [pkg for pkg in _DEBIAN_COMMON_PACKAGES]
  1251. if platform != dagger.Platform("linux/i386"):
  1252. pkgs.append("libxen-dev")
  1253. ctr = (
  1254. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1255. .with_exec(["apt-get", "update"])
  1256. .with_exec(["apt-get", "upgrade", "-y"])
  1257. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1258. .with_exec(["apt-get", "clean"])
  1259. .with_exec(["c_rehash"])
  1260. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1261. )
  1262. return ctr
  1263. _UBUNTU_COMMON_PACKAGES = [
  1264. "autoconf",
  1265. "autoconf-archive",
  1266. "autogen",
  1267. "automake",
  1268. "bison",
  1269. "build-essential",
  1270. "ca-certificates",
  1271. "cmake",
  1272. "curl",
  1273. "dh-autoreconf",
  1274. "dh-make",
  1275. "dpkg-dev",
  1276. "flex",
  1277. "g++",
  1278. "gcc",
  1279. "git-buildpackage",
  1280. "git-core",
  1281. "golang",
  1282. "libatomic1",
  1283. "libcurl4-openssl-dev",
  1284. "libcups2-dev",
  1285. "libdistro-info-perl",
  1286. "libelf-dev",
  1287. "libipmimonitoring-dev",
  1288. "libjson-c-dev",
  1289. "libyaml-dev",
  1290. "libjudy-dev",
  1291. "liblz4-dev",
  1292. "libmnl-dev",
  1293. "libmongoc-dev",
  1294. "libnetfilter-acct-dev",
  1295. "libpcre2-dev",
  1296. "libprotobuf-dev",
  1297. "libprotoc-dev",
  1298. "libsnappy-dev",
  1299. "libsystemd-dev",
  1300. "libssl-dev",
  1301. "libtool",
  1302. "libuv1-dev",
  1303. "libxen-dev",
  1304. "libzstd-dev",
  1305. "make",
  1306. "ninja-build",
  1307. "pkg-config",
  1308. "protobuf-compiler",
  1309. "systemd",
  1310. "uuid-dev",
  1311. "wget",
  1312. "zlib1g-dev",
  1313. ]
  1314. def build_ubuntu_20_04(
  1315. client: dagger.Client, platform: dagger.Platform
  1316. ) -> dagger.Container:
  1317. ctr = client.container(platform=platform).from_("ubuntu:20.04")
  1318. pkgs = [pkg for pkg in _UBUNTU_COMMON_PACKAGES] + ["dh-systemd"]
  1319. ctr = (
  1320. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1321. .with_exec(["apt-get", "update"])
  1322. .with_exec(["apt-get", "upgrade", "-y"])
  1323. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1324. .with_exec(["apt-get", "clean"])
  1325. .with_exec(["c_rehash"])
  1326. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1327. )
  1328. #
  1329. # FIXME: add kitware for cmake on arm-hf
  1330. #
  1331. return ctr
  1332. def build_ubuntu_22_04(
  1333. client: dagger.Client, platform: dagger.Platform
  1334. ) -> dagger.Container:
  1335. ctr = client.container(platform=platform).from_("ubuntu:22.04")
  1336. pkgs = [pkg for pkg in _UBUNTU_COMMON_PACKAGES]
  1337. ctr = (
  1338. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1339. .with_exec(["apt-get", "update"])
  1340. .with_exec(["apt-get", "upgrade", "-y"])
  1341. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1342. .with_exec(["apt-get", "clean"])
  1343. .with_exec(["c_rehash"])
  1344. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1345. )
  1346. return ctr
  1347. def build_ubuntu_23_04(
  1348. client: dagger.Client, platform: dagger.Platform
  1349. ) -> dagger.Container:
  1350. ctr = client.container(platform=platform).from_("ubuntu:23.04")
  1351. pkgs = [pkg for pkg in _UBUNTU_COMMON_PACKAGES]
  1352. ctr = (
  1353. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1354. .with_exec(["apt-get", "update"])
  1355. .with_exec(["apt-get", "upgrade", "-y"])
  1356. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1357. .with_exec(["apt-get", "clean"])
  1358. .with_exec(["c_rehash"])
  1359. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1360. )
  1361. return ctr
  1362. def build_ubuntu_23_10(
  1363. client: dagger.Client, platform: dagger.Platform
  1364. ) -> dagger.Container:
  1365. ctr = client.container(platform=platform).from_("ubuntu:23.10")
  1366. pkgs = [pkg for pkg in _UBUNTU_COMMON_PACKAGES]
  1367. ctr = (
  1368. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1369. .with_exec(["apt-get", "update"])
  1370. .with_exec(["apt-get", "upgrade", "-y"])
  1371. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1372. .with_exec(["apt-get", "clean"])
  1373. .with_exec(["c_rehash"])
  1374. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1375. )
  1376. return ctr
  1377. def install_cargo(ctr: dagger.Container) -> dagger.Container:
  1378. bin_paths = [
  1379. "/root/.cargo/bin",
  1380. "/usr/local/sbin",
  1381. "/usr/local/bin",
  1382. "/usr/sbin",
  1383. "/usr/bin",
  1384. "/sbin",
  1385. "/bin",
  1386. ]
  1387. ctr = (
  1388. ctr.with_workdir("/")
  1389. .with_exec(["sh", "-c", "curl https://sh.rustup.rs -sSf | sh -s -- -y"])
  1390. .with_env_variable("PATH", ":".join(bin_paths))
  1391. .with_exec(["cargo", "new", "--bin", "hello"])
  1392. .with_workdir("/hello")
  1393. .with_exec(["cargo", "run", "-v", "-v"])
  1394. )
  1395. return ctr