imageutils.py 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  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. "--use-system-protobuf",
  309. "--dont-scrub-cflags-even-though-it-may-break-things",
  310. "--one-time-build",
  311. "--enable-lto",
  312. ]
  313. ctr = (
  314. ctr.with_workdir("/netdata")
  315. .with_env_variable("NETDATA_CMAKE_OPTIONS", "-DCMAKE_BUILD_TYPE=Debug")
  316. .with_env_variable("CFLAGS", " ".join(CFLAGS))
  317. .with_env_variable("LDFLAGS", " ".join(LDFLAGS))
  318. .with_env_variable("PKG_CONFIG", " ".join(PKG_CONFIG))
  319. .with_env_variable("PKG_CONFIG_PATH", ":".join(PKG_CONFIG_PATH))
  320. .with_env_variable("CMAKE_FLAGS", " ".join(CMAKE_FLAGS))
  321. .with_env_variable("EBPF_LIBC", "static")
  322. .with_env_variable("IS_NETDATA_STATIC_BINARY", "yes")
  323. .with_exec(NETDATA_INSTALLER_CMD)
  324. )
  325. return ctr
  326. def static_build(client, repo_path):
  327. cmake_build_release_path = os.path.join(repo_path, "cmake-build-release")
  328. ctr = build_alpine_3_18(client, dagger.Platform("linux/x86_64"))
  329. ctr = static_build_openssl(client, ctr)
  330. ctr = static_build_bash(client, ctr)
  331. ctr = static_build_curl(client, ctr)
  332. ctr = static_build_ioping(client, ctr)
  333. ctr = static_build_libnetfilter_acct(client, ctr)
  334. ctr = ctr.with_directory(
  335. "/netdata",
  336. client.host().directory(repo_path),
  337. exclude=[
  338. f"{cmake_build_release_path}/*",
  339. "fluent-bit/build",
  340. ],
  341. )
  342. # TODO: link bin/sbin
  343. ctr = static_build_netdata(client, ctr)
  344. build_dir = ctr.directory("/opt/netdata")
  345. artifact_dir = os.path.join(Path.home(), "ci/netdata-static")
  346. output_task = build_dir.export(artifact_dir)
  347. return output_task
  348. _CENTOS_COMMON_PACKAGES = [
  349. "autoconf",
  350. "autoconf-archive",
  351. "autogen",
  352. "automake",
  353. "bison",
  354. "bison-devel",
  355. "cmake",
  356. "cups-devel",
  357. "curl",
  358. "diffutils",
  359. "elfutils-libelf-devel",
  360. "findutils",
  361. "flex",
  362. "flex-devel",
  363. "freeipmi-devel",
  364. "gcc",
  365. "gcc-c++",
  366. "git-core",
  367. "golang",
  368. "json-c-devel",
  369. "libyaml-devel",
  370. "libatomic",
  371. "libcurl-devel",
  372. "libmnl-devel",
  373. "libnetfilter_acct-devel",
  374. "libtool",
  375. "libuuid-devel",
  376. "libuv-devel",
  377. "libzstd-devel",
  378. "lm_sensors",
  379. "lz4-devel",
  380. "make",
  381. "ninja-build",
  382. "openssl-devel",
  383. "openssl-perl",
  384. "patch",
  385. "pcre2-devel",
  386. "pkgconfig",
  387. "pkgconfig(libmongoc-1.0)",
  388. "procps",
  389. "protobuf-c-devel",
  390. "protobuf-compiler",
  391. "protobuf-devel",
  392. "rpm-build",
  393. "rpm-devel",
  394. "rpmdevtools",
  395. "snappy-devel",
  396. "systemd-devel",
  397. "wget",
  398. "zlib-devel",
  399. ]
  400. def build_amazon_linux_2(
  401. client: dagger.Client, platform: dagger.Platform
  402. ) -> dagger.Container:
  403. ctr = client.container(platform=platform).from_("amazonlinux:2")
  404. pkgs = [pkg for pkg in _CENTOS_COMMON_PACKAGES]
  405. ctr = (
  406. ctr.with_exec(["yum", "update", "-y"])
  407. .with_exec(["yum", "install", "-y"] + pkgs)
  408. .with_exec(["yum", "clean", "all"])
  409. .with_exec(["c_rehash"])
  410. .with_exec(
  411. [
  412. "mkdir",
  413. "-p",
  414. "/root/rpmbuild/BUILD",
  415. "/root/rpmbuild/RPMS",
  416. "/root/rpmbuild/SOURCES",
  417. "/root/rpmbuild/SPECS",
  418. "/root/rpmbuild/SRPMS",
  419. ]
  420. )
  421. )
  422. if platform == "linux/x86_64":
  423. machine = "x86_64"
  424. elif platform == "linux/arm64":
  425. machine = "aarch64"
  426. else:
  427. raise Exception(
  428. "Amaxon Linux 2 supports only linux/amd64 and linux/arm64 platforms."
  429. )
  430. checksum_path = Path(__file__).parent / f"files/cmake-{machine}.sha256"
  431. ctr = (
  432. ctr.with_file(
  433. f"cmake-{machine}.sha256",
  434. client.host().file(checksum_path.as_posix()),
  435. )
  436. .with_exec(
  437. [
  438. "curl",
  439. "--fail",
  440. "-sSL",
  441. "--connect-timeout",
  442. "20",
  443. "--retry",
  444. "3",
  445. "--output",
  446. f"cmake-{machine}.sh",
  447. f"https://github.com/Kitware/CMake/releases/download/v3.27.6/cmake-3.27.6-linux-{machine}.sh",
  448. ]
  449. )
  450. .with_exec(["sha256sum", "-c", f"cmake-{machine}.sha256"])
  451. .with_exec(["chmod", "u+x", f"./cmake-{machine}.sh"])
  452. .with_exec([f"./cmake-{machine}.sh", "--skip-license", "--prefix=/usr/local"])
  453. )
  454. return ctr
  455. def build_centos_7(
  456. client: dagger.Client, platform: dagger.Platform
  457. ) -> dagger.Container:
  458. ctr = client.container(platform=platform).from_("centos:7")
  459. pkgs = [pkg for pkg in _CENTOS_COMMON_PACKAGES] + ["bash"]
  460. ctr = (
  461. ctr.with_exec(["yum", "install", "-y", "epel-release"])
  462. .with_exec(["yum", "update", "-y"])
  463. .with_exec(["yum", "install", "-y"] + pkgs)
  464. .with_exec(["yum", "clean", "all"])
  465. .with_exec(["c_rehash"])
  466. .with_exec(
  467. [
  468. "mkdir",
  469. "-p",
  470. "/root/rpmbuild/BUILD",
  471. "/root/rpmbuild/RPMS",
  472. "/root/rpmbuild/SOURCES",
  473. "/root/rpmbuild/SPECS",
  474. "/root/rpmbuild/SRPMS",
  475. ]
  476. )
  477. )
  478. if platform == "linux/x86_64":
  479. machine = "x86_64"
  480. elif platform == "linux/arm64":
  481. machine = "aarch64"
  482. else:
  483. raise Exception("CentOS 7 supports only linux/amd64 and linux/arm64 platforms.")
  484. checksum_path = Path(__file__).parent / f"files/cmake-{machine}.sha256"
  485. ctr = (
  486. ctr.with_file(
  487. f"cmake-{machine}.sha256",
  488. client.host().file(checksum_path.as_posix()),
  489. )
  490. .with_exec(
  491. [
  492. "curl",
  493. "--fail",
  494. "-sSL",
  495. "--connect-timeout",
  496. "20",
  497. "--retry",
  498. "3",
  499. "--output",
  500. f"cmake-{machine}.sh",
  501. f"https://github.com/Kitware/CMake/releases/download/v3.27.6/cmake-3.27.6-linux-{machine}.sh",
  502. ]
  503. )
  504. .with_exec(["sha256sum", "-c", f"cmake-{machine}.sha256"])
  505. .with_exec(["chmod", "u+x", f"./cmake-{machine}.sh"])
  506. .with_exec([f"./cmake-{machine}.sh", "--skip-license", "--prefix=/usr/local"])
  507. )
  508. return ctr
  509. _ROCKY_LINUX_COMMON_PACKAGES = [
  510. "autoconf",
  511. "autoconf-archive",
  512. "automake",
  513. "bash",
  514. "bison",
  515. "cmake",
  516. "cups-devel",
  517. "curl",
  518. "libcurl-devel",
  519. "diffutils",
  520. "elfutils-libelf-devel",
  521. "findutils",
  522. "flex",
  523. "freeipmi-devel",
  524. "gcc",
  525. "gcc-c++",
  526. "git",
  527. "golang",
  528. "json-c-devel",
  529. "libatomic",
  530. "libmnl-devel",
  531. "libtool",
  532. "libuuid-devel",
  533. "libuv-devel",
  534. "libyaml-devel",
  535. "libzstd-devel",
  536. "lm_sensors",
  537. "lz4-devel",
  538. "make",
  539. "ninja-build",
  540. "nc",
  541. "openssl-devel",
  542. "openssl-perl",
  543. "patch",
  544. "pcre2-devel",
  545. "pkgconfig",
  546. "pkgconfig(libmongoc-1.0)",
  547. "procps",
  548. "protobuf-c-devel",
  549. "protobuf-compiler",
  550. "protobuf-devel",
  551. "python3",
  552. "python3-pyyaml",
  553. "rpm-build",
  554. "rpm-devel",
  555. "rpmdevtools",
  556. "snappy-devel",
  557. "systemd-devel",
  558. "wget",
  559. "zlib-devel",
  560. ]
  561. def build_rocky_linux_8(
  562. client: dagger.Client, platform: dagger.Platform
  563. ) -> dagger.Container:
  564. ctr = client.container(platform=platform).from_("rockylinux:8")
  565. pkgs = [pkg for pkg in _ROCKY_LINUX_COMMON_PACKAGES] + ["autogen"]
  566. ctr = (
  567. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  568. .with_exec(
  569. [
  570. "dnf",
  571. "install",
  572. "-y",
  573. "--nodocs",
  574. "dnf-command(config-manager)",
  575. "epel-release",
  576. ]
  577. )
  578. .with_exec(["dnf", "config-manager", "--set-enabled", "powertools"])
  579. .with_exec(["dnf", "clean", "packages"])
  580. .with_exec(
  581. [
  582. "dnf",
  583. "install",
  584. "-y",
  585. "--nodocs",
  586. "--setopt=install_weak_deps=False",
  587. "--setopt=diskspacecheck=False",
  588. ]
  589. + pkgs
  590. )
  591. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  592. .with_exec(["c_rehash"])
  593. .with_exec(
  594. [
  595. "mkdir",
  596. "-p",
  597. "/root/rpmbuild/BUILD",
  598. "/root/rpmbuild/RPMS",
  599. "/root/rpmbuild/SOURCES",
  600. "/root/rpmbuild/SPECS",
  601. "/root/rpmbuild/SRPMS",
  602. ]
  603. )
  604. )
  605. return ctr
  606. def build_rocky_linux_9(
  607. client: dagger.Client, platform: dagger.Platform
  608. ) -> dagger.Container:
  609. ctr = client.container(platform=platform).from_("rockylinux:9")
  610. pkgs = [pkg for pkg in _ROCKY_LINUX_COMMON_PACKAGES]
  611. ctr = (
  612. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  613. .with_exec(
  614. [
  615. "dnf",
  616. "install",
  617. "-y",
  618. "--nodocs",
  619. "dnf-command(config-manager)",
  620. "epel-release",
  621. ]
  622. )
  623. .with_exec(["dnf", "config-manager", "--set-enabled", "crb"])
  624. .with_exec(["dnf", "clean", "packages"])
  625. .with_exec(
  626. [
  627. "dnf",
  628. "install",
  629. "-y",
  630. "--allowerasing",
  631. "--nodocs",
  632. "--setopt=install_weak_deps=False",
  633. "--setopt=diskspacecheck=False",
  634. ]
  635. + pkgs
  636. )
  637. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  638. .with_exec(["c_rehash"])
  639. .with_exec(
  640. [
  641. "mkdir",
  642. "-p",
  643. "/root/rpmbuild/BUILD",
  644. "/root/rpmbuild/RPMS",
  645. "/root/rpmbuild/SOURCES",
  646. "/root/rpmbuild/SPECS",
  647. "/root/rpmbuild/SRPMS",
  648. ]
  649. )
  650. )
  651. return ctr
  652. _CENTOS_STREAM_COMMON_PACKAGES = [
  653. "autoconf",
  654. "autoconf-archive",
  655. "automake",
  656. "bash",
  657. "bison",
  658. "cmake",
  659. "cups-devel",
  660. "curl",
  661. "libcurl-devel",
  662. "libyaml-devel",
  663. "diffutils",
  664. "elfutils-libelf-devel",
  665. "findutils",
  666. "flex",
  667. "freeipmi-devel",
  668. "gcc",
  669. "gcc-c++",
  670. "git",
  671. "golang",
  672. "json-c-devel",
  673. "libatomic",
  674. "libmnl-devel",
  675. "libtool",
  676. "libuuid-devel",
  677. "libuv-devel",
  678. # "libzstd-devel",
  679. "lm_sensors",
  680. "lz4-devel",
  681. "make",
  682. "ninja-build",
  683. "nc",
  684. "openssl-devel",
  685. "openssl-perl",
  686. "patch",
  687. "pcre2-devel",
  688. "pkgconfig",
  689. "pkgconfig(libmongoc-1.0)",
  690. "procps",
  691. "protobuf-c-devel",
  692. "protobuf-compiler",
  693. "protobuf-devel",
  694. "python3",
  695. "python3-pyyaml",
  696. "rpm-build",
  697. "rpm-devel",
  698. "rpmdevtools",
  699. "snappy-devel",
  700. "systemd-devel",
  701. "wget",
  702. "zlib-devel",
  703. ]
  704. def build_centos_stream_8(
  705. client: dagger.Client, platform: dagger.Platform
  706. ) -> dagger.Container:
  707. ctr = client.container(platform=platform).from_("quay.io/centos/centos:stream8")
  708. pkgs = [pkg for pkg in _CENTOS_STREAM_COMMON_PACKAGES] + ["autogen"]
  709. ctr = (
  710. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  711. .with_exec(
  712. [
  713. "dnf",
  714. "install",
  715. "-y",
  716. "--nodocs",
  717. "dnf-command(config-manager)",
  718. "epel-release",
  719. ]
  720. )
  721. .with_exec(["dnf", "config-manager", "--set-enabled", "powertools"])
  722. .with_exec(["dnf", "clean", "packages"])
  723. .with_exec(
  724. [
  725. "dnf",
  726. "install",
  727. "-y",
  728. "--nodocs",
  729. "--setopt=install_weak_deps=False",
  730. "--setopt=diskspacecheck=False",
  731. ]
  732. + pkgs
  733. )
  734. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  735. .with_exec(["c_rehash"])
  736. .with_exec(
  737. [
  738. "mkdir",
  739. "-p",
  740. "/root/rpmbuild/BUILD",
  741. "/root/rpmbuild/RPMS",
  742. "/root/rpmbuild/SOURCES",
  743. "/root/rpmbuild/SPECS",
  744. "/root/rpmbuild/SRPMS",
  745. ]
  746. )
  747. )
  748. return ctr
  749. def build_centos_stream_9(
  750. client: dagger.Client, platform: dagger.Platform
  751. ) -> dagger.Container:
  752. ctr = client.container(platform=platform).from_("quay.io/centos/centos:stream9")
  753. pkgs = [pkg for pkg in _CENTOS_STREAM_COMMON_PACKAGES]
  754. ctr = (
  755. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  756. .with_exec(
  757. [
  758. "dnf",
  759. "install",
  760. "-y",
  761. "--nodocs",
  762. "dnf-command(config-manager)",
  763. "epel-release",
  764. ]
  765. )
  766. .with_exec(["dnf", "config-manager", "--set-enabled", "crb"])
  767. .with_exec(["dnf", "clean", "packages"])
  768. .with_exec(
  769. [
  770. "dnf",
  771. "install",
  772. "-y",
  773. "--allowerasing",
  774. "--nodocs",
  775. "--setopt=install_weak_deps=False",
  776. "--setopt=diskspacecheck=False",
  777. ]
  778. + pkgs
  779. )
  780. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  781. .with_exec(["c_rehash"])
  782. .with_exec(
  783. [
  784. "mkdir",
  785. "-p",
  786. "/root/rpmbuild/BUILD",
  787. "/root/rpmbuild/RPMS",
  788. "/root/rpmbuild/SOURCES",
  789. "/root/rpmbuild/SPECS",
  790. "/root/rpmbuild/SRPMS",
  791. ]
  792. )
  793. )
  794. return ctr
  795. _ORACLE_LINUX_COMMON_PACKAGES = list(_ROCKY_LINUX_COMMON_PACKAGES)
  796. def build_oracle_linux_9(
  797. client: dagger.Client, platform: dagger.Platform
  798. ) -> dagger.Container:
  799. ctr = client.container(platform=platform).from_("oraclelinux:9")
  800. pkgs = [pkg for pkg in _ORACLE_LINUX_COMMON_PACKAGES]
  801. repo_path = str(Path(__file__).parent.parent.parent)
  802. this_path = os.path.join(repo_path, "packaging/dag")
  803. ctr = (
  804. ctr.with_file(
  805. "/etc/yum.repos.d/ol9-epel.repo",
  806. client.host().file(f"{this_path}/ol9-epel.repo"),
  807. )
  808. .with_exec(["dnf", "config-manager", "--set-enabled", "ol9_codeready_builder"])
  809. .with_exec(["dnf", "config-manager", "--set-enabled", "ol9_developer_EPEL"])
  810. .with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  811. .with_exec(["dnf", "clean", "-y", "packages"])
  812. .with_exec(
  813. [
  814. "dnf",
  815. "install",
  816. "-y",
  817. "--nodocs",
  818. "--setopt=install_weak_deps=False",
  819. "--setopt=diskspacecheck=False",
  820. ]
  821. + pkgs
  822. )
  823. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  824. .with_exec(["c_rehash"])
  825. .with_exec(
  826. [
  827. "mkdir",
  828. "-p",
  829. "/root/rpmbuild/BUILD",
  830. "/root/rpmbuild/RPMS",
  831. "/root/rpmbuild/SOURCES",
  832. "/root/rpmbuild/SPECS",
  833. "/root/rpmbuild/SRPMS",
  834. ]
  835. )
  836. )
  837. return ctr
  838. def build_oracle_linux_8(
  839. client: dagger.Client, platform: dagger.Platform
  840. ) -> dagger.Container:
  841. ctr = client.container(platform=platform).from_("oraclelinux:8")
  842. pkgs = [pkg for pkg in _ORACLE_LINUX_COMMON_PACKAGES] + ["autogen"]
  843. repo_path = str(Path(__file__).parent.parent.parent)
  844. this_path = os.path.join(repo_path, "packaging/dag")
  845. ctr = (
  846. ctr.with_file(
  847. "/etc/yum.repos.d/ol8-epel.repo",
  848. client.host().file(f"{this_path}/ol8-epel.repo"),
  849. )
  850. .with_exec(["dnf", "config-manager", "--set-enabled", "ol8_codeready_builder"])
  851. .with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  852. .with_exec(["dnf", "clean", "-y", "packages"])
  853. .with_exec(
  854. [
  855. "dnf",
  856. "install",
  857. "-y",
  858. "--nodocs",
  859. "--setopt=install_weak_deps=False",
  860. "--setopt=diskspacecheck=False",
  861. ]
  862. + pkgs
  863. )
  864. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  865. .with_exec(["c_rehash"])
  866. .with_exec(
  867. [
  868. "mkdir",
  869. "-p",
  870. "/root/rpmbuild/BUILD",
  871. "/root/rpmbuild/RPMS",
  872. "/root/rpmbuild/SOURCES",
  873. "/root/rpmbuild/SPECS",
  874. "/root/rpmbuild/SRPMS",
  875. ]
  876. )
  877. )
  878. return ctr
  879. _OPENSUSE_COMMON_PACKAGES = [
  880. "autoconf",
  881. "autoconf-archive",
  882. "autogen",
  883. "automake",
  884. "bison",
  885. "cmake",
  886. "cups",
  887. "cups-devel",
  888. "curl",
  889. "diffutils",
  890. "flex",
  891. "freeipmi-devel",
  892. "gcc",
  893. "gcc-c++",
  894. "git-core",
  895. "go",
  896. "json-glib-devel",
  897. "judy-devel",
  898. "libatomic1",
  899. "libcurl-devel",
  900. "libelf-devel",
  901. "liblz4-devel",
  902. "libjson-c-devel",
  903. "libyaml-devel",
  904. "libmnl0",
  905. "libmnl-devel",
  906. "libnetfilter_acct1",
  907. "libnetfilter_acct-devel",
  908. "libpcre2-8-0",
  909. "libopenssl-devel",
  910. "libtool",
  911. "libuv-devel",
  912. "libuuid-devel",
  913. "libzstd-devel",
  914. "make",
  915. "ninja",
  916. "patch",
  917. "pkg-config",
  918. "protobuf-devel",
  919. "rpm-build",
  920. "rpm-devel",
  921. "rpmdevtools",
  922. "snappy-devel",
  923. "systemd-devel",
  924. "tar",
  925. "wget",
  926. "xen-devel",
  927. ]
  928. def build_opensuse_tumbleweed(
  929. client: dagger.Client, platform: dagger.Platform
  930. ) -> dagger.Container:
  931. ctr = client.container(platform=platform).from_("opensuse/tumbleweed:latest")
  932. pkgs = [pkg for pkg in _OPENSUSE_COMMON_PACKAGES] + ["protobuf-c"]
  933. ctr = (
  934. ctr.with_exec(["zypper", "update", "-y"])
  935. .with_exec(
  936. [
  937. "zypper",
  938. "install",
  939. "-y",
  940. "--allow-downgrade",
  941. ]
  942. + pkgs
  943. )
  944. .with_exec(["zypper", "clean"])
  945. .with_exec(["rm", "-rf", "/var/cache/zypp/*/*"])
  946. .with_exec(["c_rehash"])
  947. .with_exec(
  948. [
  949. "mkdir",
  950. "-p",
  951. "/usr/src/packages/BUILD",
  952. "/usr/src/packages/RPMS",
  953. "/usr/src/packages/SOURCES",
  954. "/usr/src/packages/SPECS",
  955. "/usr/src/packages/SRPMS",
  956. ]
  957. )
  958. )
  959. return ctr
  960. def build_opensuse_15_5(
  961. client: dagger.Client, platform: dagger.Platform
  962. ) -> dagger.Container:
  963. ctr = client.container(platform=platform).from_("opensuse/leap:15.5")
  964. pkgs = [pkg for pkg in _OPENSUSE_COMMON_PACKAGES] + ["libprotobuf-c-devel"]
  965. ctr = (
  966. ctr.with_exec(["zypper", "update", "-y"])
  967. .with_exec(
  968. [
  969. "zypper",
  970. "install",
  971. "-y",
  972. "--allow-downgrade",
  973. ]
  974. + pkgs
  975. )
  976. .with_exec(["zypper", "clean"])
  977. .with_exec(["rm", "-rf", "/var/cache/zypp/*/*"])
  978. .with_exec(["c_rehash"])
  979. .with_exec(
  980. [
  981. "mkdir",
  982. "-p",
  983. "/usr/src/packages/BUILD",
  984. "/usr/src/packages/RPMS",
  985. "/usr/src/packages/SOURCES",
  986. "/usr/src/packages/SPECS",
  987. "/usr/src/packages/SRPMS",
  988. ]
  989. )
  990. )
  991. return ctr
  992. def build_opensuse_15_4(
  993. client: dagger.Client, platform: dagger.Platform
  994. ) -> dagger.Container:
  995. crt = client.container(platform=platform).from_("opensuse/leap:15.4")
  996. pkgs = [pkg for pkg in _OPENSUSE_COMMON_PACKAGES] + ["libprotobuf-c-devel"]
  997. crt = (
  998. crt.with_exec(["zypper", "update", "-y"])
  999. .with_exec(
  1000. [
  1001. "zypper",
  1002. "install",
  1003. "-y",
  1004. "--allow-downgrade",
  1005. ]
  1006. + pkgs
  1007. )
  1008. .with_exec(["zypper", "clean"])
  1009. .with_exec(["rm", "-rf", "/var/cache/zypp/*/*"])
  1010. .with_exec(["c_rehash"])
  1011. .with_exec(
  1012. [
  1013. "mkdir",
  1014. "-p",
  1015. "/usr/src/packages/BUILD",
  1016. "/usr/src/packages/RPMS",
  1017. "/usr/src/packages/SOURCES",
  1018. "/usr/src/packages/SPECS",
  1019. "/usr/src/packages/SRPMS",
  1020. ]
  1021. )
  1022. )
  1023. return crt
  1024. _FEDORA_COMMON_PACKAGES = [
  1025. "autoconf",
  1026. "autoconf-archive",
  1027. "autogen",
  1028. "automake",
  1029. "bash",
  1030. "bison",
  1031. "cmake",
  1032. "cups-devel",
  1033. "curl",
  1034. "diffutils",
  1035. "elfutils-libelf-devel",
  1036. "findutils",
  1037. "flex",
  1038. "freeipmi-devel",
  1039. "gcc",
  1040. "gcc-c++",
  1041. "git-core",
  1042. "golang",
  1043. "json-c-devel",
  1044. "libcurl-devel",
  1045. "libyaml-devel",
  1046. "Judy-devel",
  1047. "libatomic",
  1048. "libmnl-devel",
  1049. "libnetfilter_acct-devel",
  1050. "libtool",
  1051. "libuuid-devel",
  1052. "libuv-devel",
  1053. "libzstd-devel",
  1054. "lz4-devel",
  1055. "make",
  1056. "ninja-build",
  1057. "openssl-devel",
  1058. "openssl-perl",
  1059. "patch",
  1060. "pcre2-devel",
  1061. "pkgconfig",
  1062. ]
  1063. def build_fedora_37(
  1064. client: dagger.Client, platform: dagger.Platform
  1065. ) -> dagger.Container:
  1066. ctr = client.container(platform=platform).from_("fedora:37")
  1067. pkgs = [pkg for pkg in _FEDORA_COMMON_PACKAGES]
  1068. ctr = (
  1069. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  1070. .with_exec(["dnf", "clean", "-y", "packages"])
  1071. .with_exec(
  1072. [
  1073. "dnf",
  1074. "install",
  1075. "-y",
  1076. "--nodocs",
  1077. "--setopt=install_weak_deps=False",
  1078. "--setopt=diskspacecheck=False",
  1079. ]
  1080. + pkgs
  1081. )
  1082. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  1083. .with_exec(["c_rehash"])
  1084. .with_exec(
  1085. [
  1086. "mkdir",
  1087. "-p",
  1088. "/root/rpmbuild/BUILD",
  1089. "/root/rpmbuild/RPMS",
  1090. "/root/rpmbuild/SOURCES",
  1091. "/root/rpmbuild/SPECS",
  1092. "/root/rpmbuild/SRPMS",
  1093. ]
  1094. )
  1095. )
  1096. return ctr
  1097. def build_fedora_38(
  1098. client: dagger.Client, platform: dagger.Platform
  1099. ) -> dagger.Container:
  1100. ctr = client.container(platform=platform).from_("fedora:38")
  1101. pkgs = [pkg for pkg in _FEDORA_COMMON_PACKAGES]
  1102. ctr = (
  1103. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  1104. .with_exec(["dnf", "clean", "-y", "packages"])
  1105. .with_exec(
  1106. [
  1107. "dnf",
  1108. "install",
  1109. "-y",
  1110. "--nodocs",
  1111. "--setopt=install_weak_deps=False",
  1112. "--setopt=diskspacecheck=False",
  1113. ]
  1114. + pkgs
  1115. )
  1116. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  1117. .with_exec(["c_rehash"])
  1118. .with_exec(
  1119. [
  1120. "mkdir",
  1121. "-p",
  1122. "/root/rpmbuild/BUILD",
  1123. "/root/rpmbuild/RPMS",
  1124. "/root/rpmbuild/SOURCES",
  1125. "/root/rpmbuild/SPECS",
  1126. "/root/rpmbuild/SRPMS",
  1127. ]
  1128. )
  1129. )
  1130. return ctr
  1131. def build_fedora_39(
  1132. client: dagger.Client, platform: dagger.Platform
  1133. ) -> dagger.Container:
  1134. ctr = client.container(platform=platform).from_("fedora:39")
  1135. pkgs = [pkg for pkg in _FEDORA_COMMON_PACKAGES]
  1136. ctr = (
  1137. ctr.with_exec(["dnf", "distro-sync", "-y", "--nodocs"])
  1138. .with_exec(["dnf", "clean", "-y", "packages"])
  1139. .with_exec(
  1140. [
  1141. "dnf",
  1142. "install",
  1143. "-y",
  1144. "--nodocs",
  1145. "--setopt=install_weak_deps=False",
  1146. "--setopt=diskspacecheck=False",
  1147. ]
  1148. + pkgs
  1149. )
  1150. .with_exec(["rm", "-rf", "/var/cache/dnf"])
  1151. .with_exec(["c_rehash"])
  1152. .with_exec(
  1153. [
  1154. "mkdir",
  1155. "-p",
  1156. "/root/rpmbuild/BUILD",
  1157. "/root/rpmbuild/RPMS",
  1158. "/root/rpmbuild/SOURCES",
  1159. "/root/rpmbuild/SPECS",
  1160. "/root/rpmbuild/SRPMS",
  1161. ]
  1162. )
  1163. )
  1164. return ctr
  1165. _DEBIAN_COMMON_PACKAGES = [
  1166. "autoconf",
  1167. "autoconf-archive",
  1168. "autogen",
  1169. "automake",
  1170. "bison",
  1171. "build-essential",
  1172. "ca-certificates",
  1173. "cmake",
  1174. "curl",
  1175. "dh-autoreconf",
  1176. "dh-make",
  1177. "dpkg-dev",
  1178. "flex",
  1179. "g++",
  1180. "gcc",
  1181. "git-buildpackage",
  1182. "git-core",
  1183. "golang",
  1184. "libatomic1",
  1185. "libcurl4-openssl-dev",
  1186. "libcups2-dev",
  1187. "libdistro-info-perl",
  1188. "libelf-dev",
  1189. "libipmimonitoring-dev",
  1190. "libjson-c-dev",
  1191. "libyaml-dev",
  1192. "libjudy-dev",
  1193. "liblz4-dev",
  1194. "libmnl-dev",
  1195. "libmongoc-dev",
  1196. "libnetfilter-acct-dev",
  1197. "libpcre2-dev",
  1198. "libprotobuf-dev",
  1199. "libprotoc-dev",
  1200. "libsnappy-dev",
  1201. "libsystemd-dev",
  1202. "libssl-dev",
  1203. "libtool",
  1204. "libuv1-dev",
  1205. "libzstd-dev",
  1206. "make",
  1207. "ninja-build",
  1208. "pkg-config",
  1209. "protobuf-compiler",
  1210. "systemd",
  1211. "uuid-dev",
  1212. "wget",
  1213. "zlib1g-dev",
  1214. ]
  1215. def build_debian_10(
  1216. client: dagger.Client, platform: dagger.Platform
  1217. ) -> dagger.Container:
  1218. ctr = client.container(platform=platform).from_("debian:buster")
  1219. pkgs = [pkg for pkg in _DEBIAN_COMMON_PACKAGES] + ["dh-systemd", "libxen-dev"]
  1220. ctr = (
  1221. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1222. .with_exec(["apt-get", "update"])
  1223. .with_exec(["apt-get", "upgrade", "-y"])
  1224. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1225. .with_exec(["apt-get", "clean"])
  1226. .with_exec(["c_rehash"])
  1227. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1228. )
  1229. return ctr
  1230. def build_debian_11(
  1231. client: dagger.Client, platform: dagger.Platform
  1232. ) -> dagger.Container:
  1233. ctr = client.container(platform=platform).from_("debian:bullseye")
  1234. pkgs = [pkg for pkg in _DEBIAN_COMMON_PACKAGES] + ["libxen-dev"]
  1235. ctr = (
  1236. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1237. .with_exec(["apt-get", "update"])
  1238. .with_exec(["apt-get", "upgrade", "-y"])
  1239. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1240. .with_exec(["apt-get", "clean"])
  1241. .with_exec(["c_rehash"])
  1242. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1243. )
  1244. return ctr
  1245. def build_debian_12(
  1246. client: dagger.Client, platform: dagger.Platform
  1247. ) -> dagger.Container:
  1248. ctr = client.container(platform=platform).from_("debian:bookworm")
  1249. pkgs = [pkg for pkg in _DEBIAN_COMMON_PACKAGES]
  1250. if platform != dagger.Platform("linux/i386"):
  1251. pkgs.append("libxen-dev")
  1252. ctr = (
  1253. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1254. .with_exec(["apt-get", "update"])
  1255. .with_exec(["apt-get", "upgrade", "-y"])
  1256. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1257. .with_exec(["apt-get", "clean"])
  1258. .with_exec(["c_rehash"])
  1259. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1260. )
  1261. return ctr
  1262. _UBUNTU_COMMON_PACKAGES = [
  1263. "autoconf",
  1264. "autoconf-archive",
  1265. "autogen",
  1266. "automake",
  1267. "bison",
  1268. "build-essential",
  1269. "ca-certificates",
  1270. "cmake",
  1271. "curl",
  1272. "dh-autoreconf",
  1273. "dh-make",
  1274. "dpkg-dev",
  1275. "flex",
  1276. "g++",
  1277. "gcc",
  1278. "git-buildpackage",
  1279. "git-core",
  1280. "golang",
  1281. "libatomic1",
  1282. "libcurl4-openssl-dev",
  1283. "libcups2-dev",
  1284. "libdistro-info-perl",
  1285. "libelf-dev",
  1286. "libipmimonitoring-dev",
  1287. "libjson-c-dev",
  1288. "libyaml-dev",
  1289. "libjudy-dev",
  1290. "liblz4-dev",
  1291. "libmnl-dev",
  1292. "libmongoc-dev",
  1293. "libnetfilter-acct-dev",
  1294. "libpcre2-dev",
  1295. "libprotobuf-dev",
  1296. "libprotoc-dev",
  1297. "libsnappy-dev",
  1298. "libsystemd-dev",
  1299. "libssl-dev",
  1300. "libtool",
  1301. "libuv1-dev",
  1302. "libxen-dev",
  1303. "libzstd-dev",
  1304. "make",
  1305. "ninja-build",
  1306. "pkg-config",
  1307. "protobuf-compiler",
  1308. "systemd",
  1309. "uuid-dev",
  1310. "wget",
  1311. "zlib1g-dev",
  1312. ]
  1313. def build_ubuntu_20_04(
  1314. client: dagger.Client, platform: dagger.Platform
  1315. ) -> dagger.Container:
  1316. ctr = client.container(platform=platform).from_("ubuntu:20.04")
  1317. pkgs = [pkg for pkg in _UBUNTU_COMMON_PACKAGES] + ["dh-systemd"]
  1318. ctr = (
  1319. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1320. .with_exec(["apt-get", "update"])
  1321. .with_exec(["apt-get", "upgrade", "-y"])
  1322. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1323. .with_exec(["apt-get", "clean"])
  1324. .with_exec(["c_rehash"])
  1325. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1326. )
  1327. #
  1328. # FIXME: add kitware for cmake on arm-hf
  1329. #
  1330. return ctr
  1331. def build_ubuntu_22_04(
  1332. client: dagger.Client, platform: dagger.Platform
  1333. ) -> dagger.Container:
  1334. ctr = client.container(platform=platform).from_("ubuntu:22.04")
  1335. pkgs = [pkg for pkg in _UBUNTU_COMMON_PACKAGES]
  1336. ctr = (
  1337. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1338. .with_exec(["apt-get", "update"])
  1339. .with_exec(["apt-get", "upgrade", "-y"])
  1340. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1341. .with_exec(["apt-get", "clean"])
  1342. .with_exec(["c_rehash"])
  1343. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1344. )
  1345. return ctr
  1346. def build_ubuntu_23_04(
  1347. client: dagger.Client, platform: dagger.Platform
  1348. ) -> dagger.Container:
  1349. ctr = client.container(platform=platform).from_("ubuntu:23.04")
  1350. pkgs = [pkg for pkg in _UBUNTU_COMMON_PACKAGES]
  1351. ctr = (
  1352. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1353. .with_exec(["apt-get", "update"])
  1354. .with_exec(["apt-get", "upgrade", "-y"])
  1355. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1356. .with_exec(["apt-get", "clean"])
  1357. .with_exec(["c_rehash"])
  1358. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1359. )
  1360. return ctr
  1361. def build_ubuntu_23_10(
  1362. client: dagger.Client, platform: dagger.Platform
  1363. ) -> dagger.Container:
  1364. ctr = client.container(platform=platform).from_("ubuntu:23.10")
  1365. pkgs = [pkg for pkg in _UBUNTU_COMMON_PACKAGES]
  1366. ctr = (
  1367. ctr.with_env_variable("DEBIAN_FRONTEND", "noninteractive")
  1368. .with_exec(["apt-get", "update"])
  1369. .with_exec(["apt-get", "upgrade", "-y"])
  1370. .with_exec(["apt-get", "install", "-y", "--no-install-recommends"] + pkgs)
  1371. .with_exec(["apt-get", "clean"])
  1372. .with_exec(["c_rehash"])
  1373. .with_exec(["rm", "-rf", "/var/lib/apt/lists/*"])
  1374. )
  1375. return ctr
  1376. def install_cargo(ctr: dagger.Container) -> dagger.Container:
  1377. bin_paths = [
  1378. "/root/.cargo/bin",
  1379. "/usr/local/sbin",
  1380. "/usr/local/bin",
  1381. "/usr/sbin",
  1382. "/usr/bin",
  1383. "/sbin",
  1384. "/bin",
  1385. ]
  1386. ctr = (
  1387. ctr.with_workdir("/")
  1388. .with_exec(["sh", "-c", "curl https://sh.rustup.rs -sSf | sh -s -- -y"])
  1389. .with_env_variable("PATH", ":".join(bin_paths))
  1390. .with_exec(["cargo", "new", "--bin", "hello"])
  1391. .with_workdir("/hello")
  1392. .with_exec(["cargo", "run", "-v", "-v"])
  1393. )
  1394. return ctr