@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,416 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { GRPCConnection, GRPCError, GRPCStatus, decode } from '@lakutata/grpc';
3
+ import * as M from './Messages.js';
4
+ /**
5
+ * The prefix of the paths of the services of containerd
6
+ */
7
+ const SERVICES = '/containerd.services';
8
+ /**
9
+ * The type URL of the specifications of the containers and of their processes (OCI runtime spec, JSON)
10
+ */
11
+ export const SPEC_TYPE_URL = 'types.containerd.io/opencontainers/runtime-spec/1/Spec';
12
+ export const PROCESS_TYPE_URL = 'types.containerd.io/opencontainers/runtime-spec/1/Process';
13
+ export const RESOURCES_TYPE_URL = 'types.containerd.io/opencontainers/runtime-spec/1/LinuxResources';
14
+ /**
15
+ * A date of a Timestamp
16
+ * @param timestamp
17
+ */
18
+ export function timestampDate(timestamp) {
19
+ if (!timestamp)
20
+ return undefined;
21
+ return new Date(Number(timestamp.seconds ?? 0) * 1000 + Math.floor(Number(timestamp.nanos ?? 0) / 1e6));
22
+ }
23
+ /**
24
+ * Whether an error is the one of a call of a code
25
+ * @param error
26
+ * @param code
27
+ */
28
+ export function isGRPCError(error, code) {
29
+ return error instanceof GRPCError && error.code === code;
30
+ }
31
+ /**
32
+ * The client of the API of containerd (its services of the version 1), in a namespace: its calls are the ones of
33
+ * ctr and nerdctl
34
+ */
35
+ export class ContainerdClient {
36
+ constructor(socketPath, namespace) {
37
+ this.namespace = namespace;
38
+ this.grpc = new GRPCConnection(socketPath);
39
+ }
40
+ /**
41
+ * The options of a call: its namespace, its lease (the content and the snapshots it creates are kept by it until
42
+ * they are referenced)
43
+ * @param lease
44
+ * @param signal
45
+ */
46
+ options(lease, signal) {
47
+ return { metadata: { 'containerd-namespace': this.namespace, 'containerd-lease': lease }, signal: signal };
48
+ }
49
+ /**
50
+ * Call a method of a service
51
+ * @param service its name and its version (images.v1.Images)
52
+ * @param method
53
+ * @param requestSchema
54
+ * @param request
55
+ * @param responseSchema
56
+ * @param lease
57
+ * @param signal
58
+ */
59
+ call(service, method, requestSchema, request, responseSchema = M.Empty, lease, signal) {
60
+ return this.grpc.unary(`${SERVICES}.${service}/${method}`, requestSchema, request, responseSchema, this.options(lease, signal));
61
+ }
62
+ /**
63
+ * Call a method, undefined when what it reads does not exist
64
+ * @param promise
65
+ */
66
+ async orUndefined(promise) {
67
+ try {
68
+ return await promise;
69
+ }
70
+ catch (error) {
71
+ if (isGRPCError(error, GRPCStatus.NOT_FOUND))
72
+ return undefined;
73
+ throw error;
74
+ }
75
+ }
76
+ /*
77
+ * Version, namespaces
78
+ */
79
+ async version() {
80
+ return await this.call('version.v1.Version', 'Version', M.Empty, {}, M.VersionResponse);
81
+ }
82
+ /**
83
+ * Create the namespace of the client, when it does not exist
84
+ */
85
+ async ensureNamespace() {
86
+ try {
87
+ await this.call('namespaces.v1.Namespaces', 'Create', M.CreateNamespaceRequest, { namespace: { name: this.namespace } }, M.Empty);
88
+ }
89
+ catch (error) {
90
+ if (!isGRPCError(error, GRPCStatus.ALREADY_EXISTS))
91
+ throw error;
92
+ }
93
+ }
94
+ /*
95
+ * Leases
96
+ */
97
+ /**
98
+ * Create a lease, which keeps what is created under it until it is deleted (or expired)
99
+ * @param expireSeconds
100
+ */
101
+ async createLease(expireSeconds = 24 * 3600) {
102
+ const id = `lakutata-${Date.now()}-${randomBytes(4).toString('hex')}`;
103
+ const expire = new Date(Date.now() + expireSeconds * 1000).toISOString();
104
+ await this.call('leases.v1.Leases', 'Create', M.CreateLeaseRequest, { id: id, labels: { 'containerd.io/gc.expire': expire } }, M.CreateLeaseResponse);
105
+ return id;
106
+ }
107
+ async deleteLease(id) {
108
+ await this.orUndefined(this.call('leases.v1.Leases', 'Delete', M.DeleteLeaseRequest, { id: id }));
109
+ }
110
+ /*
111
+ * Images
112
+ */
113
+ async getImage(name) {
114
+ return (await this.orUndefined(this.call('images.v1.Images', 'Get', M.GetImageRequest, { name: name }, M.ImageResponse)))?.image;
115
+ }
116
+ async listImages(filters = []) {
117
+ return (await this.call('images.v1.Images', 'List', M.ListImagesRequest, { filters: filters }, M.ListImagesResponse)).images;
118
+ }
119
+ /**
120
+ * Create an image, or update it when it exists (its target and its labels)
121
+ * @param image
122
+ * @param lease
123
+ */
124
+ async putImage(image, lease) {
125
+ try {
126
+ return (await this.call('images.v1.Images', 'Create', M.CreateImageRequest, { image: image }, M.ImageResponse, lease)).image;
127
+ }
128
+ catch (error) {
129
+ if (!isGRPCError(error, GRPCStatus.ALREADY_EXISTS))
130
+ throw error;
131
+ return (await this.call('images.v1.Images', 'Update', M.UpdateImageRequest, { image: image, updateMask: { paths: ['target', 'labels'] } }, M.ImageResponse, lease)).image;
132
+ }
133
+ }
134
+ async deleteImage(name, sync = false) {
135
+ await this.call('images.v1.Images', 'Delete', M.DeleteImageRequest, { name: name, sync: sync });
136
+ }
137
+ /*
138
+ * Content
139
+ */
140
+ async contentInfo(digest) {
141
+ return (await this.orUndefined(this.call('content.v1.Content', 'Info', M.InfoRequest, { digest: digest }, M.InfoResponse)))?.info;
142
+ }
143
+ /**
144
+ * Set labels of a content
145
+ * @param digest
146
+ * @param labels
147
+ */
148
+ async labelContent(digest, labels) {
149
+ if (!Object.keys(labels).length)
150
+ return;
151
+ await this.call('content.v1.Content', 'Update', M.UpdateContentRequest, {
152
+ info: { digest: digest, labels: labels },
153
+ updateMask: { paths: Object.keys(labels).map((key) => `labels.${key}`) }
154
+ }, M.InfoResponse);
155
+ }
156
+ /**
157
+ * Read a content, by its chunks
158
+ * @param digest
159
+ * @param signal
160
+ */
161
+ async *readContent(digest, signal) {
162
+ const responses = this.grpc.serverStream(`${SERVICES}.content.v1.Content/Read`, M.ReadContentRequest, { digest: digest }, M.ReadContentResponse, this.options(undefined, signal));
163
+ for await (const response of responses)
164
+ if (response.data?.length)
165
+ yield response.data;
166
+ }
167
+ /**
168
+ * Read a content whole
169
+ * @param digest
170
+ */
171
+ async readAll(digest) {
172
+ const chunks = [];
173
+ for await (const chunk of this.readContent(digest))
174
+ chunks.push(chunk);
175
+ return Buffer.concat(chunks);
176
+ }
177
+ /**
178
+ * Write a content, checked by its digest (a content which exists is kept), its labels set
179
+ * @param descriptor its digest and its size
180
+ * @param data its bytes, or their chunks
181
+ * @param lease
182
+ * @param labels
183
+ * @param signal
184
+ */
185
+ async writeContent(descriptor, data, lease, labels = {}, signal) {
186
+ if (await this.contentInfo(descriptor.digest)) {
187
+ await this.labelContent(descriptor.digest, labels);
188
+ return;
189
+ }
190
+ const ref = `lakutata-${descriptor.digest}-${randomBytes(4).toString('hex')}`;
191
+ const stream = this.grpc.bidi(`${SERVICES}.content.v1.Content/Write`, M.WriteContentRequest, M.WriteContentResponse, this.options(lease, signal));
192
+ //The responses read while the requests are sent (one by request)
193
+ const responses = (async () => {
194
+ const all = [];
195
+ for await (const response of stream.responses)
196
+ all.push(response);
197
+ return all;
198
+ })();
199
+ responses.catch(() => undefined);
200
+ try {
201
+ let offset = 0;
202
+ const send = async (chunk) => {
203
+ //Messages of 1 MiB at most (the maximum message of gRPC is 4 MiB)
204
+ for (let start = 0; start < chunk.length; start += 1024 * 1024) {
205
+ const part = chunk.subarray(start, start + 1024 * 1024);
206
+ await stream.send({ action: M.WriteAction.WRITE, ref: ref, total: descriptor.size, expected: descriptor.digest, offset: offset, data: part });
207
+ offset += part.length;
208
+ }
209
+ };
210
+ if (data instanceof Uint8Array)
211
+ await send(data);
212
+ else
213
+ for await (const chunk of data)
214
+ await send(chunk);
215
+ await stream.send({ action: M.WriteAction.COMMIT, ref: ref, total: descriptor.size, expected: descriptor.digest, offset: offset, labels: labels });
216
+ stream.end();
217
+ const answers = await responses;
218
+ const committed = answers.find((answer) => answer.action === M.WriteAction.COMMIT);
219
+ if (committed && committed.digest !== descriptor.digest)
220
+ throw new Error(`The content written is ${committed.digest}, not ${descriptor.digest}`);
221
+ }
222
+ catch (error) {
223
+ stream.cancel();
224
+ //Written by another writer meanwhile
225
+ if (isGRPCError(error, GRPCStatus.ALREADY_EXISTS) || (await this.contentInfo(descriptor.digest))) {
226
+ await this.labelContent(descriptor.digest, labels);
227
+ return;
228
+ }
229
+ await this.orUndefined(this.call('content.v1.Content', 'Abort', M.AbortRequest, { ref: ref }));
230
+ throw error;
231
+ }
232
+ }
233
+ async deleteContent(digest) {
234
+ await this.orUndefined(this.call('content.v1.Content', 'Delete', M.DeleteContentRequest, { digest: digest }));
235
+ }
236
+ /*
237
+ * Snapshots, diff
238
+ */
239
+ async prepareSnapshot(snapshotter, key, parent, labels = {}, lease) {
240
+ return (await this.call('snapshots.v1.Snapshots', 'Prepare', M.PrepareSnapshotRequest, { snapshotter: snapshotter, key: key, parent: parent, labels: labels }, M.MountsResponse, lease)).mounts;
241
+ }
242
+ async snapshotMounts(snapshotter, key) {
243
+ return (await this.call('snapshots.v1.Snapshots', 'Mounts', M.MountsRequest, { snapshotter: snapshotter, key: key }, M.MountsResponse)).mounts;
244
+ }
245
+ async commitSnapshot(snapshotter, name, key, labels = {}, lease) {
246
+ await this.call('snapshots.v1.Snapshots', 'Commit', M.CommitSnapshotRequest, { snapshotter: snapshotter, name: name, key: key, labels: labels }, M.Empty, lease);
247
+ }
248
+ async viewSnapshot(snapshotter, key, parent, lease) {
249
+ return (await this.call('snapshots.v1.Snapshots', 'View', M.PrepareSnapshotRequest, { snapshotter: snapshotter, key: key, parent: parent }, M.MountsResponse, lease)).mounts;
250
+ }
251
+ /**
252
+ * The layer of the changes of a snapshot from another one (tar+gzip), written into the content store
253
+ * @param left the older one
254
+ * @param right the newer one
255
+ * @param lease
256
+ */
257
+ async diff(left, right, lease) {
258
+ return (await this.call('diff.v1.Diff', 'Diff', M.DiffRequest, { left: left, right: right, mediaType: 'application/vnd.oci.image.layer.v1.tar+gzip' }, M.DiffResponse, lease)).diff;
259
+ }
260
+ /**
261
+ * The metrics of the cgroup of a task: their type (io.containerd.cgroups.v1.Metrics, …v2.Metrics) and their bytes
262
+ * @param containerId
263
+ */
264
+ async metrics(containerId) {
265
+ return (await this.call('tasks.v1.Tasks', 'Metrics', M.MetricsRequest, { filters: [`id==${containerId}`] }, M.MetricsResponse)).metrics[0];
266
+ }
267
+ async removeSnapshot(snapshotter, key) {
268
+ await this.orUndefined(this.call('snapshots.v1.Snapshots', 'Remove', M.SnapshotKeyRequest, { snapshotter: snapshotter, key: key }));
269
+ }
270
+ async statSnapshot(snapshotter, key) {
271
+ return (await this.orUndefined(this.call('snapshots.v1.Snapshots', 'Stat', M.SnapshotKeyRequest, { snapshotter: snapshotter, key: key }, M.StatSnapshotResponse)))?.info;
272
+ }
273
+ async snapshotUsage(snapshotter, key) {
274
+ return await this.call('snapshots.v1.Snapshots', 'Usage', M.SnapshotKeyRequest, { snapshotter: snapshotter, key: key }, M.UsageResponse);
275
+ }
276
+ /**
277
+ * Apply a layer (its content) to the mounts of a snapshot
278
+ * @param layer
279
+ * @param mounts
280
+ * @param lease
281
+ */
282
+ async applyLayer(layer, mounts, lease) {
283
+ return (await this.call('diff.v1.Diff', 'Apply', M.ApplyRequest, { diff: { mediaType: layer.mediaType, digest: layer.digest, size: layer.size }, mounts: mounts }, M.ApplyResponse, lease)).applied;
284
+ }
285
+ /*
286
+ * Containers
287
+ */
288
+ async getContainer(id) {
289
+ return (await this.orUndefined(this.call('containers.v1.Containers', 'Get', M.GetContainerRequest, { id: id }, M.ContainerResponse)))?.container;
290
+ }
291
+ async listContainers(filters = []) {
292
+ return (await this.call('containers.v1.Containers', 'List', M.ListContainersRequest, { filters: filters }, M.ListContainersResponse)).containers;
293
+ }
294
+ async createContainer(container, lease) {
295
+ return (await this.call('containers.v1.Containers', 'Create', M.CreateContainerRequest, { container: container }, M.ContainerResponse, lease)).container;
296
+ }
297
+ async updateContainer(container, paths) {
298
+ return (await this.call('containers.v1.Containers', 'Update', M.UpdateContainerRequest, { container: container, updateMask: { paths: paths } }, M.ContainerResponse)).container;
299
+ }
300
+ async deleteContainer(id) {
301
+ await this.orUndefined(this.call('containers.v1.Containers', 'Delete', M.DeleteContainerRequest, { id: id }));
302
+ }
303
+ /*
304
+ * Tasks
305
+ */
306
+ async createTask(request) {
307
+ return (await this.call('tasks.v1.Tasks', 'Create', M.CreateTaskRequest, request, M.CreateTaskResponse)).pid ?? 0;
308
+ }
309
+ async startTask(containerId, execId = '') {
310
+ return (await this.call('tasks.v1.Tasks', 'Start', M.ProcessRequest, { containerId: containerId, execId: execId }, M.StartResponse)).pid ?? 0;
311
+ }
312
+ async deleteTask(containerId) {
313
+ return await this.orUndefined(this.call('tasks.v1.Tasks', 'Delete', M.DeleteTaskRequest, { containerId: containerId }, M.DeleteTaskResponse));
314
+ }
315
+ async deleteProcess(containerId, execId) {
316
+ return await this.orUndefined(this.call('tasks.v1.Tasks', 'DeleteProcess', M.ProcessRequest, { containerId: containerId, execId: execId }, M.DeleteTaskResponse));
317
+ }
318
+ async getTask(containerId, execId = '') {
319
+ return (await this.orUndefined(this.call('tasks.v1.Tasks', 'Get', M.ProcessRequest, { containerId: containerId, execId: execId }, M.GetTaskResponse)))?.process;
320
+ }
321
+ async listTasks() {
322
+ return (await this.call('tasks.v1.Tasks', 'List', M.ListTasksRequest, {}, M.ListTasksResponse)).tasks;
323
+ }
324
+ async kill(containerId, signal, options = {}) {
325
+ await this.call('tasks.v1.Tasks', 'Kill', M.KillRequest, { containerId: containerId, execId: options.execId ?? '', signal: signal, all: options.all ?? false });
326
+ }
327
+ async exec(request) {
328
+ await this.call('tasks.v1.Tasks', 'Exec', M.ExecProcessRequest, request);
329
+ }
330
+ async resizePty(containerId, execId, width, height) {
331
+ await this.call('tasks.v1.Tasks', 'ResizePty', M.ResizePtyRequest, { containerId: containerId, execId: execId, width: width, height: height });
332
+ }
333
+ async closeIO(containerId, execId) {
334
+ await this.call('tasks.v1.Tasks', 'CloseIO', M.CloseIORequest, { containerId: containerId, execId: execId, stdin: true });
335
+ }
336
+ async pause(containerId) {
337
+ await this.call('tasks.v1.Tasks', 'Pause', M.ContainerIdRequest, { containerId: containerId });
338
+ }
339
+ async resume(containerId) {
340
+ await this.call('tasks.v1.Tasks', 'Resume', M.ContainerIdRequest, { containerId: containerId });
341
+ }
342
+ async listPids(containerId) {
343
+ return (await this.call('tasks.v1.Tasks', 'ListPids', M.ContainerIdRequest, { containerId: containerId }, M.ListPidsResponse)).processes.map((process) => process.pid);
344
+ }
345
+ /**
346
+ * Wait for a process to exit (the task, an exec)
347
+ * @param containerId
348
+ * @param execId
349
+ * @param signal
350
+ */
351
+ async wait(containerId, execId = '', signal) {
352
+ const response = await this.call('tasks.v1.Tasks', 'Wait', M.ProcessRequest, { containerId: containerId, execId: execId }, M.WaitResponse, undefined, signal);
353
+ return { exitStatus: response.exitStatus ?? 0, exitedAt: timestampDate(response.exitedAt) };
354
+ }
355
+ /**
356
+ * Update the resources of a task (OCI LinuxResources)
357
+ * @param containerId
358
+ * @param resources
359
+ */
360
+ async updateTask(containerId, resources) {
361
+ await this.call('tasks.v1.Tasks', 'Update', M.UpdateTaskRequest, { containerId: containerId, resources: { typeUrl: RESOURCES_TYPE_URL, value: Buffer.from(JSON.stringify(resources)) } });
362
+ }
363
+ /*
364
+ * Events
365
+ */
366
+ /**
367
+ * The events of containerd, their fields decoded (the ones of the tasks, the containers and the images)
368
+ * @param filters the filters of containerd (topic~="/tasks/", namespace==default)
369
+ * @param signal its end
370
+ */
371
+ async *subscribe(filters = [], signal) {
372
+ //The events of all the namespaces: filtered by namespace
373
+ const responses = this.grpc.serverStream(`${SERVICES}.events.v1.Events/Subscribe`, M.SubscribeRequest, { filters: filters }, M.Envelope, { signal: signal });
374
+ try {
375
+ for await (const envelope of responses) {
376
+ const type = String(envelope.event?.typeUrl ?? '');
377
+ const schema = M.EVENTS[type];
378
+ yield {
379
+ timestamp: timestampDate(envelope.timestamp) ?? new Date(),
380
+ namespace: envelope.namespace ?? '',
381
+ topic: envelope.topic ?? '',
382
+ type: type,
383
+ event: schema && envelope.event?.value ? decode(schema, envelope.event.value) : {}
384
+ };
385
+ }
386
+ }
387
+ catch (error) {
388
+ if (signal?.aborted && isGRPCError(error, GRPCStatus.CANCELLED))
389
+ return;
390
+ throw error;
391
+ }
392
+ }
393
+ /**
394
+ * An Any of JSON (the specifications of OCI)
395
+ * @param typeUrl
396
+ * @param value
397
+ */
398
+ static Json(typeUrl, value) {
399
+ return { typeUrl: typeUrl, value: Buffer.from(JSON.stringify(value)) };
400
+ }
401
+ /**
402
+ * The value of an Any of JSON
403
+ * @param any
404
+ */
405
+ static FromJson(any) {
406
+ if (!any?.value?.length)
407
+ return undefined;
408
+ return JSON.parse(Buffer.from(any.value).toString('utf8'));
409
+ }
410
+ /**
411
+ * Close the connection
412
+ */
413
+ close() {
414
+ this.grpc.close();
415
+ }
416
+ }
@@ -0,0 +1,179 @@
1
+ /*
2
+ * The rules of the .dockerignore files, rewritten from @balena/dockerignore (Copyright 2020 Balena Ltd., Apache License
3
+ * 2.0, and Copyright 2018 Zeit, Inc., MIT License, see THIRD_PARTY_NOTICES.md), which follows the implementation of
4
+ * Docker (moby/moby builder/dockerignore and pkg/fileutils)
5
+ */
6
+ import path from 'node:path';
7
+ /**
8
+ * The separators of the paths of the platform: on Windows, "/" and "\" separate the paths and "\" does not escape
9
+ */
10
+ const SEPARATOR = path.sep;
11
+ /**
12
+ * filepath.Clean of Go
13
+ * @param file
14
+ */
15
+ function cleanPath(file) {
16
+ return path.normalize(file).replace(SEPARATOR === '\\' ? /(?<=.)\\$/ : /(?<=.)\/$/, '');
17
+ }
18
+ /**
19
+ * filepath.ToSlash of Go
20
+ * @param file
21
+ */
22
+ function toSlash(file) {
23
+ return SEPARATOR === '/' ? file : file.replace(/\\/g, '/');
24
+ }
25
+ /**
26
+ * filepath.FromSlash of Go
27
+ * @param file
28
+ */
29
+ function fromSlash(file) {
30
+ return SEPARATOR === '/' ? file : file.replace(/\//g, SEPARATOR);
31
+ }
32
+ /**
33
+ * The rules of a .dockerignore file: the files of a build context they exclude
34
+ */
35
+ export class DockerIgnore {
36
+ #rules = [];
37
+ #cache = new Map();
38
+ /**
39
+ * @param content the content of a .dockerignore file
40
+ * @param ignoreCase match the case-insensitively, as Docker does not (false by default)
41
+ */
42
+ constructor(content = '', ignoreCase = false) {
43
+ this.ignoreCase = ignoreCase;
44
+ this.add(content);
45
+ }
46
+ /**
47
+ * Add the rules of a content
48
+ * @param content
49
+ */
50
+ add(content) {
51
+ for (const line of content.split(/\r?\n/)) {
52
+ if (!line.trim() || line.startsWith('#'))
53
+ continue;
54
+ const rule = this.rule(line.trim());
55
+ if (rule)
56
+ this.#rules.push(rule);
57
+ }
58
+ this.#cache.clear();
59
+ return this;
60
+ }
61
+ /**
62
+ * A rule of a line (moby/moby builder/dockerignore/dockerignore.go and pkg/fileutils/fileutils.go)
63
+ * @param line
64
+ */
65
+ rule(line) {
66
+ let pattern = line;
67
+ let negative = false;
68
+ if (pattern.startsWith('!')) {
69
+ negative = true;
70
+ pattern = pattern.substring(1).trim();
71
+ }
72
+ if (pattern.length > 0) {
73
+ pattern = toSlash(cleanPath(pattern));
74
+ if (pattern.length > 1 && pattern.startsWith('/'))
75
+ pattern = pattern.slice(1);
76
+ }
77
+ if (negative)
78
+ pattern = `!${pattern}`;
79
+ pattern = pattern.trim();
80
+ if (!pattern)
81
+ return undefined;
82
+ pattern = cleanPath(pattern);
83
+ if (pattern.startsWith('!')) {
84
+ if (pattern.length === 1)
85
+ return undefined;
86
+ negative = true;
87
+ pattern = pattern.substring(1);
88
+ }
89
+ else {
90
+ negative = false;
91
+ }
92
+ return { pattern: pattern, directories: pattern.split(SEPARATOR), negative: negative };
93
+ }
94
+ /**
95
+ * The regular expression of a rule (fileutils.go regexpMatch)
96
+ * @param rule
97
+ */
98
+ expression(rule) {
99
+ if (rule.expression)
100
+ return rule.expression;
101
+ const separator = SEPARATOR === '\\' ? '\\\\' : SEPARATOR;
102
+ let source = '^';
103
+ const pattern = rule.pattern;
104
+ for (let index = 0; index < pattern.length; index++) {
105
+ const character = pattern[index];
106
+ if (character === '*') {
107
+ if (pattern[index + 1] === '*') {
108
+ index++;
109
+ //"**/" is "**"
110
+ if (pattern[index + 1] === SEPARATOR)
111
+ index++;
112
+ source += pattern[index + 1] === undefined ? '.*' : `(.*${separator})?`;
113
+ }
114
+ else {
115
+ source += `[^${separator}]*`;
116
+ }
117
+ }
118
+ else if (character === '?') {
119
+ source += `[^${separator}]`;
120
+ }
121
+ else if (character === '.' || character === '$') {
122
+ source += `\\${character}`;
123
+ }
124
+ else if (character === '\\') {
125
+ if (SEPARATOR === '\\') {
126
+ source += separator;
127
+ }
128
+ else if (pattern[index + 1] !== undefined) {
129
+ source += `\\${pattern[++index]}`;
130
+ }
131
+ else {
132
+ source += '\\';
133
+ }
134
+ }
135
+ else {
136
+ source += character;
137
+ }
138
+ }
139
+ return rule.expression = new RegExp(`${source}$`, this.ignoreCase ? 'i' : '');
140
+ }
141
+ /**
142
+ * Whether a file of the context is excluded by the rules (its path relative to the context, "/" separated)
143
+ * @param file
144
+ */
145
+ ignores(file) {
146
+ if (!file)
147
+ return true;
148
+ let ignored = this.#cache.get(file);
149
+ if (ignored === undefined)
150
+ this.#cache.set(file, ignored = this.test(file));
151
+ return ignored;
152
+ }
153
+ /**
154
+ * Whether a file is excluded: the last rule matching it or one of its parent directories decides
155
+ * @param file
156
+ */
157
+ test(file) {
158
+ const local = fromSlash(file);
159
+ const parent = cleanPath(path.dirname(local));
160
+ const parentDirectories = parent.split(SEPARATOR);
161
+ let matched = false;
162
+ for (const rule of this.#rules) {
163
+ let match = this.expression(rule).test(local);
164
+ if (!match && parent !== '.') {
165
+ if (rule.directories.includes('**')) {
166
+ for (let index = rule.directories.filter((directory) => directory !== '**').length; index <= parentDirectories.length; index++) {
167
+ match = match || this.expression(rule).test(parentDirectories.slice(0, index).join(SEPARATOR));
168
+ }
169
+ }
170
+ else if (rule.directories.length <= parentDirectories.length) {
171
+ match = this.expression(rule).test(parentDirectories.slice(0, rule.directories.length).join(SEPARATOR));
172
+ }
173
+ }
174
+ if (match)
175
+ matched = !rule.negative;
176
+ }
177
+ return matched;
178
+ }
179
+ }
@@ -0,0 +1,59 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { closeSync, constants, openSync } from 'node:fs';
3
+ import net from 'node:net';
4
+ /**
5
+ * The FIFOs of the standard streams of a process of containerd (the ones of its cio): created by mkfifo, the shim
6
+ * writing (or reading) them, read (or written) from the event loop
7
+ */
8
+ export class ProcessFifo {
9
+ #keeper;
10
+ #socket;
11
+ constructor(path, direction) {
12
+ this.path = path;
13
+ this.direction = direction;
14
+ }
15
+ /**
16
+ * Whether the FIFOs can be created (mkfifo of the system: coreutils, busybox)
17
+ */
18
+ static Supported() {
19
+ return spawnSync('mkfifo', ['--help'], { stdio: 'ignore' }).error === undefined;
20
+ }
21
+ /**
22
+ * Create a FIFO, kept open (read and write) for the shim to open its end without waiting
23
+ * @param path
24
+ * @param direction read: the shim writes it (stdout, stderr), write: the shim reads it (stdin)
25
+ */
26
+ static Create(path, direction) {
27
+ const result = spawnSync('mkfifo', ['-m', '0600', path], { stdio: ['ignore', 'ignore', 'pipe'] });
28
+ if (result.error || result.status !== 0)
29
+ throw new Error(`The FIFO ${path} is not created: ${result.error?.message ?? result.stderr.toString().trim()}`);
30
+ const fifo = new ProcessFifo(path, direction);
31
+ fifo.#keeper = openSync(path, constants.O_RDWR | constants.O_NONBLOCK);
32
+ return fifo;
33
+ }
34
+ /**
35
+ * Its end opened, once the shim has opened its own one (after the creation of the process): the one kept closed,
36
+ * the end of the stream is the one of the shim
37
+ */
38
+ open() {
39
+ if (this.#socket)
40
+ return this.#socket;
41
+ const flags = (this.direction === 'read' ? constants.O_RDONLY : constants.O_WRONLY) | constants.O_NONBLOCK;
42
+ this.#socket = new net.Socket({ fd: openSync(this.path, flags), readable: this.direction === 'read', writable: this.direction === 'write' });
43
+ this.releaseKeeper();
44
+ return this.#socket;
45
+ }
46
+ releaseKeeper() {
47
+ if (this.#keeper === undefined)
48
+ return;
49
+ closeSync(this.#keeper);
50
+ this.#keeper = undefined;
51
+ }
52
+ /**
53
+ * Close it
54
+ */
55
+ close() {
56
+ this.releaseKeeper();
57
+ this.#socket?.destroy();
58
+ }
59
+ }