@lakutata/docker 3.0.0-beta.0

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 (305) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +309 -0
  3. package/THIRD_PARTY_NOTICES.md +299 -0
  4. package/dist/cjs/client/BuildContext.d.ts +22 -0
  5. package/dist/cjs/client/BuildContext.js +76 -0
  6. package/dist/cjs/client/BuildKitProgress.d.ts +81 -0
  7. package/dist/cjs/client/BuildKitProgress.js +195 -0
  8. package/dist/cjs/client/DockerClient.d.ts +196 -0
  9. package/dist/cjs/client/DockerClient.js +312 -0
  10. package/dist/cjs/client/DockerConnection.d.ts +154 -0
  11. package/dist/cjs/client/DockerConnection.js +397 -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/DockerRequestError.d.ts +17 -0
  15. package/dist/cjs/client/DockerRequestError.js +24 -0
  16. package/dist/cjs/client/DockerStreams.d.ts +35 -0
  17. package/dist/cjs/client/DockerStreams.js +117 -0
  18. package/dist/cjs/client/types/ContainerCreateResponse.d.ts +7 -0
  19. package/dist/cjs/client/types/ContainerCreateResponse.js +2 -0
  20. package/dist/cjs/client/types/ContainerStopQuery.d.ts +13 -0
  21. package/dist/cjs/client/types/ContainerStopQuery.js +2 -0
  22. package/dist/cjs/client/types/DeviceMapping.d.ts +8 -0
  23. package/dist/cjs/client/types/DeviceMapping.js +2 -0
  24. package/dist/cjs/client/types/IdResponse.d.ts +6 -0
  25. package/dist/cjs/client/types/IdResponse.js +2 -0
  26. package/dist/cjs/client/types/NetworkCreateResponse.d.ts +7 -0
  27. package/dist/cjs/client/types/NetworkCreateResponse.js +2 -0
  28. package/dist/cjs/client/types/PortBinding.d.ts +10 -0
  29. package/dist/cjs/client/types/PortBinding.js +2 -0
  30. package/dist/cjs/docker/ConnectionOptionsBuilder.d.ts +128 -0
  31. package/dist/cjs/docker/ConnectionOptionsBuilder.js +150 -0
  32. package/dist/cjs/docker/Docker.d.ts +301 -0
  33. package/dist/cjs/docker/Docker.js +703 -0
  34. package/dist/cjs/docker/exceptions/DockerConnectionException.d.ts +9 -0
  35. package/dist/cjs/docker/exceptions/DockerConnectionException.js +16 -0
  36. package/dist/cjs/docker/exceptions/DockerContainerNotFoundException.d.ts +9 -0
  37. package/dist/cjs/docker/exceptions/DockerContainerNotFoundException.js +16 -0
  38. package/dist/cjs/docker/exceptions/DockerImageBuildException.d.ts +9 -0
  39. package/dist/cjs/docker/exceptions/DockerImageBuildException.js +16 -0
  40. package/dist/cjs/docker/exceptions/DockerImageImportException.d.ts +9 -0
  41. package/dist/cjs/docker/exceptions/DockerImageImportException.js +16 -0
  42. package/dist/cjs/docker/exceptions/DockerImageNotFoundException.d.ts +10 -0
  43. package/dist/cjs/docker/exceptions/DockerImageNotFoundException.js +17 -0
  44. package/dist/cjs/docker/exceptions/DockerImagePullException.d.ts +9 -0
  45. package/dist/cjs/docker/exceptions/DockerImagePullException.js +16 -0
  46. package/dist/cjs/docker/exceptions/DockerImagePushException.d.ts +8 -0
  47. package/dist/cjs/docker/exceptions/DockerImagePushException.js +15 -0
  48. package/dist/cjs/docker/exceptions/DockerImageRepoTagNotFoundException.d.ts +8 -0
  49. package/dist/cjs/docker/exceptions/DockerImageRepoTagNotFoundException.js +15 -0
  50. package/dist/cjs/docker/exceptions/DockerNetworkNotFoundException.d.ts +9 -0
  51. package/dist/cjs/docker/exceptions/DockerNetworkNotFoundException.js +16 -0
  52. package/dist/cjs/docker/exceptions/DockerRequestException.d.ts +22 -0
  53. package/dist/cjs/docker/exceptions/DockerRequestException.js +24 -0
  54. package/dist/cjs/docker/interfaces/IDockerConnectionOptions.d.ts +75 -0
  55. package/dist/cjs/docker/interfaces/IDockerConnectionOptions.js +2 -0
  56. package/dist/cjs/docker/interfaces/IDockerHttpConnectionOptions.d.ts +16 -0
  57. package/dist/cjs/docker/interfaces/IDockerHttpConnectionOptions.js +2 -0
  58. package/dist/cjs/docker/interfaces/IDockerHttpsConnectionOptions.d.ts +16 -0
  59. package/dist/cjs/docker/interfaces/IDockerHttpsConnectionOptions.js +2 -0
  60. package/dist/cjs/docker/interfaces/IDockerKeyObject.d.ts +14 -0
  61. package/dist/cjs/docker/interfaces/IDockerKeyObject.js +2 -0
  62. package/dist/cjs/docker/interfaces/IDockerSSHConnectionOptions.d.ts +16 -0
  63. package/dist/cjs/docker/interfaces/IDockerSSHConnectionOptions.js +2 -0
  64. package/dist/cjs/docker/interfaces/IDockerSocketConnectionOptions.d.ts +7 -0
  65. package/dist/cjs/docker/interfaces/IDockerSocketConnectionOptions.js +2 -0
  66. package/dist/cjs/docker/lib/DockerContainer.d.ts +315 -0
  67. package/dist/cjs/docker/lib/DockerContainer.js +742 -0
  68. package/dist/cjs/docker/lib/DockerContainerTTY.d.ts +99 -0
  69. package/dist/cjs/docker/lib/DockerContainerTTY.js +157 -0
  70. package/dist/cjs/docker/lib/DockerImage.d.ts +153 -0
  71. package/dist/cjs/docker/lib/DockerImage.js +273 -0
  72. package/dist/cjs/docker/lib/EngineSettings.d.ts +41 -0
  73. package/dist/cjs/docker/lib/EngineSettings.js +86 -0
  74. package/dist/cjs/docker/lib/ParseBaseImages.d.ts +9 -0
  75. package/dist/cjs/docker/lib/ParseBaseImages.js +50 -0
  76. package/dist/cjs/docker/lib/ParseEnvToRecord.d.ts +14 -0
  77. package/dist/cjs/docker/lib/ParseEnvToRecord.js +25 -0
  78. package/dist/cjs/docker/lib/ParseRepositoryTag.d.ts +17 -0
  79. package/dist/cjs/docker/lib/ParseRepositoryTag.js +48 -0
  80. package/dist/cjs/docker/lib/RegistryAuth.d.ts +8 -0
  81. package/dist/cjs/docker/lib/RegistryAuth.js +15 -0
  82. package/dist/cjs/docker/options/DockerPruneOptions.d.ts +38 -0
  83. package/dist/cjs/docker/options/DockerPruneOptions.js +47 -0
  84. package/dist/cjs/docker/options/auth/DockerAuthOptions.d.ts +46 -0
  85. package/dist/cjs/docker/options/auth/DockerAuthOptions.js +59 -0
  86. package/dist/cjs/docker/options/container/ContainerCommitOptions.d.ts +28 -0
  87. package/dist/cjs/docker/options/container/ContainerCommitOptions.js +39 -0
  88. package/dist/cjs/docker/options/container/ContainerCreateTTYOptions.d.ts +32 -0
  89. package/dist/cjs/docker/options/container/ContainerCreateTTYOptions.js +43 -0
  90. package/dist/cjs/docker/options/container/ContainerExecOptions.d.ts +26 -0
  91. package/dist/cjs/docker/options/container/ContainerExecOptions.js +38 -0
  92. package/dist/cjs/docker/options/container/ContainerExportDirectoryOptions.d.ts +27 -0
  93. package/dist/cjs/docker/options/container/ContainerExportDirectoryOptions.js +39 -0
  94. package/dist/cjs/docker/options/container/ContainerKillOptions.d.ts +25 -0
  95. package/dist/cjs/docker/options/container/ContainerKillOptions.js +36 -0
  96. package/dist/cjs/docker/options/container/ContainerLogsOptions.d.ts +48 -0
  97. package/dist/cjs/docker/options/container/ContainerLogsOptions.js +56 -0
  98. package/dist/cjs/docker/options/container/ContainerRemoveOptions.d.ts +22 -0
  99. package/dist/cjs/docker/options/container/ContainerRemoveOptions.js +34 -0
  100. package/dist/cjs/docker/options/container/ContainerSettingOptions.d.ts +137 -0
  101. package/dist/cjs/docker/options/container/ContainerSettingOptions.js +136 -0
  102. package/dist/cjs/docker/options/container/ContainerStopOptions.d.ts +28 -0
  103. package/dist/cjs/docker/options/container/ContainerStopOptions.js +40 -0
  104. package/dist/cjs/docker/options/container/ContainerTTYConsoleSizeOptions.d.ts +26 -0
  105. package/dist/cjs/docker/options/container/ContainerTTYConsoleSizeOptions.js +40 -0
  106. package/dist/cjs/docker/options/image/ImageBuildOptions.d.ts +117 -0
  107. package/dist/cjs/docker/options/image/ImageBuildOptions.js +111 -0
  108. package/dist/cjs/docker/options/image/ImageExportOptions.d.ts +33 -0
  109. package/dist/cjs/docker/options/image/ImageExportOptions.js +44 -0
  110. package/dist/cjs/docker/options/image/ImageImportOptions.d.ts +28 -0
  111. package/dist/cjs/docker/options/image/ImageImportOptions.js +42 -0
  112. package/dist/cjs/docker/options/image/ImagePullOptions.d.ts +49 -0
  113. package/dist/cjs/docker/options/image/ImagePullOptions.js +63 -0
  114. package/dist/cjs/docker/options/image/ImagePushOptions.d.ts +41 -0
  115. package/dist/cjs/docker/options/image/ImagePushOptions.js +56 -0
  116. package/dist/cjs/docker/options/image/ImageRemoveOptions.d.ts +26 -0
  117. package/dist/cjs/docker/options/image/ImageRemoveOptions.js +38 -0
  118. package/dist/cjs/docker/options/image/ImageTagOptions.d.ts +25 -0
  119. package/dist/cjs/docker/options/image/ImageTagOptions.js +38 -0
  120. package/dist/cjs/docker/options/network/NetworkCreateOptions.d.ts +54 -0
  121. package/dist/cjs/docker/options/network/NetworkCreateOptions.js +63 -0
  122. package/dist/cjs/docker/types/ContainerBind.d.ts +19 -0
  123. package/dist/cjs/docker/types/ContainerBind.js +2 -0
  124. package/dist/cjs/docker/types/ContainerCapability.d.ts +286 -0
  125. package/dist/cjs/docker/types/ContainerCapability.js +290 -0
  126. package/dist/cjs/docker/types/ContainerConfig.d.ts +67 -0
  127. package/dist/cjs/docker/types/ContainerConfig.js +2 -0
  128. package/dist/cjs/docker/types/ContainerDevice.d.ts +19 -0
  129. package/dist/cjs/docker/types/ContainerDevice.js +2 -0
  130. package/dist/cjs/docker/types/ContainerExecResult.d.ts +20 -0
  131. package/dist/cjs/docker/types/ContainerExecResult.js +2 -0
  132. package/dist/cjs/docker/types/ContainerNetwork.d.ts +46 -0
  133. package/dist/cjs/docker/types/ContainerNetwork.js +2 -0
  134. package/dist/cjs/docker/types/ContainerPort.d.ts +25 -0
  135. package/dist/cjs/docker/types/ContainerPort.js +2 -0
  136. package/dist/cjs/docker/types/ContainerRestartPolicy.d.ts +11 -0
  137. package/dist/cjs/docker/types/ContainerRestartPolicy.js +2 -0
  138. package/dist/cjs/docker/types/ContainerState.d.ts +48 -0
  139. package/dist/cjs/docker/types/ContainerState.js +2 -0
  140. package/dist/cjs/docker/types/ContainerStats.d.ts +408 -0
  141. package/dist/cjs/docker/types/ContainerStats.js +2 -0
  142. package/dist/cjs/docker/types/DockerOutputCallback.d.ts +8 -0
  143. package/dist/cjs/docker/types/DockerOutputCallback.js +2 -0
  144. package/dist/cjs/docker/types/ImageConfig.d.ts +34 -0
  145. package/dist/cjs/docker/types/ImageConfig.js +2 -0
  146. package/dist/cjs/docker/types/ImageExposePort.d.ts +17 -0
  147. package/dist/cjs/docker/types/ImageExposePort.js +2 -0
  148. package/dist/cjs/docker/types/NetworkInfo.d.ts +59 -0
  149. package/dist/cjs/docker/types/NetworkInfo.js +2 -0
  150. package/dist/cjs/docker/types/RepositoryTag.d.ts +15 -0
  151. package/dist/cjs/docker/types/RepositoryTag.js +2 -0
  152. package/dist/cjs/exports/Docker.d.ts +73 -0
  153. package/dist/cjs/exports/Docker.js +92 -0
  154. package/dist/cjs/package.json +1 -0
  155. package/dist/esm/client/BuildContext.js +70 -0
  156. package/dist/esm/client/BuildKitProgress.js +190 -0
  157. package/dist/esm/client/DockerClient.js +307 -0
  158. package/dist/esm/client/DockerConnection.js +355 -0
  159. package/dist/esm/client/DockerIgnore.js +179 -0
  160. package/dist/esm/client/DockerRequestError.js +20 -0
  161. package/dist/esm/client/DockerStreams.js +111 -0
  162. package/dist/esm/client/types/ContainerCreateResponse.js +1 -0
  163. package/dist/esm/client/types/ContainerStopQuery.js +1 -0
  164. package/dist/esm/client/types/DeviceMapping.js +1 -0
  165. package/dist/esm/client/types/IdResponse.js +1 -0
  166. package/dist/esm/client/types/NetworkCreateResponse.js +1 -0
  167. package/dist/esm/client/types/PortBinding.js +1 -0
  168. package/dist/esm/docker/ConnectionOptionsBuilder.js +142 -0
  169. package/dist/esm/docker/Docker.js +697 -0
  170. package/dist/esm/docker/exceptions/DockerConnectionException.js +12 -0
  171. package/dist/esm/docker/exceptions/DockerContainerNotFoundException.js +12 -0
  172. package/dist/esm/docker/exceptions/DockerImageBuildException.js +12 -0
  173. package/dist/esm/docker/exceptions/DockerImageImportException.js +12 -0
  174. package/dist/esm/docker/exceptions/DockerImageNotFoundException.js +13 -0
  175. package/dist/esm/docker/exceptions/DockerImagePullException.js +12 -0
  176. package/dist/esm/docker/exceptions/DockerImagePushException.js +11 -0
  177. package/dist/esm/docker/exceptions/DockerImageRepoTagNotFoundException.js +11 -0
  178. package/dist/esm/docker/exceptions/DockerNetworkNotFoundException.js +12 -0
  179. package/dist/esm/docker/exceptions/DockerRequestException.js +20 -0
  180. package/dist/esm/docker/interfaces/IDockerConnectionOptions.js +1 -0
  181. package/dist/esm/docker/interfaces/IDockerHttpConnectionOptions.js +1 -0
  182. package/dist/esm/docker/interfaces/IDockerHttpsConnectionOptions.js +1 -0
  183. package/dist/esm/docker/interfaces/IDockerKeyObject.js +1 -0
  184. package/dist/esm/docker/interfaces/IDockerSSHConnectionOptions.js +1 -0
  185. package/dist/esm/docker/interfaces/IDockerSocketConnectionOptions.js +1 -0
  186. package/dist/esm/docker/lib/DockerContainer.js +739 -0
  187. package/dist/esm/docker/lib/DockerContainerTTY.js +154 -0
  188. package/dist/esm/docker/lib/DockerImage.js +270 -0
  189. package/dist/esm/docker/lib/EngineSettings.js +78 -0
  190. package/dist/esm/docker/lib/ParseBaseImages.js +47 -0
  191. package/dist/esm/docker/lib/ParseEnvToRecord.js +22 -0
  192. package/dist/esm/docker/lib/ParseRepositoryTag.js +45 -0
  193. package/dist/esm/docker/lib/RegistryAuth.js +12 -0
  194. package/dist/esm/docker/options/DockerPruneOptions.js +43 -0
  195. package/dist/esm/docker/options/auth/DockerAuthOptions.js +55 -0
  196. package/dist/esm/docker/options/container/ContainerCommitOptions.js +35 -0
  197. package/dist/esm/docker/options/container/ContainerCreateTTYOptions.js +39 -0
  198. package/dist/esm/docker/options/container/ContainerExecOptions.js +34 -0
  199. package/dist/esm/docker/options/container/ContainerExportDirectoryOptions.js +35 -0
  200. package/dist/esm/docker/options/container/ContainerKillOptions.js +32 -0
  201. package/dist/esm/docker/options/container/ContainerLogsOptions.js +52 -0
  202. package/dist/esm/docker/options/container/ContainerRemoveOptions.js +30 -0
  203. package/dist/esm/docker/options/container/ContainerSettingOptions.js +132 -0
  204. package/dist/esm/docker/options/container/ContainerStopOptions.js +36 -0
  205. package/dist/esm/docker/options/container/ContainerTTYConsoleSizeOptions.js +36 -0
  206. package/dist/esm/docker/options/image/ImageBuildOptions.js +107 -0
  207. package/dist/esm/docker/options/image/ImageExportOptions.js +40 -0
  208. package/dist/esm/docker/options/image/ImageImportOptions.js +38 -0
  209. package/dist/esm/docker/options/image/ImagePullOptions.js +59 -0
  210. package/dist/esm/docker/options/image/ImagePushOptions.js +52 -0
  211. package/dist/esm/docker/options/image/ImageRemoveOptions.js +34 -0
  212. package/dist/esm/docker/options/image/ImageTagOptions.js +34 -0
  213. package/dist/esm/docker/options/network/NetworkCreateOptions.js +59 -0
  214. package/dist/esm/docker/types/ContainerBind.js +1 -0
  215. package/dist/esm/docker/types/ContainerCapability.js +287 -0
  216. package/dist/esm/docker/types/ContainerConfig.js +1 -0
  217. package/dist/esm/docker/types/ContainerDevice.js +1 -0
  218. package/dist/esm/docker/types/ContainerExecResult.js +1 -0
  219. package/dist/esm/docker/types/ContainerNetwork.js +1 -0
  220. package/dist/esm/docker/types/ContainerPort.js +1 -0
  221. package/dist/esm/docker/types/ContainerRestartPolicy.js +1 -0
  222. package/dist/esm/docker/types/ContainerState.js +1 -0
  223. package/dist/esm/docker/types/ContainerStats.js +1 -0
  224. package/dist/esm/docker/types/DockerOutputCallback.js +1 -0
  225. package/dist/esm/docker/types/ImageConfig.js +1 -0
  226. package/dist/esm/docker/types/ImageExposePort.js +1 -0
  227. package/dist/esm/docker/types/NetworkInfo.js +1 -0
  228. package/dist/esm/docker/types/RepositoryTag.js +1 -0
  229. package/dist/esm/exports/Docker.js +73 -0
  230. package/dist/types/client/BuildContext.d.ts +22 -0
  231. package/dist/types/client/BuildKitProgress.d.ts +81 -0
  232. package/dist/types/client/DockerClient.d.ts +196 -0
  233. package/dist/types/client/DockerConnection.d.ts +154 -0
  234. package/dist/types/client/DockerIgnore.d.ts +44 -0
  235. package/dist/types/client/DockerRequestError.d.ts +17 -0
  236. package/dist/types/client/DockerStreams.d.ts +35 -0
  237. package/dist/types/client/types/ContainerCreateResponse.d.ts +7 -0
  238. package/dist/types/client/types/ContainerStopQuery.d.ts +13 -0
  239. package/dist/types/client/types/DeviceMapping.d.ts +8 -0
  240. package/dist/types/client/types/IdResponse.d.ts +6 -0
  241. package/dist/types/client/types/NetworkCreateResponse.d.ts +7 -0
  242. package/dist/types/client/types/PortBinding.d.ts +10 -0
  243. package/dist/types/docker/ConnectionOptionsBuilder.d.ts +128 -0
  244. package/dist/types/docker/Docker.d.ts +301 -0
  245. package/dist/types/docker/exceptions/DockerConnectionException.d.ts +9 -0
  246. package/dist/types/docker/exceptions/DockerContainerNotFoundException.d.ts +9 -0
  247. package/dist/types/docker/exceptions/DockerImageBuildException.d.ts +9 -0
  248. package/dist/types/docker/exceptions/DockerImageImportException.d.ts +9 -0
  249. package/dist/types/docker/exceptions/DockerImageNotFoundException.d.ts +10 -0
  250. package/dist/types/docker/exceptions/DockerImagePullException.d.ts +9 -0
  251. package/dist/types/docker/exceptions/DockerImagePushException.d.ts +8 -0
  252. package/dist/types/docker/exceptions/DockerImageRepoTagNotFoundException.d.ts +8 -0
  253. package/dist/types/docker/exceptions/DockerNetworkNotFoundException.d.ts +9 -0
  254. package/dist/types/docker/exceptions/DockerRequestException.d.ts +22 -0
  255. package/dist/types/docker/interfaces/IDockerConnectionOptions.d.ts +75 -0
  256. package/dist/types/docker/interfaces/IDockerHttpConnectionOptions.d.ts +16 -0
  257. package/dist/types/docker/interfaces/IDockerHttpsConnectionOptions.d.ts +16 -0
  258. package/dist/types/docker/interfaces/IDockerKeyObject.d.ts +14 -0
  259. package/dist/types/docker/interfaces/IDockerSSHConnectionOptions.d.ts +16 -0
  260. package/dist/types/docker/interfaces/IDockerSocketConnectionOptions.d.ts +7 -0
  261. package/dist/types/docker/lib/DockerContainer.d.ts +315 -0
  262. package/dist/types/docker/lib/DockerContainerTTY.d.ts +99 -0
  263. package/dist/types/docker/lib/DockerImage.d.ts +153 -0
  264. package/dist/types/docker/lib/EngineSettings.d.ts +41 -0
  265. package/dist/types/docker/lib/ParseBaseImages.d.ts +9 -0
  266. package/dist/types/docker/lib/ParseEnvToRecord.d.ts +14 -0
  267. package/dist/types/docker/lib/ParseRepositoryTag.d.ts +17 -0
  268. package/dist/types/docker/lib/RegistryAuth.d.ts +8 -0
  269. package/dist/types/docker/options/DockerPruneOptions.d.ts +38 -0
  270. package/dist/types/docker/options/auth/DockerAuthOptions.d.ts +46 -0
  271. package/dist/types/docker/options/container/ContainerCommitOptions.d.ts +28 -0
  272. package/dist/types/docker/options/container/ContainerCreateTTYOptions.d.ts +32 -0
  273. package/dist/types/docker/options/container/ContainerExecOptions.d.ts +26 -0
  274. package/dist/types/docker/options/container/ContainerExportDirectoryOptions.d.ts +27 -0
  275. package/dist/types/docker/options/container/ContainerKillOptions.d.ts +25 -0
  276. package/dist/types/docker/options/container/ContainerLogsOptions.d.ts +48 -0
  277. package/dist/types/docker/options/container/ContainerRemoveOptions.d.ts +22 -0
  278. package/dist/types/docker/options/container/ContainerSettingOptions.d.ts +137 -0
  279. package/dist/types/docker/options/container/ContainerStopOptions.d.ts +28 -0
  280. package/dist/types/docker/options/container/ContainerTTYConsoleSizeOptions.d.ts +26 -0
  281. package/dist/types/docker/options/image/ImageBuildOptions.d.ts +117 -0
  282. package/dist/types/docker/options/image/ImageExportOptions.d.ts +33 -0
  283. package/dist/types/docker/options/image/ImageImportOptions.d.ts +28 -0
  284. package/dist/types/docker/options/image/ImagePullOptions.d.ts +49 -0
  285. package/dist/types/docker/options/image/ImagePushOptions.d.ts +41 -0
  286. package/dist/types/docker/options/image/ImageRemoveOptions.d.ts +26 -0
  287. package/dist/types/docker/options/image/ImageTagOptions.d.ts +25 -0
  288. package/dist/types/docker/options/network/NetworkCreateOptions.d.ts +54 -0
  289. package/dist/types/docker/types/ContainerBind.d.ts +19 -0
  290. package/dist/types/docker/types/ContainerCapability.d.ts +286 -0
  291. package/dist/types/docker/types/ContainerConfig.d.ts +67 -0
  292. package/dist/types/docker/types/ContainerDevice.d.ts +19 -0
  293. package/dist/types/docker/types/ContainerExecResult.d.ts +20 -0
  294. package/dist/types/docker/types/ContainerNetwork.d.ts +46 -0
  295. package/dist/types/docker/types/ContainerPort.d.ts +25 -0
  296. package/dist/types/docker/types/ContainerRestartPolicy.d.ts +11 -0
  297. package/dist/types/docker/types/ContainerState.d.ts +48 -0
  298. package/dist/types/docker/types/ContainerStats.d.ts +408 -0
  299. package/dist/types/docker/types/DockerOutputCallback.d.ts +8 -0
  300. package/dist/types/docker/types/ImageConfig.d.ts +34 -0
  301. package/dist/types/docker/types/ImageExposePort.d.ts +17 -0
  302. package/dist/types/docker/types/NetworkInfo.d.ts +59 -0
  303. package/dist/types/docker/types/RepositoryTag.d.ts +15 -0
  304. package/dist/types/exports/Docker.d.ts +73 -0
  305. package/package.json +57 -0
