@lakutata/containerd 0.0.0-stage → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +409 -2
  3. package/THIRD_PARTY_NOTICES.md +310 -0
  4. package/dist/cjs/client/BuildKit.d.ts +176 -0
  5. package/dist/cjs/client/BuildKit.js +536 -0
  6. package/dist/cjs/client/BuildKitMessages.d.ts +35 -0
  7. package/dist/cjs/client/BuildKitMessages.js +123 -0
  8. package/dist/cjs/client/ContainerStore.d.ts +558 -0
  9. package/dist/cjs/client/ContainerStore.js +1384 -0
  10. package/dist/cjs/client/ContainerdClient.d.ts +244 -0
  11. package/dist/cjs/client/ContainerdClient.js +455 -0
  12. package/dist/cjs/client/DockerIgnore.d.ts +44 -0
  13. package/dist/cjs/client/DockerIgnore.js +186 -0
  14. package/dist/cjs/client/Fifo.d.ts +31 -0
  15. package/dist/cjs/client/Fifo.js +66 -0
  16. package/dist/cjs/client/ImageStore.d.ts +258 -0
  17. package/dist/cjs/client/ImageStore.js +636 -0
  18. package/dist/cjs/client/Messages.d.ts +103 -0
  19. package/dist/cjs/client/Messages.js +397 -0
  20. package/dist/cjs/client/Networks.d.ts +221 -0
  21. package/dist/cjs/client/Networks.js +630 -0
  22. package/dist/cjs/client/Platforms.d.ts +53 -0
  23. package/dist/cjs/client/Platforms.js +169 -0
  24. package/dist/cjs/client/Reference.d.ts +33 -0
  25. package/dist/cjs/client/Reference.js +70 -0
  26. package/dist/cjs/client/Registry.d.ts +145 -0
  27. package/dist/cjs/client/Registry.js +272 -0
  28. package/dist/cjs/client/Rootfs.d.ts +83 -0
  29. package/dist/cjs/client/Rootfs.js +245 -0
  30. package/dist/cjs/client/Seccomp.d.ts +36 -0
  31. package/dist/cjs/client/Seccomp.js +156 -0
  32. package/dist/cjs/client/Spec.d.ts +151 -0
  33. package/dist/cjs/client/Spec.js +227 -0
  34. package/dist/cjs/client/Volumes.d.ts +42 -0
  35. package/dist/cjs/client/Volumes.js +80 -0
  36. package/dist/cjs/containerd/Containerd.d.ts +442 -0
  37. package/dist/cjs/containerd/Containerd.js +929 -0
  38. package/dist/cjs/containerd/exceptions/ContainerdConnectionException.d.ts +9 -0
  39. package/dist/cjs/containerd/exceptions/ContainerdConnectionException.js +16 -0
  40. package/dist/cjs/containerd/exceptions/ContainerdContainerNameConflictException.d.ts +8 -0
  41. package/dist/cjs/containerd/exceptions/ContainerdContainerNameConflictException.js +15 -0
  42. package/dist/cjs/containerd/exceptions/ContainerdContainerNotFoundException.d.ts +9 -0
  43. package/dist/cjs/containerd/exceptions/ContainerdContainerNotFoundException.js +16 -0
  44. package/dist/cjs/containerd/exceptions/ContainerdContainerStateException.d.ts +10 -0
  45. package/dist/cjs/containerd/exceptions/ContainerdContainerStateException.js +17 -0
  46. package/dist/cjs/containerd/exceptions/ContainerdImageBuildException.d.ts +9 -0
  47. package/dist/cjs/containerd/exceptions/ContainerdImageBuildException.js +16 -0
  48. package/dist/cjs/containerd/exceptions/ContainerdImageExportException.d.ts +9 -0
  49. package/dist/cjs/containerd/exceptions/ContainerdImageExportException.js +16 -0
  50. package/dist/cjs/containerd/exceptions/ContainerdImageImportException.d.ts +9 -0
  51. package/dist/cjs/containerd/exceptions/ContainerdImageImportException.js +16 -0
  52. package/dist/cjs/containerd/exceptions/ContainerdImageNotFoundException.d.ts +9 -0
  53. package/dist/cjs/containerd/exceptions/ContainerdImageNotFoundException.js +16 -0
  54. package/dist/cjs/containerd/exceptions/ContainerdImagePullException.d.ts +9 -0
  55. package/dist/cjs/containerd/exceptions/ContainerdImagePullException.js +16 -0
  56. package/dist/cjs/containerd/exceptions/ContainerdImagePushException.d.ts +8 -0
  57. package/dist/cjs/containerd/exceptions/ContainerdImagePushException.js +15 -0
  58. package/dist/cjs/containerd/exceptions/ContainerdNetworkConflictException.d.ts +9 -0
  59. package/dist/cjs/containerd/exceptions/ContainerdNetworkConflictException.js +16 -0
  60. package/dist/cjs/containerd/exceptions/ContainerdNetworkNotFoundException.d.ts +9 -0
  61. package/dist/cjs/containerd/exceptions/ContainerdNetworkNotFoundException.js +16 -0
  62. package/dist/cjs/containerd/exceptions/ContainerdPathNotFoundException.d.ts +8 -0
  63. package/dist/cjs/containerd/exceptions/ContainerdPathNotFoundException.js +15 -0
  64. package/dist/cjs/containerd/exceptions/ContainerdPlatformException.d.ts +9 -0
  65. package/dist/cjs/containerd/exceptions/ContainerdPlatformException.js +16 -0
  66. package/dist/cjs/containerd/exceptions/ContainerdVolumeInUseException.d.ts +8 -0
  67. package/dist/cjs/containerd/exceptions/ContainerdVolumeInUseException.js +15 -0
  68. package/dist/cjs/containerd/exceptions/ContainerdVolumeNotFoundException.d.ts +8 -0
  69. package/dist/cjs/containerd/exceptions/ContainerdVolumeNotFoundException.js +15 -0
  70. package/dist/cjs/containerd/lib/ContainerdContainer.d.ts +292 -0
  71. package/dist/cjs/containerd/lib/ContainerdContainer.js +536 -0
  72. package/dist/cjs/containerd/lib/ContainerdContainerTTY.d.ts +116 -0
  73. package/dist/cjs/containerd/lib/ContainerdContainerTTY.js +178 -0
  74. package/dist/cjs/containerd/lib/ContainerdErrors.d.ts +6 -0
  75. package/dist/cjs/containerd/lib/ContainerdErrors.js +37 -0
  76. package/dist/cjs/containerd/lib/ContainerdImage.d.ts +149 -0
  77. package/dist/cjs/containerd/lib/ContainerdImage.js +222 -0
  78. package/dist/cjs/containerd/options/ContainerdPruneOptions.d.ts +44 -0
  79. package/dist/cjs/containerd/options/ContainerdPruneOptions.js +51 -0
  80. package/dist/cjs/containerd/options/ContainerdRegistryAuthOptions.d.ts +32 -0
  81. package/dist/cjs/containerd/options/ContainerdRegistryAuthOptions.js +45 -0
  82. package/dist/cjs/containerd/options/container/ContainerCommitOptions.d.ts +57 -0
  83. package/dist/cjs/containerd/options/container/ContainerCommitOptions.js +66 -0
  84. package/dist/cjs/containerd/options/container/ContainerCreateOptions.d.ts +273 -0
  85. package/dist/cjs/containerd/options/container/ContainerCreateOptions.js +239 -0
  86. package/dist/cjs/containerd/options/container/ContainerExecOptions.d.ts +53 -0
  87. package/dist/cjs/containerd/options/container/ContainerExecOptions.js +63 -0
  88. package/dist/cjs/containerd/options/container/ContainerExportDirectoryOptions.d.ts +32 -0
  89. package/dist/cjs/containerd/options/container/ContainerExportDirectoryOptions.js +45 -0
  90. package/dist/cjs/containerd/options/container/ContainerKillOptions.d.ts +30 -0
  91. package/dist/cjs/containerd/options/container/ContainerKillOptions.js +41 -0
  92. package/dist/cjs/containerd/options/container/ContainerLogsOptions.d.ts +34 -0
  93. package/dist/cjs/containerd/options/container/ContainerLogsOptions.js +44 -0
  94. package/dist/cjs/containerd/options/container/ContainerRemoveOptions.d.ts +22 -0
  95. package/dist/cjs/containerd/options/container/ContainerRemoveOptions.js +34 -0
  96. package/dist/cjs/containerd/options/container/ContainerResourceOptions.d.ts +63 -0
  97. package/dist/cjs/containerd/options/container/ContainerResourceOptions.js +67 -0
  98. package/dist/cjs/containerd/options/container/ContainerStopOptions.d.ts +30 -0
  99. package/dist/cjs/containerd/options/container/ContainerStopOptions.js +41 -0
  100. package/dist/cjs/containerd/options/container/ContainerTTYConsoleSizeOptions.d.ts +26 -0
  101. package/dist/cjs/containerd/options/container/ContainerTTYConsoleSizeOptions.js +40 -0
  102. package/dist/cjs/containerd/options/container/ContainerTTYOptions.d.ts +50 -0
  103. package/dist/cjs/containerd/options/container/ContainerTTYOptions.js +63 -0
  104. package/dist/cjs/containerd/options/image/ImageBuildOptions.d.ts +88 -0
  105. package/dist/cjs/containerd/options/image/ImageBuildOptions.js +95 -0
  106. package/dist/cjs/containerd/options/image/ImageExportOptions.d.ts +25 -0
  107. package/dist/cjs/containerd/options/image/ImageExportOptions.js +39 -0
  108. package/dist/cjs/containerd/options/image/ImageImportOptions.d.ts +38 -0
  109. package/dist/cjs/containerd/options/image/ImageImportOptions.js +47 -0
  110. package/dist/cjs/containerd/options/image/ImagePullOptions.d.ts +53 -0
  111. package/dist/cjs/containerd/options/image/ImagePullOptions.js +66 -0
  112. package/dist/cjs/containerd/options/image/ImagePushOptions.d.ts +44 -0
  113. package/dist/cjs/containerd/options/image/ImagePushOptions.js +58 -0
  114. package/dist/cjs/containerd/options/network/NetworkCreateOptions.d.ts +82 -0
  115. package/dist/cjs/containerd/options/network/NetworkCreateOptions.js +83 -0
  116. package/dist/cjs/containerd/options/volume/VolumeCreateOptions.d.ts +26 -0
  117. package/dist/cjs/containerd/options/volume/VolumeCreateOptions.js +40 -0
  118. package/dist/cjs/containerd/types/ContainerdBind.d.ts +28 -0
  119. package/dist/cjs/containerd/types/ContainerdBind.js +2 -0
  120. package/dist/cjs/containerd/types/ContainerdBuildOutputCallback.d.ts +6 -0
  121. package/dist/cjs/containerd/types/ContainerdBuildOutputCallback.js +2 -0
  122. package/dist/cjs/containerd/types/ContainerdContainerNetwork.d.ts +40 -0
  123. package/dist/cjs/containerd/types/ContainerdContainerNetwork.js +2 -0
  124. package/dist/cjs/containerd/types/ContainerdContainerPort.d.ts +22 -0
  125. package/dist/cjs/containerd/types/ContainerdContainerPort.js +2 -0
  126. package/dist/cjs/containerd/types/ContainerdContainerState.d.ts +42 -0
  127. package/dist/cjs/containerd/types/ContainerdContainerState.js +2 -0
  128. package/dist/cjs/containerd/types/ContainerdContainerStats.d.ts +107 -0
  129. package/dist/cjs/containerd/types/ContainerdContainerStats.js +2 -0
  130. package/dist/cjs/containerd/types/ContainerdDevice.d.ts +25 -0
  131. package/dist/cjs/containerd/types/ContainerdDevice.js +2 -0
  132. package/dist/cjs/containerd/types/ContainerdExecResult.d.ts +18 -0
  133. package/dist/cjs/containerd/types/ContainerdExecResult.js +2 -0
  134. package/dist/cjs/containerd/types/ContainerdImageConfig.d.ts +46 -0
  135. package/dist/cjs/containerd/types/ContainerdImageConfig.js +2 -0
  136. package/dist/cjs/containerd/types/ContainerdNetworkInfo.d.ts +49 -0
  137. package/dist/cjs/containerd/types/ContainerdNetworkInfo.js +2 -0
  138. package/dist/cjs/containerd/types/ContainerdProgressCallback.d.ts +29 -0
  139. package/dist/cjs/containerd/types/ContainerdProgressCallback.js +2 -0
  140. package/dist/cjs/containerd/types/ContainerdPruneResult.d.ts +21 -0
  141. package/dist/cjs/containerd/types/ContainerdPruneResult.js +2 -0
  142. package/dist/cjs/containerd/types/ContainerdRestartPolicy.d.ts +13 -0
  143. package/dist/cjs/containerd/types/ContainerdRestartPolicy.js +2 -0
  144. package/dist/cjs/containerd/types/ContainerdTmpfs.d.ts +20 -0
  145. package/dist/cjs/containerd/types/ContainerdTmpfs.js +2 -0
  146. package/dist/cjs/containerd/types/ContainerdVolume.d.ts +19 -0
  147. package/dist/cjs/containerd/types/ContainerdVolume.js +2 -0
  148. package/dist/cjs/containerd/types/ContainerdVolumeInfo.d.ts +26 -0
  149. package/dist/cjs/containerd/types/ContainerdVolumeInfo.js +2 -0
  150. package/dist/cjs/exports/Containerd.d.ts +69 -0
  151. package/dist/cjs/exports/Containerd.js +87 -0
  152. package/dist/cjs/package.json +1 -0
  153. package/dist/esm/client/BuildKit.js +488 -0
  154. package/dist/esm/client/BuildKitMessages.js +120 -0
  155. package/dist/esm/client/ContainerStore.js +1339 -0
  156. package/dist/esm/client/ContainerdClient.js +416 -0
  157. package/dist/esm/client/DockerIgnore.js +179 -0
  158. package/dist/esm/client/Fifo.js +59 -0
  159. package/dist/esm/client/ImageStore.js +628 -0
  160. package/dist/esm/client/Messages.js +393 -0
  161. package/dist/esm/client/Networks.js +621 -0
  162. package/dist/esm/client/Platforms.js +156 -0
  163. package/dist/esm/client/Reference.js +66 -0
  164. package/dist/esm/client/Registry.js +263 -0
  165. package/dist/esm/client/Rootfs.js +234 -0
  166. package/dist/esm/client/Seccomp.js +152 -0
  167. package/dist/esm/client/Spec.js +220 -0
  168. package/dist/esm/client/Volumes.js +73 -0
  169. package/dist/esm/containerd/Containerd.js +923 -0
  170. package/dist/esm/containerd/exceptions/ContainerdConnectionException.js +12 -0
  171. package/dist/esm/containerd/exceptions/ContainerdContainerNameConflictException.js +11 -0
  172. package/dist/esm/containerd/exceptions/ContainerdContainerNotFoundException.js +12 -0
  173. package/dist/esm/containerd/exceptions/ContainerdContainerStateException.js +13 -0
  174. package/dist/esm/containerd/exceptions/ContainerdImageBuildException.js +12 -0
  175. package/dist/esm/containerd/exceptions/ContainerdImageExportException.js +12 -0
  176. package/dist/esm/containerd/exceptions/ContainerdImageImportException.js +12 -0
  177. package/dist/esm/containerd/exceptions/ContainerdImageNotFoundException.js +12 -0
  178. package/dist/esm/containerd/exceptions/ContainerdImagePullException.js +12 -0
  179. package/dist/esm/containerd/exceptions/ContainerdImagePushException.js +11 -0
  180. package/dist/esm/containerd/exceptions/ContainerdNetworkConflictException.js +12 -0
  181. package/dist/esm/containerd/exceptions/ContainerdNetworkNotFoundException.js +12 -0
  182. package/dist/esm/containerd/exceptions/ContainerdPathNotFoundException.js +11 -0
  183. package/dist/esm/containerd/exceptions/ContainerdPlatformException.js +12 -0
  184. package/dist/esm/containerd/exceptions/ContainerdVolumeInUseException.js +11 -0
  185. package/dist/esm/containerd/exceptions/ContainerdVolumeNotFoundException.js +11 -0
  186. package/dist/esm/containerd/lib/ContainerdContainer.js +533 -0
  187. package/dist/esm/containerd/lib/ContainerdContainerTTY.js +175 -0
  188. package/dist/esm/containerd/lib/ContainerdErrors.js +34 -0
  189. package/dist/esm/containerd/lib/ContainerdImage.js +219 -0
  190. package/dist/esm/containerd/options/ContainerdPruneOptions.js +47 -0
  191. package/dist/esm/containerd/options/ContainerdRegistryAuthOptions.js +41 -0
  192. package/dist/esm/containerd/options/container/ContainerCommitOptions.js +62 -0
  193. package/dist/esm/containerd/options/container/ContainerCreateOptions.js +235 -0
  194. package/dist/esm/containerd/options/container/ContainerExecOptions.js +59 -0
  195. package/dist/esm/containerd/options/container/ContainerExportDirectoryOptions.js +41 -0
  196. package/dist/esm/containerd/options/container/ContainerKillOptions.js +37 -0
  197. package/dist/esm/containerd/options/container/ContainerLogsOptions.js +40 -0
  198. package/dist/esm/containerd/options/container/ContainerRemoveOptions.js +30 -0
  199. package/dist/esm/containerd/options/container/ContainerResourceOptions.js +63 -0
  200. package/dist/esm/containerd/options/container/ContainerStopOptions.js +37 -0
  201. package/dist/esm/containerd/options/container/ContainerTTYConsoleSizeOptions.js +36 -0
  202. package/dist/esm/containerd/options/container/ContainerTTYOptions.js +59 -0
  203. package/dist/esm/containerd/options/image/ImageBuildOptions.js +91 -0
  204. package/dist/esm/containerd/options/image/ImageExportOptions.js +35 -0
  205. package/dist/esm/containerd/options/image/ImageImportOptions.js +43 -0
  206. package/dist/esm/containerd/options/image/ImagePullOptions.js +62 -0
  207. package/dist/esm/containerd/options/image/ImagePushOptions.js +54 -0
  208. package/dist/esm/containerd/options/network/NetworkCreateOptions.js +79 -0
  209. package/dist/esm/containerd/options/volume/VolumeCreateOptions.js +36 -0
  210. package/dist/esm/containerd/types/ContainerdBind.js +1 -0
  211. package/dist/esm/containerd/types/ContainerdBuildOutputCallback.js +1 -0
  212. package/dist/esm/containerd/types/ContainerdContainerNetwork.js +1 -0
  213. package/dist/esm/containerd/types/ContainerdContainerPort.js +1 -0
  214. package/dist/esm/containerd/types/ContainerdContainerState.js +1 -0
  215. package/dist/esm/containerd/types/ContainerdContainerStats.js +1 -0
  216. package/dist/esm/containerd/types/ContainerdDevice.js +1 -0
  217. package/dist/esm/containerd/types/ContainerdExecResult.js +1 -0
  218. package/dist/esm/containerd/types/ContainerdImageConfig.js +1 -0
  219. package/dist/esm/containerd/types/ContainerdNetworkInfo.js +1 -0
  220. package/dist/esm/containerd/types/ContainerdProgressCallback.js +1 -0
  221. package/dist/esm/containerd/types/ContainerdPruneResult.js +1 -0
  222. package/dist/esm/containerd/types/ContainerdRestartPolicy.js +1 -0
  223. package/dist/esm/containerd/types/ContainerdTmpfs.js +1 -0
  224. package/dist/esm/containerd/types/ContainerdVolume.js +1 -0
  225. package/dist/esm/containerd/types/ContainerdVolumeInfo.js +1 -0
  226. package/dist/esm/exports/Containerd.js +68 -0
  227. package/dist/types/client/BuildKit.d.ts +176 -0
  228. package/dist/types/client/BuildKitMessages.d.ts +35 -0
  229. package/dist/types/client/ContainerStore.d.ts +558 -0
  230. package/dist/types/client/ContainerdClient.d.ts +244 -0
  231. package/dist/types/client/DockerIgnore.d.ts +44 -0
  232. package/dist/types/client/Fifo.d.ts +31 -0
  233. package/dist/types/client/ImageStore.d.ts +258 -0
  234. package/dist/types/client/Messages.d.ts +103 -0
  235. package/dist/types/client/Networks.d.ts +221 -0
  236. package/dist/types/client/Platforms.d.ts +53 -0
  237. package/dist/types/client/Reference.d.ts +33 -0
  238. package/dist/types/client/Registry.d.ts +145 -0
  239. package/dist/types/client/Rootfs.d.ts +83 -0
  240. package/dist/types/client/Seccomp.d.ts +36 -0
  241. package/dist/types/client/Spec.d.ts +151 -0
  242. package/dist/types/client/Volumes.d.ts +42 -0
  243. package/dist/types/containerd/Containerd.d.ts +442 -0
  244. package/dist/types/containerd/exceptions/ContainerdConnectionException.d.ts +9 -0
  245. package/dist/types/containerd/exceptions/ContainerdContainerNameConflictException.d.ts +8 -0
  246. package/dist/types/containerd/exceptions/ContainerdContainerNotFoundException.d.ts +9 -0
  247. package/dist/types/containerd/exceptions/ContainerdContainerStateException.d.ts +10 -0
  248. package/dist/types/containerd/exceptions/ContainerdImageBuildException.d.ts +9 -0
  249. package/dist/types/containerd/exceptions/ContainerdImageExportException.d.ts +9 -0
  250. package/dist/types/containerd/exceptions/ContainerdImageImportException.d.ts +9 -0
  251. package/dist/types/containerd/exceptions/ContainerdImageNotFoundException.d.ts +9 -0
  252. package/dist/types/containerd/exceptions/ContainerdImagePullException.d.ts +9 -0
  253. package/dist/types/containerd/exceptions/ContainerdImagePushException.d.ts +8 -0
  254. package/dist/types/containerd/exceptions/ContainerdNetworkConflictException.d.ts +9 -0
  255. package/dist/types/containerd/exceptions/ContainerdNetworkNotFoundException.d.ts +9 -0
  256. package/dist/types/containerd/exceptions/ContainerdPathNotFoundException.d.ts +8 -0
  257. package/dist/types/containerd/exceptions/ContainerdPlatformException.d.ts +9 -0
  258. package/dist/types/containerd/exceptions/ContainerdVolumeInUseException.d.ts +8 -0
  259. package/dist/types/containerd/exceptions/ContainerdVolumeNotFoundException.d.ts +8 -0
  260. package/dist/types/containerd/lib/ContainerdContainer.d.ts +292 -0
  261. package/dist/types/containerd/lib/ContainerdContainerTTY.d.ts +116 -0
  262. package/dist/types/containerd/lib/ContainerdErrors.d.ts +6 -0
  263. package/dist/types/containerd/lib/ContainerdImage.d.ts +149 -0
  264. package/dist/types/containerd/options/ContainerdPruneOptions.d.ts +44 -0
  265. package/dist/types/containerd/options/ContainerdRegistryAuthOptions.d.ts +32 -0
  266. package/dist/types/containerd/options/container/ContainerCommitOptions.d.ts +57 -0
  267. package/dist/types/containerd/options/container/ContainerCreateOptions.d.ts +273 -0
  268. package/dist/types/containerd/options/container/ContainerExecOptions.d.ts +53 -0
  269. package/dist/types/containerd/options/container/ContainerExportDirectoryOptions.d.ts +32 -0
  270. package/dist/types/containerd/options/container/ContainerKillOptions.d.ts +30 -0
  271. package/dist/types/containerd/options/container/ContainerLogsOptions.d.ts +34 -0
  272. package/dist/types/containerd/options/container/ContainerRemoveOptions.d.ts +22 -0
  273. package/dist/types/containerd/options/container/ContainerResourceOptions.d.ts +63 -0
  274. package/dist/types/containerd/options/container/ContainerStopOptions.d.ts +30 -0
  275. package/dist/types/containerd/options/container/ContainerTTYConsoleSizeOptions.d.ts +26 -0
  276. package/dist/types/containerd/options/container/ContainerTTYOptions.d.ts +50 -0
  277. package/dist/types/containerd/options/image/ImageBuildOptions.d.ts +88 -0
  278. package/dist/types/containerd/options/image/ImageExportOptions.d.ts +25 -0
  279. package/dist/types/containerd/options/image/ImageImportOptions.d.ts +38 -0
  280. package/dist/types/containerd/options/image/ImagePullOptions.d.ts +53 -0
  281. package/dist/types/containerd/options/image/ImagePushOptions.d.ts +44 -0
  282. package/dist/types/containerd/options/network/NetworkCreateOptions.d.ts +82 -0
  283. package/dist/types/containerd/options/volume/VolumeCreateOptions.d.ts +26 -0
  284. package/dist/types/containerd/types/ContainerdBind.d.ts +28 -0
  285. package/dist/types/containerd/types/ContainerdBuildOutputCallback.d.ts +6 -0
  286. package/dist/types/containerd/types/ContainerdContainerNetwork.d.ts +40 -0
  287. package/dist/types/containerd/types/ContainerdContainerPort.d.ts +22 -0
  288. package/dist/types/containerd/types/ContainerdContainerState.d.ts +42 -0
  289. package/dist/types/containerd/types/ContainerdContainerStats.d.ts +107 -0
  290. package/dist/types/containerd/types/ContainerdDevice.d.ts +25 -0
  291. package/dist/types/containerd/types/ContainerdExecResult.d.ts +18 -0
  292. package/dist/types/containerd/types/ContainerdImageConfig.d.ts +46 -0
  293. package/dist/types/containerd/types/ContainerdNetworkInfo.d.ts +49 -0
  294. package/dist/types/containerd/types/ContainerdProgressCallback.d.ts +29 -0
  295. package/dist/types/containerd/types/ContainerdPruneResult.d.ts +21 -0
  296. package/dist/types/containerd/types/ContainerdRestartPolicy.d.ts +13 -0
  297. package/dist/types/containerd/types/ContainerdTmpfs.d.ts +20 -0
  298. package/dist/types/containerd/types/ContainerdVolume.d.ts +19 -0
  299. package/dist/types/containerd/types/ContainerdVolumeInfo.d.ts +26 -0
  300. package/dist/types/exports/Containerd.d.ts +69 -0
  301. package/package.json +51 -4