@@ -0,0 +1,154 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Provider, DTO } from '@lakutata/core';
11
+ import { Configurable, Transient } from '@lakutata/core/decorator/di';
12
+ import { ContainerTTYConsoleSizeOptions } from '../options/container/ContainerTTYConsoleSizeOptions.js';
13
+ import { Accept } from '@lakutata/core/decorator/dto';
14
+ /**
15
+ * An interactive command running with a TTY in a container, as `docker exec -it`: what is written to it is the
16
+ * command's input, its output (stdout and stderr together, with the terminal's control sequences) is read from it. It is
17
+ * not created with `new`: {@link DockerContainer.createTTY} returns it, its command started.
18
+ *
19
+ * The command runs until it exits (`exit` written to a shell), or until the stream is closed (`tty.raw.end()`,
20
+ * `tty.raw.destroy()`); the stream then ends. A command which cannot be started (not found in the image) does not fail
21
+ * the creation: its error message is the output, then the stream ends. The write failures are logged by the
22
+ * application's `log` component, else by the console.
23
+ * @example
24
+ * ```typescript
25
+ * import {type DockerContainer, type DockerContainerTTY} from 'lakutata/com/docker'
26
+ *
27
+ * declare const container: DockerContainer
28
+ *
29
+ * //A shell: /bin/sh by default
30
+ * const tty: DockerContainerTTY = await container.createTTY({consoleSize: {cols: 120, rows: 40}})
31
+ * tty.onData((chunk: Buffer): void => {
32
+ * process.stdout.write(chunk)
33
+ * })
34
+ * tty.raw.once('end', (): void => console.log('The shell exited'))
35
+ * tty.write('ls -l /\n')
36
+ * await tty.resize({cols: 160, rows: 50})
37
+ * tty.write('exit\n')
38
+ * ```
39
+ */
40
+ let DockerContainerTTY = class DockerContainerTTY extends Provider {
41
+ #execId;
42
+ #duplexStream;
43
+ /**
44
+ * The logger of the write failures: the application's log component, else the console
45
+ */
46
+ #log;
47
+ /**
48
+ * Create the execution of the command and start it, attached to its TTY.
49
+ * @throws {DockerContainerNotFoundException} When the container was removed.
50
+ * @throws {DockerRequestException} When the container is not running (HTTP 409).
51
+ * @protected
52
+ */
53
+ async init() {
54
+ try {
55
+ this.#log = await this.getObject('log');
56
+ }
57
+ catch {
58
+ //An application without a log component
59
+ this.#log = console;
60
+ }
61
+ const exec = await this.getClient().createExec(this.containerId, {
62
+ AttachStderr: true,
63
+ AttachStdin: true,
64
+ AttachStdout: true,
65
+ Cmd: this.cmd ? Array.isArray(this.cmd) ? this.cmd : [this.cmd] : undefined,
66
+ Tty: true,
67
+ ConsoleSize: [this.initialConsoleSize?.rows ? this.initialConsoleSize.rows : 0, this.initialConsoleSize?.cols ? this.initialConsoleSize.cols : 0]
68
+ });
69
+ this.#execId = exec.Id;
70
+ //Started with its TTY: its output is not multiplexed
71
+ this.#duplexStream = await this.getClient().startExec(this.#execId, { Detach: false, Tty: true });
72
+ }
73
+ /**
74
+ * Close the stream of the TTY, which ends the command's input.
75
+ * @protected
76
+ */
77
+ async destroy() {
78
+ //Not created when its execution failed to start
79
+ if (this.#duplexStream && !this.#duplexStream.destroyed) {
80
+ this.#duplexStream.removeAllListeners();
81
+ this.#duplexStream.destroy();
82
+ }
83
+ }
84
+ /**
85
+ * The stream of the TTY, both ways: written, the command's input; read, its output. Its `end` event tells that the
86
+ * command exited, once its output is read (with {@link DockerContainerTTY.onData} or a `data` listener).
87
+ */
88
+ get raw() {
89
+ return this.#duplexStream;
90
+ }
91
+ /**
92
+ * The stream of the TTY, typed as its writable side: the command's input.
93
+ */
94
+ get writable() {
95
+ return this.#duplexStream;
96
+ }
97
+ /**
98
+ * The stream of the TTY, typed as its readable side: the command's output.
99
+ */
100
+ get readable() {
101
+ return this.#duplexStream;
102
+ }
103
+ /**
104
+ * Change the size of the TTY's console, as a terminal window resized does (the command gets `SIGWINCH`).
105
+ * @param options The number of columns (`cols`) and rows (`rows`).
106
+ * @throws {DockerRequestException} When the command has exited (HTTP 404, no such exec; HTTP 500).
107
+ * @throws {DockerContainerNotFoundException} When the container was removed.
108
+ */
109
+ async resize(options) {
110
+ await this.getClient().resizeExec(this.#execId, {
111
+ w: options.cols,
112
+ h: options.rows
113
+ });
114
+ }
115
+ /**
116
+ * Receive the command's output as it comes. Each call adds a handler.
117
+ * @param handler Called with each chunk of the output: raw bytes, the terminal's control sequences included.
118
+ */
119
+ onData(handler) {
120
+ this.#duplexStream.on('data', handler);
121
+ }
122
+ write(data) {
123
+ this.#duplexStream.write(data, (error) => {
124
+ if (error)
125
+ this.#log.warn('Write data to duplex stream error: %s', error.message);
126
+ });
127
+ }
128
+ };
129
+ __decorate([
130
+ Configurable(DTO.Function()),
131
+ __metadata("design:type", Function)
132
+ ], DockerContainerTTY.prototype, "getClient", void 0);
133
+ __decorate([
134
+ Configurable(DTO.String()),
135
+ __metadata("design:type", String)
136
+ ], DockerContainerTTY.prototype, "containerId", void 0);
137
+ __decorate([
138
+ Configurable(DTO.Alternatives(DTO.String(), DTO.Array(DTO.String()).min(1))),
139
+ __metadata("design:type", Object)
140
+ ], DockerContainerTTY.prototype, "cmd", void 0);
141
+ __decorate([
142
+ Configurable(ContainerTTYConsoleSizeOptions.optional()),
143
+ __metadata("design:type", ContainerTTYConsoleSizeOptions)
144
+ ], DockerContainerTTY.prototype, "initialConsoleSize", void 0);
145
+ __decorate([
146
+ Accept(ContainerTTYConsoleSizeOptions.required()),
147
+ __metadata("design:type", Function),
148
+ __metadata("design:paramtypes", [ContainerTTYConsoleSizeOptions]),
149
+ __metadata("design:returntype", Promise)
150
+ ], DockerContainerTTY.prototype, "resize", null);
151
+ DockerContainerTTY = __decorate([
152
+ Transient()
153
+ ], DockerContainerTTY);
154
+ export { DockerContainerTTY };
@@ -0,0 +1,270 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Provider, DTO } from '@lakutata/core';
11
+ import { Transient, Configurable } from '@lakutata/core/decorator/di';
12
+ import { followProgress } from '../../client/DockerStreams.js';
13
+ import { Time } from '@lakutata/utils/Time';
14
+ import { ImageTagOptions } from '../options/image/ImageTagOptions.js';
15
+ import { Accept } from '@lakutata/core/decorator/dto';
16
+ import { ImageExportOptions } from '../options/image/ImageExportOptions.js';
17
+ import { createWriteStream } from 'node:fs';
18
+ import { pipeline } from 'stream/promises';
19
+ import { DockerImageRepoTagNotFoundException } from '../exceptions/DockerImageRepoTagNotFoundException.js';
20
+ import { ImageRemoveOptions } from '../options/image/ImageRemoveOptions.js';
21
+ import { ImagePushOptions } from '../options/image/ImagePushOptions.js';
22
+ import { DockerImagePushException } from '../exceptions/DockerImagePushException.js';
23
+ import { isAbortError, As } from '@lakutata/utils';
24
+ import { parseRepositoryTag } from './ParseRepositoryTag.js';
25
+ import { parseEnvToRecord } from './ParseEnvToRecord.js';
26
+ import { ContainerSettingOptions } from '../options/container/ContainerSettingOptions.js';
27
+ import { registryAuth } from './RegistryAuth.js';
28
+ /**
29
+ * An image of the Docker daemon, with its tags, platform, size and configuration as inspected, and its operations: tag,
30
+ * export, push, remove, and run a container. It is not created with `new`: {@link Docker.getImage},
31
+ * {@link Docker.listImages}, {@link Docker.pullImage}, {@link Docker.buildImage}, {@link Docker.importImage} and
32
+ * {@link DockerContainer.commit} return it.
33
+ *
34
+ * Its properties are a snapshot, taken when it is obtained and refreshed by `tag()` and `push()`. Its operations reject
35
+ * with {@link DockerImageNotFoundException} when the image was removed, with {@link DockerRequestException} when the
36
+ * daemon refuses them otherwise (used by a container: HTTP 409), and with the network error of Node.js when the daemon
37
+ * cannot be reached.
38
+ * @example
39
+ * ```typescript
40
+ * import {type Docker, type DockerContainer, type DockerImage} from 'lakutata/com/docker'
41
+ *
42
+ * declare const docker: Docker
43
+ *
44
+ * const image: DockerImage = await docker.buildImage({workdir: '/srv/app', files: ['Dockerfile', 'src', 'package.json'], repoTag: 'app:1.0.0'})
45
+ * console.log(image.id, image.platform, image.size, image.config.ports)
46
+ * await image.tag({repo: 'registry.example.com/team/app', tag: '1.0.0'})
47
+ * await image.push({
48
+ * repo: 'registry.example.com/team/app',
49
+ * tag: '1.0.0',
50
+ * auth: {serverAddress: 'registry.example.com', username: 'ci', password: 'secret'}
51
+ * })
52
+ * await image.export({destination: '/tmp/app-1.0.0.tar', repoTag: 'app:1.0.0'})
53
+ * const container: DockerContainer = await image.run({name: 'app', ports: [{port: 3000, type: 'tcp', hostPorts: [3000]}]})
54
+ * console.log(container.state.status)
55
+ * ```
56
+ */
57
+ let DockerImage = class DockerImage extends Provider {
58
+ #abortController = new AbortController();
59
+ /**
60
+ * Inspect the image.
61
+ * @throws {DockerImageNotFoundException} When the image does not exist.
62
+ * @protected
63
+ */
64
+ async init() {
65
+ await this.syncImageInfo();
66
+ }
67
+ /**
68
+ * Abort the export in progress of the object (the image itself is left as it is).
69
+ * @protected
70
+ */
71
+ async destroy() {
72
+ this.#abortController.abort();
73
+ }
74
+ /**
75
+ * Refresh the properties from the daemon's inspection of the image.
76
+ * @throws {DockerImageNotFoundException} When the image does not exist.
77
+ * @protected
78
+ */
79
+ async syncImageInfo() {
80
+ const inspectInfo = await this.getClient().inspectImage(this.id);
81
+ this.repoTags = inspectInfo.RepoTags;
82
+ this.createdAt = new Time(inspectInfo.Created);
83
+ this.arch = inspectInfo.Architecture;
84
+ this.os = inspectInfo.Os;
85
+ this.platform = `${this.os}/${this.arch}`;
86
+ this.size = inspectInfo.Size;
87
+ const exposePorts = [];
88
+ const exposePortMap = new Map();
89
+ if (inspectInfo.Config.ExposedPorts) {
90
+ Object.keys(inspectInfo.Config.ExposedPorts).forEach((portWithType) => {
91
+ const portInfos = portWithType.split('/');
92
+ const port = parseInt(portInfos[0]);
93
+ const type = As(portInfos[1].toLowerCase());
94
+ if (!exposePortMap.has(port))
95
+ exposePortMap.set(port, { tcp: false, udp: false });
96
+ const portType = exposePortMap.get(port);
97
+ portType[type] = true;
98
+ exposePortMap.set(port, portType);
99
+ });
100
+ exposePortMap.forEach((portType, port) => exposePorts.push({ port: port, ...portType }));
101
+ }
102
+ this.config = {
103
+ hostname: inspectInfo.Config.Hostname,
104
+ user: inspectInfo.Config.User,
105
+ env: parseEnvToRecord(inspectInfo.Config.Env),
106
+ cmd: inspectInfo.Config.Cmd,
107
+ entrypoint: inspectInfo.Config.Entrypoint
108
+ ? Array.isArray(inspectInfo.Config.Entrypoint)
109
+ ? inspectInfo.Config.Entrypoint
110
+ : [inspectInfo.Config.Entrypoint]
111
+ : [],
112
+ volumes: inspectInfo.Config.Volumes ? Object.keys(inspectInfo.Config.Volumes) : [],
113
+ ports: exposePorts
114
+ };
115
+ }
116
+ /**
117
+ * Add a tag to the image, as `docker tag`, then refresh its properties. A tag already given to another image moves to
118
+ * this one.
119
+ * @param options The repository (`registry.example.com/team/app`) and the tag (`latest` by default).
120
+ * @throws {DockerImageNotFoundException} When the image was removed.
121
+ * @throws {DockerRequestException} When the name is invalid (HTTP 400).
122
+ */
123
+ async tag(options) {
124
+ try {
125
+ await this.getClient().tagImage(this.id, { repo: options.repo, tag: options.tag });
126
+ await this.syncImageInfo();
127
+ }
128
+ catch (e) {
129
+ if (!isAbortError(e))
130
+ throw e;
131
+ }
132
+ }
133
+ /**
134
+ * Save the image as a tar archive, as `docker save`, which {@link Docker.importImage} loads. With `repoTag`, the
135
+ * archive holds that tag (restored when it is loaded); without it, the image is saved by ID, without its tags.
136
+ * @param options The `destination` (a file path, created or overwritten, or a writable stream, ended after the
137
+ * archive), the tag saved (`repoTag`), and `createRepoTagIfNotExists` (`true` by default) to add that tag to the image
138
+ * when it does not have it.
139
+ * @throws {DockerImageRepoTagNotFoundException} When the image does not have `repoTag` and
140
+ * `createRepoTagIfNotExists` is `false`.
141
+ * @throws {DockerImageNotFoundException} When the image was removed.
142
+ * @throws {Error} The error of the destination.
143
+ */
144
+ async export(options) {
145
+ try {
146
+ let name = this.id;
147
+ if (options.repoTag) {
148
+ if (!this.repoTags.includes(options.repoTag)) {
149
+ if (!options.createRepoTagIfNotExists)
150
+ throw new DockerImageRepoTagNotFoundException('The current image does not contain the RepoTag of {0}', [options.repoTag]);
151
+ const { repo, tag } = parseRepositoryTag(options.repoTag);
152
+ await this.tag({ repo: repo, tag: tag });
153
+ }
154
+ name = options.repoTag;
155
+ }
156
+ const readableStream = await this.getClient().exportImage(name);
157
+ const destStream = typeof options.destination === 'string'
158
+ ? createWriteStream(options.destination, { signal: this.#abortController.signal })
159
+ : options.destination;
160
+ await pipeline(readableStream, destStream);
161
+ }
162
+ catch (e) {
163
+ if (!isAbortError(e))
164
+ throw e;
165
+ }
166
+ }
167
+ /**
168
+ * Push the image to its registry, as `docker push`, and wait for its end. The image is first tagged `repo:tag` (the
169
+ * tag is kept afterwards).
170
+ * @param options The repository, with its registry (`registry.example.com/team/app`); the tag (`latest` by default);
171
+ * the registry credentials; and a callback receiving each progress message.
172
+ * @throws {DockerImagePushException} When the registry refuses the push (refused credentials, a repository not
173
+ * found).
174
+ * @throws {DockerImageNotFoundException} When the image was removed.
175
+ * @throws {DockerRequestException} When the daemon refuses to push it.
176
+ */
177
+ async push(options) {
178
+ const tag = options.tag ? options.tag : 'latest';
179
+ await this.tag({ repo: options.repo, tag: tag });
180
+ await this.syncImageInfo();
181
+ let pushException;
182
+ const readableStream = await this.getClient().pushImage(options.repo, { tag: tag }, registryAuth(options.auth));
183
+ await followProgress(readableStream, (outputObject) => {
184
+ if (outputObject.error && !pushException)
185
+ pushException = new DockerImagePushException(outputObject.error);
186
+ if (options.outputCallback)
187
+ options.outputCallback(outputObject);
188
+ });
189
+ if (pushException)
190
+ throw pushException;
191
+ }
192
+ /**
193
+ * Remove the image, as `docker rmi -f` by default: forced, it is removed with all its tags, even when a stopped
194
+ * container uses it.
195
+ * @param options `force` (`true` by default; `false` refuses an image with several tags or used by a container) and
196
+ * `noprune` (keeps its untagged parent images; `false` by default).
197
+ * @throws {DockerImageNotFoundException} When the image was already removed.
198
+ * @throws {DockerRequestException} When it is used by a running container or, without `force`, by any container or
199
+ * with several tags (HTTP 409).
200
+ */
201
+ async remove(options) {
202
+ try {
203
+ await this.getClient().removeImage(this.id, { force: options?.force, noprune: options?.noprune });
204
+ }
205
+ catch (e) {
206
+ if (!isAbortError(e))
207
+ throw e;
208
+ }
209
+ }
210
+ /**
211
+ * Create a container from the image, for its platform, then start it, as `docker run -d`.
212
+ * @param options The container's settings: name, command, environment, ports, binds, devices, networks, limits…
213
+ * @returns The container, started.
214
+ * @throws {DockerRequestException} When the name is already used (HTTP 409), or the start fails (HTTP 500: a command
215
+ * not found, a port already used); the container then stays created.
216
+ * @throws {DockerNetworkNotFoundException} When a network of the settings is not found.
217
+ * @throws {InvalidMethodAcceptException} When the settings are invalid.
218
+ */
219
+ async run(options) {
220
+ const container = await this.getDocker().createContainer(this.id, this.platform, options);
221
+ await container.start();
222
+ return container;
223
+ }
224
+ };
225
+ __decorate([
226
+ Configurable(DTO.Function()),
227
+ __metadata("design:type", Function)
228
+ ], DockerImage.prototype, "getClient", void 0);
229
+ __decorate([
230
+ Configurable(DTO.Function()),
231
+ __metadata("design:type", Function)
232
+ ], DockerImage.prototype, "getDocker", void 0);
233
+ __decorate([
234
+ Configurable(DTO.String()),
235
+ __metadata("design:type", String)
236
+ ], DockerImage.prototype, "id", void 0);
237
+ __decorate([
238
+ Accept(ImageTagOptions.required()),
239
+ __metadata("design:type", Function),
240
+ __metadata("design:paramtypes", [ImageTagOptions]),
241
+ __metadata("design:returntype", Promise)
242
+ ], DockerImage.prototype, "tag", null);
243
+ __decorate([
244
+ Accept(ImageExportOptions.required()),
245
+ __metadata("design:type", Function),
246
+ __metadata("design:paramtypes", [ImageExportOptions]),
247
+ __metadata("design:returntype", Promise)
248
+ ], DockerImage.prototype, "export", null);
249
+ __decorate([
250
+ Accept(ImagePushOptions.required()),
251
+ __metadata("design:type", Function),
252
+ __metadata("design:paramtypes", [ImagePushOptions]),
253
+ __metadata("design:returntype", Promise)
254
+ ], DockerImage.prototype, "push", null);
255
+ __decorate([
256
+ Accept(ImageRemoveOptions.optional().default({ force: true })),
257
+ __metadata("design:type", Function),
258
+ __metadata("design:paramtypes", [ImageRemoveOptions]),
259
+ __metadata("design:returntype", Promise)
260
+ ], DockerImage.prototype, "remove", null);
261
+ __decorate([
262
+ Accept(ContainerSettingOptions.required()),
263
+ __metadata("design:type", Function),
264
+ __metadata("design:paramtypes", [ContainerSettingOptions]),
265
+ __metadata("design:returntype", Promise)
266
+ ], DockerImage.prototype, "run", null);
267
+ DockerImage = __decorate([
268
+ Transient()
269
+ ], DockerImage);
270
+ export { DockerImage };
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The networks Docker creates itself: the addresses of their endpoints cannot be set
3
+ */
4
+ const RESERVED_NETWORKS = ['bridge', 'host', 'none'];
5
+ /**
6
+ * The restart policy of the Engine API: "on-failure:3" is the policy on-failure with 3 retries at most
7
+ * @param restartPolicy
8
+ */
9
+ export function engineRestartPolicy(restartPolicy) {
10
+ const [name, retries] = restartPolicy.split(':');
11
+ return retries === undefined ? { Name: name } : { Name: name, MaximumRetryCount: Number.parseInt(retries, 10) };
12
+ }
13
+ /**
14
+ * The restart policy of a container, from the one of the Engine API
15
+ * @param restartPolicy
16
+ */
17
+ export function parseRestartPolicy(restartPolicy) {
18
+ if (!restartPolicy?.Name)
19
+ return '';
20
+ if (restartPolicy.Name === 'on-failure' && restartPolicy.MaximumRetryCount)
21
+ return `on-failure:${restartPolicy.MaximumRetryCount}`;
22
+ return restartPolicy.Name;
23
+ }
24
+ /**
25
+ * The port bindings of the Engine API ("80/tcp": [{HostPort: "8080"}]): each host port once, null for a port published
26
+ * on no host port
27
+ * @param ports
28
+ */
29
+ export function enginePortBindings(ports) {
30
+ const hostPortsMap = new Map();
31
+ for (const port of ports) {
32
+ const key = `${port.port}/${port.type}`;
33
+ const hostPorts = hostPortsMap.get(key) ?? new Set();
34
+ port.hostPorts?.forEach((hostPort) => hostPorts.add(hostPort));
35
+ hostPortsMap.set(key, hostPorts);
36
+ }
37
+ const portBindings = {};
38
+ hostPortsMap.forEach((hostPorts, key) => {
39
+ portBindings[key] = hostPorts.size ? [...hostPorts].map((hostPort) => ({ HostPort: hostPort.toString() })) : null;
40
+ });
41
+ return portBindings;
42
+ }
43
+ /**
44
+ * The bind mounts of the Engine API ("hostPath:containerPath:rw")
45
+ * @param binds
46
+ */
47
+ export function engineBinds(binds) {
48
+ return binds.map((bind) => `${bind.hostPath}:${bind.containerPath}:${bind.rw ? 'rw' : 'ro'}`);
49
+ }
50
+ /**
51
+ * The devices of the Engine API
52
+ * @param devices
53
+ */
54
+ export function engineDevices(devices) {
55
+ return devices.map((device) => ({
56
+ PathOnHost: device.hostPath,
57
+ PathInContainer: device.containerPath,
58
+ CgroupPermissions: device.cgroupPermissions
59
+ }));
60
+ }
61
+ /**
62
+ * The endpoints of the Engine API, by network: the static addresses given, none on the reserved networks
63
+ * @param networks
64
+ */
65
+ export function engineEndpoints(networks) {
66
+ const endpoints = {};
67
+ for (const network of networks) {
68
+ endpoints[network.networkName] = RESERVED_NETWORKS.includes(network.networkName)
69
+ ? {}
70
+ : {
71
+ IPAMConfig: {
72
+ IPv4Address: network.ip ? network.ip : undefined,
73
+ IPv6Address: network.ipv6 ? network.ipv6 : undefined
74
+ }
75
+ };
76
+ }
77
+ return endpoints;
78
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The images of the FROM instructions of a Dockerfile, pulled before a build with credentials: their flags (--platform)
3
+ * and their stage names (AS build) are skipped, the stages of the Dockerfile and scratch are not images, the variables
4
+ * are the ARG declared before the first FROM (with their defaults) and the build arguments. The images whose variables
5
+ * are unknown are skipped
6
+ * @param dockerfile the content of the Dockerfile
7
+ * @param buildargs
8
+ */
9
+ export function parseBaseImages(dockerfile, buildargs = {}) {
10
+ //The instructions continued on the next lines (a backslash at the end of a line)
11
+ const instructions = dockerfile.replace(/\\\r?\n/g, ' ').split(/\r?\n/).map((line) => line.trim()).filter((line) => !!line && !line.startsWith('#'));
12
+ const variables = {};
13
+ const stages = new Set();
14
+ const images = [];
15
+ let beforeFirstFrom = true;
16
+ for (const instruction of instructions) {
17
+ const [keyword, ...rest] = instruction.split(/\s+/);
18
+ if (keyword.toUpperCase() === 'ARG' && beforeFirstFrom) {
19
+ for (const declaration of rest) {
20
+ const [name, value] = declaration.split(/=(.*)/s);
21
+ if (buildargs[name] !== undefined)
22
+ variables[name] = buildargs[name];
23
+ else if (value !== undefined)
24
+ variables[name] = value.replace(/^["']|["']$/g, '');
25
+ }
26
+ }
27
+ if (keyword.toUpperCase() !== 'FROM')
28
+ continue;
29
+ beforeFirstFrom = false;
30
+ const words = rest.filter((word) => !word.startsWith('--'));
31
+ const [reference, as, stage] = words;
32
+ if (as?.toUpperCase() === 'AS' && stage)
33
+ stages.add(stage.toLowerCase());
34
+ if (!reference)
35
+ continue;
36
+ let unknown = false;
37
+ const image = reference.replace(/\$\{?([A-Za-z_][A-Za-z0-9_]*)}?/g, (_, name) => {
38
+ if (variables[name] === undefined)
39
+ unknown = true;
40
+ return variables[name] ?? '';
41
+ });
42
+ if (unknown || !image || image.toLowerCase() === 'scratch' || stages.has(image.toLowerCase()) || images.includes(image))
43
+ continue;
44
+ images.push(image);
45
+ }
46
+ return images;
47
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Turn a list of environment variables as the Engine API gives them (`['PATH=/usr/bin', 'MODE=a=b']`) into a record by
3
+ * name. A variable is split at its first `=`; an entry without `=` is skipped; a repeated name keeps its last value.
4
+ * @param rawEnv The `NAME=value` entries; `null` or `undefined` for none.
5
+ * @returns The values by name (`{PATH: '/usr/bin', MODE: 'a=b'}`).
6
+ * @example
7
+ * ```typescript
8
+ * import {parseEnvToRecord} from 'lakutata/com/docker'
9
+ *
10
+ * const env: Record<string, string> = parseEnvToRecord(['PATH=/usr/bin', 'MODE=a=b', 'EMPTY='])
11
+ * console.log(env) //{PATH: '/usr/bin', MODE: 'a=b', EMPTY: ''}
12
+ * ```
13
+ */
14
+ export function parseEnvToRecord(rawEnv) {
15
+ const environments = {};
16
+ for (const envString of rawEnv ?? []) {
17
+ const splitPos = envString.indexOf('=');
18
+ if (splitPos !== -1)
19
+ environments[envString.substring(0, splitPos)] = envString.substring(splitPos + 1);
20
+ }
21
+ return environments;
22
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Split an image reference into its repository and its tag (or digest). A digest (`@`) wins over a tag; the port of a
3
+ * registry (`registry:5000/app`) is not taken for a tag.
4
+ * @param input The image reference: `alpine`, `alpine:3.20`, `registry.example.com:5000/team/app:1.0`,
5
+ * `alpine@sha256:…`.
6
+ * @returns The repository, and the tag (or the digest, without its `@`) when the reference has one.
7
+ * @example
8
+ * ```typescript
9
+ * import {parseRepositoryTag, type RepositoryTag} from 'lakutata/com/docker'
10
+ *
11
+ * const reference: RepositoryTag = parseRepositoryTag('registry.example.com:5000/team/app:1.0')
12
+ * console.log(reference) //{repo: 'registry.example.com:5000/team/app', tag: '1.0'}
13
+ * console.log(parseRepositoryTag('registry.example.com:5000/team/app')) //{repo: 'registry.example.com:5000/team/app'}
14
+ * ```
15
+ */
16
+ export function parseRepositoryTag(input) {
17
+ let separatorPos;
18
+ const digestPos = input.indexOf('@');
19
+ const colonPos = input.lastIndexOf(':');
20
+ // @ symbol is more important
21
+ if (digestPos >= 0) {
22
+ separatorPos = digestPos;
23
+ }
24
+ else if (colonPos >= 0) {
25
+ separatorPos = colonPos;
26
+ }
27
+ else {
28
+ // no colon nor @
29
+ return {
30
+ repo: input
31
+ };
32
+ }
33
+ // last colon is either the tag (or part of a port designation)
34
+ const tag = input.slice(separatorPos + 1);
35
+ // if it contains a / its not a tag and is part of the url
36
+ if (tag.indexOf('/') === -1) {
37
+ return {
38
+ repo: input.slice(0, separatorPos),
39
+ tag: tag
40
+ };
41
+ }
42
+ return {
43
+ repo: input
44
+ };
45
+ }
@@ -0,0 +1,12 @@
1
+ export function registryAuth(auth) {
2
+ if (!auth)
3
+ return undefined;
4
+ return {
5
+ username: auth.username,
6
+ password: auth.password,
7
+ serveraddress: auth.serverAddress,
8
+ email: auth.email,
9
+ identitytoken: auth.identityToken,
10
+ registrytoken: auth.registryToken
11
+ };
12
+ }
@@ -0,0 +1,43 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from '@lakutata/core';
11
+ import { Expect } from '@lakutata/core/decorator/dto';
12
+ /**
13
+ * Which unused resources {@link Docker.prune} removes, each kind as its `docker … prune` command does without options.
14
+ * Called without options, it prunes the containers and the images; the networks and the volumes only when asked (the
15
+ * volumes, as `docker system prune --volumes`).
16
+ * @example
17
+ * ```typescript
18
+ * import {Docker} from 'lakutata/com/docker'
19
+ *
20
+ * declare const docker: Docker
21
+ *
22
+ * //The stopped containers and the unused networks, keeping the images and the volumes
23
+ * await docker.prune({containers: true, images: false, networks: true, volumes: false})
24
+ * ```
25
+ */
26
+ export class DockerPruneOptions extends DTO {
27
+ }
28
+ __decorate([
29
+ Expect(DTO.Boolean().optional().default(true)),
30
+ __metadata("design:type", Boolean)
31
+ ], DockerPruneOptions.prototype, "containers", void 0);
32
+ __decorate([
33
+ Expect(DTO.Boolean().optional().default(true)),
34
+ __metadata("design:type", Boolean)
35
+ ], DockerPruneOptions.prototype, "images", void 0);
36
+ __decorate([
37
+ Expect(DTO.Boolean().optional().default(false)),
38
+ __metadata("design:type", Boolean)
39
+ ], DockerPruneOptions.prototype, "networks", void 0);
40
+ __decorate([
41
+ Expect(DTO.Boolean().optional().default(false)),
42
+ __metadata("design:type", Boolean)
43
+ ], DockerPruneOptions.prototype, "volumes", void 0);