@@ -0,0 +1,636 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ImageStore = void 0;
7
+ exports.chainIds = chainIds;
8
+ const node_crypto_1 = require("node:crypto");
9
+ const node_fs_1 = require("node:fs");
10
+ const promises_1 = require("node:fs/promises");
11
+ const node_os_1 = __importDefault(require("node:os"));
12
+ const node_path_1 = __importDefault(require("node:path"));
13
+ const promises_2 = require("node:stream/promises");
14
+ const tar_stream_1 = require("tar-stream");
15
+ const ContainerdClient_js_1 = require("./ContainerdClient.js");
16
+ const grpc_1 = require("@lakutata/grpc");
17
+ const Platforms_js_1 = require("./Platforms.js");
18
+ const Reference_js_1 = require("./Reference.js");
19
+ const Registry_js_1 = require("./Registry.js");
20
+ /**
21
+ * The labels of containerd binding its content (its garbage collection keeps what an image references)
22
+ */
23
+ const Labels = {
24
+ contentRef: (kind, index) => `containerd.io/gc.ref.content.${kind}${index === undefined ? '' : `.${index}`}`,
25
+ snapshotRef: (snapshotter) => `containerd.io/gc.ref.snapshot.${snapshotter}`,
26
+ uncompressed: 'containerd.io/uncompressed',
27
+ source: (registry) => `containerd.io/distribution.source.${registry}`
28
+ };
29
+ /**
30
+ * The bytes of a stream, whole
31
+ * @param chunks
32
+ */
33
+ async function collect(chunks) {
34
+ const all = [];
35
+ for await (const chunk of chunks)
36
+ all.push(Buffer.from(chunk));
37
+ return Buffer.concat(all);
38
+ }
39
+ /**
40
+ * The identifiers of the chain of layers (OCI): the ones of the snapshots of their unpacking
41
+ * @param diffIds
42
+ */
43
+ function chainIds(diffIds) {
44
+ const chain = [];
45
+ for (const diffId of diffIds) {
46
+ chain.push(chain.length ? `sha256:${(0, node_crypto_1.createHash)('sha256').update(`${chain[chain.length - 1]} ${diffId}`).digest('hex')}` : diffId);
47
+ }
48
+ return chain;
49
+ }
50
+ /**
51
+ * The platform of the configuration of an image
52
+ * @param config
53
+ */
54
+ function configPlatform(config) {
55
+ return (0, Platforms_js_1.normalizePlatform)({ os: config.os, architecture: config.architecture, variant: config.variant });
56
+ }
57
+ /**
58
+ * The images of containerd: pulled from the registries, unpacked into the snapshots, pushed, imported and exported
59
+ * (OCI image layouts, the archives of docker save), as ctr and nerdctl do: their content bound by the labels of the
60
+ * garbage collection of containerd, under a lease until the image references it
61
+ */
62
+ class ImageStore {
63
+ /**
64
+ * @param client
65
+ * @param snapshotter
66
+ * @param temporary the directory of the archives extracted (a disk of the machine, not a small tmpfs)
67
+ * @param runnablePlatforms the platforms the machine runs, unpacked by the pulls and the imports (the one of the
68
+ * machine by default)
69
+ */
70
+ constructor(client, snapshotter, temporary = node_os_1.default.tmpdir(), runnablePlatforms = () => [(0, Platforms_js_1.hostPlatform)()]) {
71
+ this.client = client;
72
+ this.snapshotter = snapshotter;
73
+ this.temporary = temporary;
74
+ this.runnablePlatforms = runnablePlatforms;
75
+ }
76
+ /**
77
+ * The JSON of a content
78
+ * @param digest
79
+ */
80
+ async readJson(digest) {
81
+ return JSON.parse((await this.client.readAll(digest)).toString('utf8'));
82
+ }
83
+ /**
84
+ * The best manifest of an index for a platform, among the ones the content store has (or all)
85
+ * @param index
86
+ * @param platform
87
+ * @param local
88
+ */
89
+ async chooseManifest(index, platform, local) {
90
+ let best;
91
+ for (const descriptor of index.manifests) {
92
+ if (!(0, Registry_js_1.isManifest)(descriptor.mediaType) || !descriptor.platform)
93
+ continue;
94
+ const rank = (0, Platforms_js_1.platformRank)(descriptor.platform, platform);
95
+ if (rank === undefined || (best && best.rank <= rank))
96
+ continue;
97
+ if (local && !(await this.client.contentInfo(descriptor.digest)))
98
+ continue;
99
+ best = { descriptor: descriptor, rank: rank };
100
+ }
101
+ return best?.descriptor;
102
+ }
103
+ /**
104
+ * The image of a name (the reference given or its normalized name), undefined when it does not exist
105
+ * @param name
106
+ */
107
+ async get(name) {
108
+ return await this.client.getImage((0, Reference_js_1.imageName)(name)) ?? ((0, Reference_js_1.imageName)(name) === name ? undefined : await this.client.getImage(name));
109
+ }
110
+ /**
111
+ * Resolve an image for a platform: its manifest and its configuration (the manifest of the platform of its index)
112
+ * @param name
113
+ * @param platform the one of the machine by default
114
+ */
115
+ async resolve(name, platform = (0, Platforms_js_1.hostPlatform)()) {
116
+ const image = await this.get(name);
117
+ if (!image)
118
+ throw Object.assign(new Error(`The image ${name} does not exist`), { code: 'NOT_FOUND' });
119
+ const target = image.target;
120
+ let manifestDescriptor = target;
121
+ if ((0, Registry_js_1.isIndex)(target.mediaType)) {
122
+ const chosen = await this.chooseManifest(await this.readJson(target.digest), platform, true);
123
+ if (!chosen)
124
+ throw Object.assign(new Error(`The image ${name} has no manifest of the platform ${(0, Platforms_js_1.formatPlatform)(platform)}`), { code: 'PLATFORM' });
125
+ manifestDescriptor = chosen;
126
+ }
127
+ const manifest = await this.readJson(manifestDescriptor.digest);
128
+ const config = await this.readJson(manifest.config.digest);
129
+ return { image: image, name: image.name, target: target, manifestDescriptor: manifestDescriptor, manifest: manifest, config: config, platform: configPlatform(config) };
130
+ }
131
+ /**
132
+ * The platforms of an image the content store has (the ones pulled)
133
+ * @param name
134
+ */
135
+ async platforms(name) {
136
+ const image = await this.get(name);
137
+ if (!image)
138
+ return [];
139
+ if (!(0, Registry_js_1.isIndex)(image.target.mediaType))
140
+ return [configPlatform(await this.readJson((await this.readJson(image.target.digest)).config.digest))];
141
+ const platforms = [];
142
+ for (const descriptor of (await this.readJson(image.target.digest)).manifests) {
143
+ if (descriptor.platform && (0, Registry_js_1.isManifest)(descriptor.mediaType) && await this.client.contentInfo(descriptor.digest))
144
+ platforms.push((0, Platforms_js_1.normalizePlatform)(descriptor.platform));
145
+ }
146
+ return platforms;
147
+ }
148
+ /**
149
+ * Unpack the layers of an image into the snapshots of the snapshotter (named by the chain of their identifiers), the
150
+ * configuration bound to the last one
151
+ * @param manifest
152
+ * @param lease
153
+ */
154
+ async unpack(manifest, lease) {
155
+ const config = await this.readJson(manifest.config.digest);
156
+ const diffIds = config.rootfs?.diff_ids ?? [];
157
+ if (diffIds.length !== manifest.layers.length)
158
+ throw new Error(`The image ${manifest.config.digest} has ${manifest.layers.length} layers and ${diffIds.length} identifiers of them`);
159
+ const chain = chainIds(diffIds);
160
+ for (let index = 0; index < chain.length; index++) {
161
+ if (await this.client.statSnapshot(this.snapshotter, chain[index]))
162
+ continue;
163
+ const key = `extract-${(0, node_crypto_1.randomBytes)(6).toString('hex')}-${chain[index]}`;
164
+ const mounts = await this.client.prepareSnapshot(this.snapshotter, key, index ? chain[index - 1] : '', {}, lease);
165
+ try {
166
+ const applied = await this.client.applyLayer(manifest.layers[index], mounts, lease);
167
+ if (applied.digest !== diffIds[index])
168
+ throw new Error(`The layer ${manifest.layers[index].digest} unpacked is ${applied.digest}, not ${diffIds[index]}`);
169
+ await this.client.commitSnapshot(this.snapshotter, chain[index], key, {}, lease);
170
+ }
171
+ catch (error) {
172
+ await this.client.removeSnapshot(this.snapshotter, key);
173
+ //Unpacked meanwhile
174
+ if ((0, ContainerdClient_js_1.isGRPCError)(error, grpc_1.GRPCStatus.ALREADY_EXISTS))
175
+ continue;
176
+ throw error;
177
+ }
178
+ }
179
+ if (chain.length)
180
+ await this.client.labelContent(manifest.config.digest, { [Labels.snapshotRef(this.snapshotter)]: chain[chain.length - 1] });
181
+ return chain[chain.length - 1] ?? '';
182
+ }
183
+ /**
184
+ * Write a manifest, its configuration and its layers (the blobs given by a source), bound by the labels of the
185
+ * garbage collection
186
+ * @param manifest
187
+ * @param blob the bytes of a blob (its stream)
188
+ * @param lease
189
+ * @param labels the labels of all the content (its source)
190
+ * @param progress
191
+ */
192
+ async writeImage(manifest, blob, lease, labels, progress) {
193
+ const configData = await blob(manifest.config);
194
+ const configBytes = configData instanceof Uint8Array ? Buffer.from(configData) : await collect(configData);
195
+ await this.client.writeContent(manifest.config, configBytes, lease, labels);
196
+ const config = JSON.parse(configBytes.toString('utf8'));
197
+ for (let index = 0; index < manifest.layers.length; index++) {
198
+ const layer = manifest.layers[index];
199
+ const uncompressed = config.rootfs?.diff_ids?.[index] ? { [Labels.uncompressed]: config.rootfs.diff_ids[index] } : {};
200
+ if (await this.client.contentInfo(layer.digest)) {
201
+ await this.client.labelContent(layer.digest, { ...labels, ...uncompressed });
202
+ progress?.({ digest: layer.digest, mediaType: layer.mediaType, current: layer.size, total: layer.size });
203
+ continue;
204
+ }
205
+ const data = await blob(layer);
206
+ let current = 0;
207
+ const counted = async function* () {
208
+ for await (const chunk of data) {
209
+ current += chunk.length;
210
+ progress?.({ digest: layer.digest, mediaType: layer.mediaType, current: current, total: layer.size });
211
+ yield chunk;
212
+ }
213
+ };
214
+ await this.client.writeContent(layer, data instanceof Uint8Array ? data : counted(), lease, { ...labels, ...uncompressed });
215
+ }
216
+ }
217
+ /**
218
+ * The labels of a manifest binding its configuration and its layers
219
+ * @param manifest
220
+ */
221
+ manifestLabels(manifest) {
222
+ const labels = { [Labels.contentRef('config')]: manifest.config.digest };
223
+ manifest.layers.forEach((layer, index) => labels[Labels.contentRef('l', index)] = layer.digest);
224
+ return labels;
225
+ }
226
+ /**
227
+ * Pull an image from its registry: the manifests of the platforms asked (of its index), their configurations and
228
+ * their layers; the image named by its reference (docker.io/library/busybox:latest), unpacked for the machine
229
+ * @param reference
230
+ * @param options
231
+ */
232
+ async pull(reference, options = {}) {
233
+ const parsed = (0, Reference_js_1.parseReference)(reference);
234
+ const registry = new Registry_js_1.RegistryClient(parsed, options.registry);
235
+ const platforms = options.platforms ?? [(0, Platforms_js_1.hostPlatform)()];
236
+ const source = { [Labels.source(parsed.registry)]: parsed.repository };
237
+ const lease = await this.client.createLease();
238
+ try {
239
+ const root = await registry.resolve(parsed.digest ?? parsed.tag);
240
+ const manifests = [];
241
+ if ((0, Registry_js_1.isIndex)(root.descriptor.mediaType)) {
242
+ const index = JSON.parse(root.data.toString('utf8'));
243
+ const chosen = new Set();
244
+ if (platforms === 'all') {
245
+ index.manifests.filter((descriptor) => (0, Registry_js_1.isManifest)(descriptor.mediaType) && descriptor.platform?.os !== 'unknown').forEach((descriptor) => chosen.add(descriptor));
246
+ }
247
+ else {
248
+ for (const platform of platforms) {
249
+ const descriptor = await this.chooseManifest(index, platform, false);
250
+ if (!descriptor) {
251
+ const available = index.manifests.filter((item) => !!item.platform && item.platform.os !== 'unknown').map((item) => (0, Platforms_js_1.formatPlatform)((0, Platforms_js_1.normalizePlatform)(item.platform))).join(', ');
252
+ throw Object.assign(new Error(`The image ${parsed.name} has no manifest of the platform ${(0, Platforms_js_1.formatPlatform)(platform)} (it has ${available})`), { code: 'PLATFORM' });
253
+ }
254
+ chosen.add(descriptor);
255
+ }
256
+ }
257
+ for (const descriptor of chosen)
258
+ manifests.push({ descriptor: descriptor, data: await registry.fetchManifest(descriptor), index: index.manifests.indexOf(descriptor) });
259
+ }
260
+ else {
261
+ manifests.push(root);
262
+ }
263
+ for (const { descriptor, data } of manifests) {
264
+ const manifest = JSON.parse(data.toString('utf8'));
265
+ await this.writeImage(manifest, (blob) => registry.fetchBlob(blob), lease, source, options.progress);
266
+ await this.client.writeContent(descriptor, data, lease, { ...source, ...this.manifestLabels(manifest) });
267
+ }
268
+ if ((0, Registry_js_1.isIndex)(root.descriptor.mediaType)) {
269
+ const labels = { ...source };
270
+ manifests.forEach(({ descriptor, index }) => labels[Labels.contentRef('m', index)] = descriptor.digest);
271
+ await this.client.writeContent(root.descriptor, root.data, lease, labels);
272
+ }
273
+ await this.client.putImage({ name: parsed.name, target: root.descriptor }, lease);
274
+ if (options.unpack ?? true)
275
+ await this.unpackFor(parsed.name, lease);
276
+ return parsed.name;
277
+ }
278
+ finally {
279
+ await this.client.deleteLease(lease);
280
+ }
281
+ }
282
+ /**
283
+ * Unpack an image for the platforms the machine runs, among the ones the content store has (its manifests pulled):
284
+ * not the other platforms, nor the attestations (unknown/unknown)
285
+ * @param name
286
+ * @param lease
287
+ */
288
+ async unpackFor(name, lease) {
289
+ const image = await this.get(name);
290
+ if (!image)
291
+ return;
292
+ const manifests = (0, Registry_js_1.isIndex)(image.target.mediaType)
293
+ ? (await this.readJson(image.target.digest)).manifests.filter((descriptor) => (0, Registry_js_1.isManifest)(descriptor.mediaType))
294
+ : [image.target];
295
+ const runnable = this.runnablePlatforms();
296
+ for (const descriptor of manifests) {
297
+ if (!(await this.client.contentInfo(descriptor.digest)))
298
+ continue;
299
+ const manifest = await this.readJson(descriptor.digest);
300
+ const platform = descriptor.platform ? (0, Platforms_js_1.normalizePlatform)(descriptor.platform) : configPlatform(await this.readJson(manifest.config.digest));
301
+ if (!runnable.some((item) => (0, Platforms_js_1.matchPlatform)(platform, item)))
302
+ continue;
303
+ await this.unpack(manifest, lease);
304
+ }
305
+ }
306
+ /**
307
+ * Push an image to a registry (as another reference): the manifest of the platform asked; without it, the manifests
308
+ * of all the platforms and the index when the content store has all of them, the manifest of the machine's platform
309
+ * otherwise
310
+ * @param name
311
+ * @param options
312
+ */
313
+ async push(name, options = {}) {
314
+ const image = await this.get(name);
315
+ if (!image)
316
+ throw Object.assign(new Error(`The image ${name} does not exist`), { code: 'NOT_FOUND' });
317
+ const parsed = (0, Reference_js_1.parseReference)(options.reference ?? image.name);
318
+ const registry = new Registry_js_1.RegistryClient(parsed, options.registry);
319
+ const tag = parsed.tag ?? parsed.digest;
320
+ const pushManifest = async (descriptor, reference) => {
321
+ const data = await this.client.readAll(descriptor.digest);
322
+ const manifest = JSON.parse(data.toString('utf8'));
323
+ for (const blob of [manifest.config, ...manifest.layers]) {
324
+ await registry.pushBlob(blob, () => this.client.readContent(blob.digest));
325
+ options.progress?.({ digest: blob.digest, mediaType: blob.mediaType, current: blob.size, total: blob.size });
326
+ }
327
+ await registry.pushManifest(reference, descriptor.mediaType, data);
328
+ };
329
+ const target = image.target;
330
+ if (!(0, Registry_js_1.isIndex)(target.mediaType)) {
331
+ if (options.platform) {
332
+ const platform = configPlatform(await this.readJson((await this.readJson(target.digest)).config.digest));
333
+ if (!(0, Platforms_js_1.matchPlatform)(platform, options.platform))
334
+ throw Object.assign(new Error(`The image ${name} has no manifest of the platform ${(0, Platforms_js_1.formatPlatform)(options.platform)} to push (it is ${(0, Platforms_js_1.formatPlatform)(platform)})`), { code: 'PLATFORM' });
335
+ }
336
+ return await pushManifest(target, tag);
337
+ }
338
+ const index = await this.readJson(target.digest);
339
+ const local = [];
340
+ for (const descriptor of index.manifests)
341
+ if (await this.client.contentInfo(descriptor.digest))
342
+ local.push(descriptor);
343
+ if (!options.platform && local.length === index.manifests.length) {
344
+ for (const descriptor of local)
345
+ await pushManifest(descriptor, descriptor.digest);
346
+ return await registry.pushManifest(tag, target.mediaType, await this.client.readAll(target.digest));
347
+ }
348
+ const chosen = await this.chooseManifest(index, options.platform ?? (0, Platforms_js_1.hostPlatform)(), true);
349
+ if (!chosen)
350
+ throw Object.assign(new Error(`The image ${name} has no manifest of the platform ${(0, Platforms_js_1.formatPlatform)(options.platform ?? (0, Platforms_js_1.hostPlatform)())} to push`), { code: 'PLATFORM' });
351
+ await pushManifest(chosen, tag);
352
+ }
353
+ /**
354
+ * Commit the changes of a snapshot (the one of a container) on its image: a layer of their diff, the configuration
355
+ * of the image with its changes, a manifest of the platform, the image named (and unpacked)
356
+ * @param options
357
+ */
358
+ async commit(options) {
359
+ const base = await this.resolve(options.image, options.platform);
360
+ const name = (0, Reference_js_1.imageName)(options.name);
361
+ const lease = await this.client.createLease();
362
+ const view = `commit-${(0, node_crypto_1.randomBytes)(6).toString('hex')}`;
363
+ try {
364
+ const chain = chainIds(base.config.rootfs?.diff_ids ?? []);
365
+ const left = chain.length ? await this.client.viewSnapshot(this.snapshotter, view, chain[chain.length - 1], lease) : [];
366
+ const right = await this.client.snapshotMounts(this.snapshotter, options.snapshotKey);
367
+ const layer = await this.client.diff(left, right, lease);
368
+ const diffId = (await this.client.contentInfo(layer.digest))?.labels?.[Labels.uncompressed];
369
+ if (!diffId)
370
+ throw new Error(`The layer ${layer.digest} of the commit has no uncompressed digest`);
371
+ const created = new Date().toISOString();
372
+ const changes = options.changes ?? {};
373
+ const config = {
374
+ ...structuredClone(base.config),
375
+ created: created,
376
+ rootfs: { type: 'layers', diff_ids: [...base.config.rootfs?.diff_ids ?? [], diffId] }
377
+ };
378
+ const containerConfig = config.config ??= {};
379
+ if (changes.cmd)
380
+ containerConfig.Cmd = changes.cmd;
381
+ if (changes.entrypoint)
382
+ containerConfig.Entrypoint = changes.entrypoint;
383
+ if (changes.env) {
384
+ const env = new Map((containerConfig.Env ?? []).map((entry) => [entry.split('=')[0], entry]));
385
+ for (const entry of changes.env)
386
+ env.set(entry.split('=')[0], entry);
387
+ containerConfig.Env = [...env.values()];
388
+ }
389
+ if (changes.workingDir !== undefined)
390
+ containerConfig.WorkingDir = changes.workingDir;
391
+ if (changes.user !== undefined)
392
+ containerConfig.User = changes.user;
393
+ if (changes.labels)
394
+ containerConfig.Labels = { ...containerConfig.Labels ?? {}, ...changes.labels };
395
+ if (changes.exposedPorts)
396
+ containerConfig.ExposedPorts = { ...containerConfig.ExposedPorts ?? {}, ...Object.fromEntries(changes.exposedPorts.map((port) => [port.includes('/') ? port : `${port}/tcp`, {}])) };
397
+ if (options.author)
398
+ config.author = options.author;
399
+ config.history = [...config.history ?? [], { created: created, created_by: 'lakutata commit', ...options.comment ? { comment: options.comment } : {}, ...options.author ? { author: options.author } : {} }];
400
+ const configData = Buffer.from(JSON.stringify(config));
401
+ const configDescriptor = { mediaType: Registry_js_1.MediaTypes.OCI_CONFIG, digest: (0, Registry_js_1.digestOf)(configData), size: configData.length };
402
+ await this.client.writeContent(configDescriptor, configData, lease);
403
+ const manifest = {
404
+ schemaVersion: 2,
405
+ mediaType: Registry_js_1.MediaTypes.OCI_MANIFEST,
406
+ config: configDescriptor,
407
+ layers: [...base.manifest.layers.map((item) => ({ mediaType: item.mediaType, digest: item.digest, size: item.size })), { mediaType: layer.mediaType, digest: layer.digest, size: Number(layer.size) }]
408
+ };
409
+ const manifestData = Buffer.from(JSON.stringify(manifest));
410
+ const manifestDescriptor = { mediaType: Registry_js_1.MediaTypes.OCI_MANIFEST, digest: (0, Registry_js_1.digestOf)(manifestData), size: manifestData.length };
411
+ await this.client.writeContent(manifestDescriptor, manifestData, lease, this.manifestLabels(manifest));
412
+ await this.client.putImage({ name: name, target: manifestDescriptor }, lease);
413
+ await this.unpack(manifest, lease);
414
+ return name;
415
+ }
416
+ finally {
417
+ await this.client.removeSnapshot(this.snapshotter, view);
418
+ await this.client.deleteLease(lease);
419
+ }
420
+ }
421
+ /**
422
+ * Name an image again (a tag), its target the same
423
+ * @param name
424
+ * @param reference
425
+ */
426
+ async tag(name, reference) {
427
+ const image = await this.get(name);
428
+ if (!image)
429
+ throw Object.assign(new Error(`The image ${name} does not exist`), { code: 'NOT_FOUND' });
430
+ const target = (0, Reference_js_1.imageName)(reference);
431
+ await this.client.putImage({ name: target, target: image.target, labels: image.labels });
432
+ return target;
433
+ }
434
+ /**
435
+ * Remove an image (its content and its snapshots are collected by containerd once nothing references them)
436
+ * @param name
437
+ */
438
+ async remove(name) {
439
+ const image = await this.get(name);
440
+ if (!image)
441
+ throw Object.assign(new Error(`The image ${name} does not exist`), { code: 'NOT_FOUND' });
442
+ await this.client.deleteImage(image.name, true);
443
+ }
444
+ /**
445
+ * Import an archive of images: an OCI image layout (nerdctl save, docker save of Docker 25+), or an archive of
446
+ * docker save; the images named by the archive (or by a name given, to an archive of one image), unpacked for the
447
+ * platforms the machine runs
448
+ * @param source a file, or its stream
449
+ * @param options
450
+ */
451
+ async import(source, options = {}) {
452
+ await (0, promises_1.mkdir)(this.temporary, { recursive: true });
453
+ const directory = await (0, promises_1.mkdtemp)(node_path_1.default.join(this.temporary, 'lakutata-containerd-import-'));
454
+ const lease = await this.client.createLease();
455
+ try {
456
+ await this.extract(typeof source === 'string' ? (0, node_fs_1.createReadStream)(source) : source, directory);
457
+ const file = (name) => node_path_1.default.join(directory, ...name.split('/'));
458
+ const blobFile = (digest) => file(`blobs/${digest.replace(':', '/')}`);
459
+ const exists = async (name) => !!(await (0, promises_1.stat)(name).catch(() => undefined));
460
+ const names = [];
461
+ const named = (name) => options.name ? (0, Reference_js_1.imageName)(options.name) : name ? (0, Reference_js_1.imageName)(name) : undefined;
462
+ const index = await exists(file('index.json')) ? JSON.parse(await (0, promises_1.readFile)(file('index.json'), 'utf8')) : undefined;
463
+ const entries = await exists(file('manifest.json')) ? JSON.parse(await (0, promises_1.readFile)(file('manifest.json'), 'utf8')) : [];
464
+ if (options.name) {
465
+ //One name for one image (its tags: its entries of the same digest), checked before any import
466
+ const images = new Set((index?.manifests ?? []).map((entry) => entry.digest)).size || new Set(entries.map((entry) => entry.Config)).size;
467
+ if (images > 1)
468
+ throw new Error(`The archive has ${images} images: the name ${options.name} can only be given to an archive of one image`);
469
+ }
470
+ if (index) {
471
+ const blob = async (descriptor) => (0, node_fs_1.createReadStream)(blobFile(descriptor.digest));
472
+ for (const entry of index.manifests) {
473
+ const name = named(entry.annotations?.['io.containerd.image.name'] ?? entry.annotations?.['org.opencontainers.image.ref.name']);
474
+ await this.writeTree(entry, blob, lease);
475
+ if (!name)
476
+ continue;
477
+ await this.client.putImage({ name: name, target: { mediaType: entry.mediaType, digest: entry.digest, size: entry.size } }, lease);
478
+ if (!names.includes(name))
479
+ names.push(name);
480
+ }
481
+ }
482
+ if (!names.length && entries.length) {
483
+ //docker save: uncompressed layers (or compressed ones), the configuration, the tags
484
+ for (const entry of entries) {
485
+ const configData = await (0, promises_1.readFile)(file(entry.Config));
486
+ const layers = [];
487
+ const layerFiles = new Map();
488
+ for (const layer of entry.Layers) {
489
+ const data = await (0, promises_1.readFile)(file(layer));
490
+ const digest = (0, Registry_js_1.digestOf)(data);
491
+ const magic = data.subarray(0, 4).toString('hex');
492
+ const mediaType = magic.startsWith('1f8b') ? Registry_js_1.MediaTypes.DOCKER_LAYER_GZIP : magic === '28b52ffd' ? 'application/vnd.oci.image.layer.v1.tar+zstd' : Registry_js_1.MediaTypes.DOCKER_LAYER;
493
+ layers.push({ mediaType: mediaType, digest: digest, size: data.length });
494
+ layerFiles.set(digest, file(layer));
495
+ }
496
+ const manifest = { schemaVersion: 2, mediaType: Registry_js_1.MediaTypes.DOCKER_MANIFEST, config: { mediaType: Registry_js_1.MediaTypes.DOCKER_CONFIG, digest: (0, Registry_js_1.digestOf)(configData), size: configData.length }, layers: layers };
497
+ const manifestData = Buffer.from(JSON.stringify(manifest));
498
+ const descriptor = { mediaType: Registry_js_1.MediaTypes.DOCKER_MANIFEST, digest: (0, Registry_js_1.digestOf)(manifestData), size: manifestData.length };
499
+ await this.writeImage(manifest, async (blob) => blob.digest === manifest.config.digest ? configData : (0, node_fs_1.createReadStream)(layerFiles.get(blob.digest)), lease, {});
500
+ await this.client.writeContent(descriptor, manifestData, lease, this.manifestLabels(manifest));
501
+ const tags = options.name ? [options.name] : entry.RepoTags?.length ? entry.RepoTags : [`import-${Date.now()}@${descriptor.digest}`];
502
+ for (const tag of tags) {
503
+ const name = (0, Reference_js_1.imageName)(tag);
504
+ await this.client.putImage({ name: name, target: descriptor }, lease);
505
+ names.push(name);
506
+ }
507
+ }
508
+ }
509
+ if (!names.length)
510
+ throw new Error('The archive has no image: an OCI image layout (index.json) or an archive of docker save (manifest.json)');
511
+ if (options.unpack ?? true)
512
+ for (const name of names)
513
+ await this.unpackFor(name, lease);
514
+ return names;
515
+ }
516
+ finally {
517
+ await this.client.deleteLease(lease);
518
+ await (0, promises_1.rm)(directory, { recursive: true, force: true });
519
+ }
520
+ }
521
+ /**
522
+ * Write a manifest or an index of an archive, and what it references (the manifests the archive has)
523
+ * @param descriptor
524
+ * @param blob
525
+ * @param lease
526
+ */
527
+ async writeTree(descriptor, blob, lease) {
528
+ const data = await collect(await blob(descriptor));
529
+ if ((0, Registry_js_1.isIndex)(descriptor.mediaType)) {
530
+ const index = JSON.parse(data.toString('utf8'));
531
+ const labels = {};
532
+ for (let position = 0; position < index.manifests.length; position++) {
533
+ const child = index.manifests[position];
534
+ try {
535
+ await this.writeTree(child, blob, lease);
536
+ labels[Labels.contentRef('m', position)] = child.digest;
537
+ }
538
+ catch (error) {
539
+ //The archives of a platform have the index of all of them
540
+ if (error.code !== 'ENOENT')
541
+ throw error;
542
+ }
543
+ }
544
+ return await this.client.writeContent(descriptor, data, lease, labels);
545
+ }
546
+ const manifest = JSON.parse(data.toString('utf8'));
547
+ await this.writeImage(manifest, blob, lease, {});
548
+ await this.client.writeContent(descriptor, data, lease, this.manifestLabels(manifest));
549
+ }
550
+ /**
551
+ * Extract an archive into a directory
552
+ * @param source
553
+ * @param directory
554
+ */
555
+ async extract(source, directory) {
556
+ const extractor = (0, tar_stream_1.extract)();
557
+ extractor.on('entry', (header, entry, next) => {
558
+ const stream = entry;
559
+ const target = node_path_1.default.resolve(directory, header.name);
560
+ if (header.type !== 'file' || !target.startsWith(directory + node_path_1.default.sep)) {
561
+ stream.on('end', () => next()).resume();
562
+ return;
563
+ }
564
+ (0, promises_1.mkdir)(node_path_1.default.dirname(target), { recursive: true })
565
+ .then(() => (0, promises_2.pipeline)(stream, (0, node_fs_1.createWriteStream)(target)))
566
+ .then(() => next(), (error) => next(error));
567
+ });
568
+ await (0, promises_2.pipeline)(source, extractor);
569
+ }
570
+ /**
571
+ * Export images into an archive: an OCI image layout (named by io.containerd.image.name), with the manifest.json of
572
+ * docker load (the manifest of the platform of the machine, or the first one)
573
+ * @param names
574
+ * @param destination a file, or its stream
575
+ */
576
+ async export(names, destination) {
577
+ const blobs = new Map();
578
+ const entries = [];
579
+ const dockerManifests = [];
580
+ const blobPath = (digest) => `blobs/${digest.replace(':', '/')}`;
581
+ for (const name of names) {
582
+ const image = await this.get(name);
583
+ if (!image)
584
+ throw Object.assign(new Error(`The image ${name} does not exist`), { code: 'NOT_FOUND' });
585
+ const target = { mediaType: image.target.mediaType, digest: image.target.digest, size: Number(image.target.size) };
586
+ const reference = (() => {
587
+ try {
588
+ return (0, Reference_js_1.parseReference)(image.name);
589
+ }
590
+ catch {
591
+ return undefined;
592
+ }
593
+ })();
594
+ entries.push({ ...target, annotations: { 'io.containerd.image.name': image.name, ...reference?.tag ? { 'org.opencontainers.image.ref.name': reference.tag } : {} } });
595
+ blobs.set(target.digest, target);
596
+ const manifests = (0, Registry_js_1.isIndex)(target.mediaType) ? (await this.readJson(target.digest)).manifests : [target];
597
+ let first;
598
+ for (const descriptor of manifests) {
599
+ if (!(0, Registry_js_1.isManifest)(descriptor.mediaType) || !(await this.client.contentInfo(descriptor.digest)))
600
+ continue;
601
+ const manifest = await this.readJson(descriptor.digest);
602
+ blobs.set(descriptor.digest, descriptor);
603
+ for (const blob of [manifest.config, ...manifest.layers])
604
+ blobs.set(blob.digest, blob);
605
+ const config = await this.readJson(manifest.config.digest);
606
+ if (!first || (0, Platforms_js_1.platformRank)(configPlatform(config), (0, Platforms_js_1.hostPlatform)()) !== undefined)
607
+ first = manifest;
608
+ }
609
+ if (first && reference) {
610
+ const short = reference.registry === 'docker.io' ? reference.repository.replace(/^library\//, '') : `${reference.registry}/${reference.repository}`;
611
+ dockerManifests.push({ Config: blobPath(first.config.digest), RepoTags: reference.tag ? [`${short}:${reference.tag}`] : [], Layers: first.layers.map((layer) => blobPath(layer.digest)) });
612
+ }
613
+ }
614
+ const archive = (0, tar_stream_1.pack)();
615
+ const output = (0, promises_2.pipeline)(archive, typeof destination === 'string' ? (0, node_fs_1.createWriteStream)(destination) : destination);
616
+ const entry = (name, data) => new Promise((resolve, reject) => void archive.entry({ name: name, size: data.length, mode: 0o644 }, data, (error) => error ? reject(error) : resolve()));
617
+ try {
618
+ await entry('oci-layout', Buffer.from(JSON.stringify({ imageLayoutVersion: '1.0.0' })));
619
+ for (const blob of blobs.values()) {
620
+ const size = Number((await this.client.contentInfo(blob.digest))?.size ?? blob.size);
621
+ await new Promise((resolve, reject) => {
622
+ const writer = archive.entry({ name: blobPath(blob.digest), size: size, mode: 0o644 }, (error) => error ? reject(error) : resolve());
623
+ (0, promises_2.pipeline)(this.client.readContent(blob.digest), writer).catch(reject);
624
+ });
625
+ }
626
+ await entry('index.json', Buffer.from(JSON.stringify({ schemaVersion: 2, mediaType: Registry_js_1.MediaTypes.OCI_INDEX, manifests: entries })));
627
+ await entry('manifest.json', Buffer.from(JSON.stringify(dockerManifests)));
628
+ archive.finalize();
629
+ }
630
+ catch (error) {
631
+ archive.destroy(error);
632
+ }
633
+ await output;
634
+ }
635
+ }
636
+ exports.ImageStore = ImageStore;