@vaharoni/devops 1.0.47

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 (342) hide show
  1. package/README.md +51 -0
  2. package/dist/app-support/crypto/index.d.ts +15 -0
  3. package/dist/app-support/crypto/index.d.ts.map +1 -0
  4. package/dist/app-support/crypto/index.js +30 -0
  5. package/dist/app-support/crypto/internal-token.d.ts +20 -0
  6. package/dist/app-support/crypto/internal-token.d.ts.map +1 -0
  7. package/dist/app-support/crypto/internal-token.js +42 -0
  8. package/dist/app-support/crypto/internal-token.spec.d.ts +2 -0
  9. package/dist/app-support/crypto/internal-token.spec.d.ts.map +1 -0
  10. package/dist/app-support/crypto/internal-token.spec.js +45 -0
  11. package/dist/app-support/crypto/secret.d.ts +3 -0
  12. package/dist/app-support/crypto/secret.d.ts.map +1 -0
  13. package/dist/app-support/crypto/secret.js +12 -0
  14. package/dist/app-support/crypto/secret.spec.d.ts +2 -0
  15. package/dist/app-support/crypto/secret.spec.d.ts.map +1 -0
  16. package/dist/app-support/crypto/secret.spec.js +15 -0
  17. package/dist/app-support/discovery/dev-discovery-loader.d.ts +2 -0
  18. package/dist/app-support/discovery/dev-discovery-loader.d.ts.map +1 -0
  19. package/dist/app-support/discovery/dev-discovery-loader.js +30 -0
  20. package/dist/app-support/discovery/service-endpoint.d.ts +2 -0
  21. package/dist/app-support/discovery/service-endpoint.d.ts.map +1 -0
  22. package/dist/app-support/discovery/service-endpoint.js +10 -0
  23. package/dist/cli/affected.d.ts +11 -0
  24. package/dist/cli/affected.d.ts.map +1 -0
  25. package/dist/cli/affected.js +103 -0
  26. package/dist/cli/common.d.ts +89 -0
  27. package/dist/cli/common.d.ts.map +1 -0
  28. package/dist/cli/common.js +236 -0
  29. package/dist/cli/common.spec.d.ts +2 -0
  30. package/dist/cli/common.spec.d.ts.map +1 -0
  31. package/dist/cli/common.spec.js +64 -0
  32. package/dist/cli/console.d.ts +11 -0
  33. package/dist/cli/console.d.ts.map +1 -0
  34. package/dist/cli/console.js +35 -0
  35. package/dist/cli/constant.d.ts +11 -0
  36. package/dist/cli/constant.d.ts.map +1 -0
  37. package/dist/cli/constant.js +22 -0
  38. package/dist/cli/db.d.ts +11 -0
  39. package/dist/cli/db.d.ts.map +1 -0
  40. package/dist/cli/db.js +119 -0
  41. package/dist/cli/dml.d.ts +11 -0
  42. package/dist/cli/dml.d.ts.map +1 -0
  43. package/dist/cli/dml.js +116 -0
  44. package/dist/cli/env.d.ts +11 -0
  45. package/dist/cli/env.d.ts.map +1 -0
  46. package/dist/cli/env.js +67 -0
  47. package/dist/cli/exec.d.ts +11 -0
  48. package/dist/cli/exec.d.ts.map +1 -0
  49. package/dist/cli/exec.js +50 -0
  50. package/dist/cli/image.d.ts +11 -0
  51. package/dist/cli/image.d.ts.map +1 -0
  52. package/dist/cli/image.js +140 -0
  53. package/dist/cli/init.d.ts +11 -0
  54. package/dist/cli/init.d.ts.map +1 -0
  55. package/dist/cli/init.js +66 -0
  56. package/dist/cli/internal-curl.d.ts +11 -0
  57. package/dist/cli/internal-curl.d.ts.map +1 -0
  58. package/dist/cli/internal-curl.js +43 -0
  59. package/dist/cli/job.d.ts +11 -0
  60. package/dist/cli/job.d.ts.map +1 -0
  61. package/dist/cli/job.js +67 -0
  62. package/dist/cli/jwt.d.ts +11 -0
  63. package/dist/cli/jwt.d.ts.map +1 -0
  64. package/dist/cli/jwt.js +27 -0
  65. package/dist/cli/namespace.d.ts +11 -0
  66. package/dist/cli/namespace.d.ts.map +1 -0
  67. package/dist/cli/namespace.js +70 -0
  68. package/dist/cli/prep-build.d.ts +11 -0
  69. package/dist/cli/prep-build.d.ts.map +1 -0
  70. package/dist/cli/prep-build.js +82 -0
  71. package/dist/cli/prisma.d.ts +11 -0
  72. package/dist/cli/prisma.d.ts.map +1 -0
  73. package/dist/cli/prisma.js +25 -0
  74. package/dist/cli/redis.d.ts +11 -0
  75. package/dist/cli/redis.d.ts.map +1 -0
  76. package/dist/cli/redis.js +76 -0
  77. package/dist/cli/registry.d.ts +11 -0
  78. package/dist/cli/registry.d.ts.map +1 -0
  79. package/dist/cli/registry.js +58 -0
  80. package/dist/cli/run-many.d.ts +11 -0
  81. package/dist/cli/run-many.d.ts.map +1 -0
  82. package/dist/cli/run-many.js +50 -0
  83. package/dist/cli/run.d.ts +11 -0
  84. package/dist/cli/run.d.ts.map +1 -0
  85. package/dist/cli/run.js +37 -0
  86. package/dist/cli/template.d.ts +11 -0
  87. package/dist/cli/template.d.ts.map +1 -0
  88. package/dist/cli/template.js +123 -0
  89. package/dist/cli/test.d.ts +11 -0
  90. package/dist/cli/test.d.ts.map +1 -0
  91. package/dist/cli/test.js +28 -0
  92. package/dist/devops.d.ts +3 -0
  93. package/dist/devops.d.ts.map +1 -0
  94. package/dist/devops.js +103 -0
  95. package/dist/index.d.ts +4 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +3 -0
  98. package/dist/libs/affected-entities.d.ts +15 -0
  99. package/dist/libs/affected-entities.d.ts.map +1 -0
  100. package/dist/libs/affected-entities.js +52 -0
  101. package/dist/libs/config.d.ts +6 -0
  102. package/dist/libs/config.d.ts.map +1 -0
  103. package/dist/libs/config.js +98 -0
  104. package/dist/libs/dependencies.d.ts +19 -0
  105. package/dist/libs/dependencies.d.ts.map +1 -0
  106. package/dist/libs/dependencies.js +62 -0
  107. package/dist/libs/dependencies.spec.d.ts +2 -0
  108. package/dist/libs/dependencies.spec.d.ts.map +1 -0
  109. package/dist/libs/dependencies.spec.js +21 -0
  110. package/dist/libs/digital-ocean/container-reg.d.ts +6 -0
  111. package/dist/libs/digital-ocean/container-reg.d.ts.map +1 -0
  112. package/dist/libs/digital-ocean/container-reg.js +69 -0
  113. package/dist/libs/discovery/dependencies.d.ts +19 -0
  114. package/dist/libs/discovery/dependencies.d.ts.map +1 -0
  115. package/dist/libs/discovery/dependencies.js +62 -0
  116. package/dist/libs/discovery/dependencies.spec.d.ts +2 -0
  117. package/dist/libs/discovery/dependencies.spec.d.ts.map +1 -0
  118. package/dist/libs/discovery/dependencies.spec.js +21 -0
  119. package/dist/libs/discovery/images.d.ts +5 -0
  120. package/dist/libs/discovery/images.d.ts.map +1 -0
  121. package/dist/libs/discovery/images.js +45 -0
  122. package/dist/libs/discovery/index.d.ts +5 -0
  123. package/dist/libs/discovery/index.d.ts.map +1 -0
  124. package/dist/libs/discovery/index.js +55 -0
  125. package/dist/libs/discovery/package-json-processor.d.ts +3 -0
  126. package/dist/libs/discovery/package-json-processor.d.ts.map +1 -0
  127. package/dist/libs/discovery/package-json-processor.js +34 -0
  128. package/dist/libs/discovery/process-common.d.ts +25 -0
  129. package/dist/libs/discovery/process-common.d.ts.map +1 -0
  130. package/dist/libs/discovery/process-common.js +40 -0
  131. package/dist/libs/discovery/process-package-json.d.ts +3 -0
  132. package/dist/libs/discovery/process-package-json.d.ts.map +1 -0
  133. package/dist/libs/discovery/process-package-json.js +34 -0
  134. package/dist/libs/discovery/process-pyproject-toml.d.ts +3 -0
  135. package/dist/libs/discovery/process-pyproject-toml.d.ts.map +1 -0
  136. package/dist/libs/discovery/process-pyproject-toml.js +36 -0
  137. package/dist/libs/discovery/pyproject-toml-processor.d.ts +3 -0
  138. package/dist/libs/discovery/pyproject-toml-processor.d.ts.map +1 -0
  139. package/dist/libs/discovery/pyproject-toml-processor.js +39 -0
  140. package/dist/libs/git-helpers.d.ts +8 -0
  141. package/dist/libs/git-helpers.d.ts.map +1 -0
  142. package/dist/libs/git-helpers.js +20 -0
  143. package/dist/libs/hetzner/reg-secret.d.ts +3 -0
  144. package/dist/libs/hetzner/reg-secret.d.ts.map +1 -0
  145. package/dist/libs/hetzner/reg-secret.js +39 -0
  146. package/dist/libs/k8s-constants.d.ts +12 -0
  147. package/dist/libs/k8s-constants.d.ts.map +1 -0
  148. package/dist/libs/k8s-constants.js +66 -0
  149. package/dist/libs/k8s-db.d.ts +18 -0
  150. package/dist/libs/k8s-db.d.ts.map +1 -0
  151. package/dist/libs/k8s-db.js +73 -0
  152. package/dist/libs/k8s-generate.d.ts +17 -0
  153. package/dist/libs/k8s-generate.d.ts.map +1 -0
  154. package/dist/libs/k8s-generate.js +179 -0
  155. package/dist/libs/k8s-helpers.d.ts +11 -0
  156. package/dist/libs/k8s-helpers.d.ts.map +1 -0
  157. package/dist/libs/k8s-helpers.js +42 -0
  158. package/dist/libs/k8s-image-config.d.ts +8 -0
  159. package/dist/libs/k8s-image-config.d.ts.map +1 -0
  160. package/dist/libs/k8s-image-config.js +113 -0
  161. package/dist/libs/k8s-job-waiter.d.ts +8 -0
  162. package/dist/libs/k8s-job-waiter.d.ts.map +1 -0
  163. package/dist/libs/k8s-job-waiter.js +84 -0
  164. package/dist/libs/k8s-namespace.d.ts +7 -0
  165. package/dist/libs/k8s-namespace.d.ts.map +1 -0
  166. package/dist/libs/k8s-namespace.js +27 -0
  167. package/dist/libs/k8s-redis.d.ts +6 -0
  168. package/dist/libs/k8s-redis.d.ts.map +1 -0
  169. package/dist/libs/k8s-redis.js +31 -0
  170. package/dist/libs/k8s-secrets-manager.d.ts +5 -0
  171. package/dist/libs/k8s-secrets-manager.d.ts.map +1 -0
  172. package/dist/libs/k8s-secrets-manager.js +61 -0
  173. package/dist/libs/validate-env.d.ts +56 -0
  174. package/dist/libs/validate-env.d.ts.map +1 -0
  175. package/dist/libs/validate-env.js +214 -0
  176. package/dist/libs/validate-env.spec.d.ts +2 -0
  177. package/dist/libs/validate-env.spec.d.ts.map +1 -0
  178. package/dist/libs/validate-env.spec.js +168 -0
  179. package/dist/libs/workspace-discovery.d.ts +2 -0
  180. package/dist/libs/workspace-discovery.d.ts.map +1 -0
  181. package/dist/libs/workspace-discovery.js +75 -0
  182. package/dist/test.d.ts +2 -0
  183. package/dist/test.d.ts.map +1 -0
  184. package/dist/test.js +1 -0
  185. package/dist/types/index.d.ts +925 -0
  186. package/dist/types/index.d.ts.map +1 -0
  187. package/dist/types/index.js +79 -0
  188. package/package.json +55 -0
  189. package/src/app-support/crypto/index.ts +31 -0
  190. package/src/app-support/crypto/internal-token.spec.ts +53 -0
  191. package/src/app-support/crypto/internal-token.ts +82 -0
  192. package/src/app-support/crypto/secret.spec.ts +18 -0
  193. package/src/app-support/crypto/secret.ts +13 -0
  194. package/src/app-support/discovery/dev-discovery-loader.ts +35 -0
  195. package/src/app-support/discovery/service-endpoint.ts +12 -0
  196. package/src/cli/affected.ts +116 -0
  197. package/src/cli/common.spec.ts +78 -0
  198. package/src/cli/common.ts +323 -0
  199. package/src/cli/console.ts +46 -0
  200. package/src/cli/constant.ts +25 -0
  201. package/src/cli/db.ts +133 -0
  202. package/src/cli/dml.ts +126 -0
  203. package/src/cli/env.ts +87 -0
  204. package/src/cli/exec.sh +21 -0
  205. package/src/cli/exec.ts +57 -0
  206. package/src/cli/image.ts +197 -0
  207. package/src/cli/init.ts +75 -0
  208. package/src/cli/internal-curl.ts +48 -0
  209. package/src/cli/job.ts +80 -0
  210. package/src/cli/jwt.ts +32 -0
  211. package/src/cli/namespace.ts +78 -0
  212. package/src/cli/prep-build.ts +96 -0
  213. package/src/cli/prisma.ts +33 -0
  214. package/src/cli/redis.ts +83 -0
  215. package/src/cli/registry.ts +76 -0
  216. package/src/cli/run-many.ts +61 -0
  217. package/src/cli/run.ts +46 -0
  218. package/src/cli/template.ts +169 -0
  219. package/src/cli/test.ts +30 -0
  220. package/src/devops.ts +119 -0
  221. package/src/index.ts +3 -0
  222. package/src/libs/affected-entities.ts +71 -0
  223. package/src/libs/config.ts +117 -0
  224. package/src/libs/digital-ocean/container-reg.ts +81 -0
  225. package/src/libs/discovery/dependencies.spec.ts +25 -0
  226. package/src/libs/discovery/dependencies.ts +73 -0
  227. package/src/libs/discovery/images.ts +57 -0
  228. package/src/libs/discovery/index.ts +60 -0
  229. package/src/libs/discovery/process-common.ts +55 -0
  230. package/src/libs/discovery/process-package-json.ts +47 -0
  231. package/src/libs/discovery/process-pyproject-toml.ts +43 -0
  232. package/src/libs/git-helpers.ts +32 -0
  233. package/src/libs/hetzner/reg-secret.ts +54 -0
  234. package/src/libs/k8s-constants.ts +83 -0
  235. package/src/libs/k8s-db.ts +83 -0
  236. package/src/libs/k8s-generate.ts +211 -0
  237. package/src/libs/k8s-helpers.ts +59 -0
  238. package/src/libs/k8s-image-config.ts +165 -0
  239. package/src/libs/k8s-job-waiter.ts +124 -0
  240. package/src/libs/k8s-namespace.ts +41 -0
  241. package/src/libs/k8s-redis.ts +31 -0
  242. package/src/libs/k8s-secrets-manager.ts +79 -0
  243. package/src/libs/validate-env.spec.ts +223 -0
  244. package/src/libs/validate-env.ts +266 -0
  245. package/src/target-templates/.devops/config/constants.yaml +17 -0
  246. package/src/target-templates/.devops/config/images.yaml +88 -0
  247. package/src/target-templates/.devops/docker-images/common/docker-common.sh +23 -0
  248. package/src/target-templates/.devops/docker-images/node-services/node-exec.sh +8 -0
  249. package/src/target-templates/.devops/docker-images/node-services/node-run.sh +8 -0
  250. package/src/target-templates/.devops/docker-images/node-services.Dockerfile +34 -0
  251. package/src/target-templates/.devops/docker-images/python-services/python-exec.sh +8 -0
  252. package/src/target-templates/.devops/docker-images/python-services/python-run.sh +8 -0
  253. package/src/target-templates/.devops/docker-images/python-services.Dockerfile +29 -0
  254. package/src/target-templates/.devops/env.example.yaml +23 -0
  255. package/src/target-templates/.devops/infra/hetzner/abandoned/harbor-values.yaml +30 -0
  256. package/src/target-templates/.devops/infra/hetzner/abandoned/hcloud-config.yaml +134 -0
  257. package/src/target-templates/.devops/infra/hetzner/cert-manager.yaml +25 -0
  258. package/src/target-templates/.devops/infra/hetzner/harbor-cert.yaml +13 -0
  259. package/src/target-templates/.devops/infra/hetzner/harbor-values.yaml +76 -0
  260. package/src/target-templates/.devops/infra/hetzner/hcloud-config.yaml +113 -0
  261. package/src/target-templates/.devops/infra/hetzner/ingress-nginx-annotations.yaml +49 -0
  262. package/src/target-templates/.devops/infra/hetzner/ingress-nginx-configmap.yaml +8 -0
  263. package/src/target-templates/.devops/infra/hetzner/retain-storage-class.yaml +8 -0
  264. package/src/target-templates/.devops/infra/monitoring-ingress.yaml +62 -0
  265. package/src/target-templates/.devops/infra/stackgres-ui-ingress.yaml +35 -0
  266. package/src/target-templates/.devops/infra/test.yaml +60 -0
  267. package/src/target-templates/.devops/manifests/_index.yaml +21 -0
  268. package/src/target-templates/.devops/manifests/cron-jobs.yaml.hb +55 -0
  269. package/src/target-templates/.devops/manifests/db-migrate-job.yaml.hb +42 -0
  270. package/src/target-templates/.devops/manifests/deployment-debug.yaml.hb +44 -0
  271. package/src/target-templates/.devops/manifests/deployment-process.yaml.hb +47 -0
  272. package/src/target-templates/.devops/manifests/deployment-web.yaml.hb +53 -0
  273. package/src/target-templates/.devops/manifests/ingress.yaml.hb +21 -0
  274. package/src/target-templates/.devops/manifests/prefect.yaml.hb +62 -0
  275. package/src/target-templates/.devops/manifests/service.yaml.hb +15 -0
  276. package/src/target-templates/.devops/milvus/production/milvus-values.yaml +2 -0
  277. package/src/target-templates/.devops/milvus/staging/milvus-values.yaml +2 -0
  278. package/src/target-templates/.devops/postgres/DailyOperatorRestart.yaml +54 -0
  279. package/src/target-templates/.devops/postgres/production/cluster/PodDisruptionBudget.yaml +27 -0
  280. package/src/target-templates/.devops/postgres/production/cluster/SGCluster.yaml +47 -0
  281. package/src/target-templates/.devops/postgres/production/cluster/StackGres-alerts.yaml +191 -0
  282. package/src/target-templates/.devops/postgres/production/configurations/06-SGDistributedLogs.yaml +11 -0
  283. package/src/target-templates/.devops/postgres/production/configurations/07-SGObjectStorage.yaml +18 -0
  284. package/src/target-templates/.devops/postgres/production/configurations/08-SGScript.yaml +12 -0
  285. package/src/target-templates/.devops/postgres/staging/cluster/SGCluster.yaml +42 -0
  286. package/src/target-templates/.devops/postgres/staging/configurations/07-SGObjectStorage.yaml +18 -0
  287. package/src/target-templates/.devops/postgres/staging/configurations/08-SGScript.yaml +12 -0
  288. package/src/target-templates/.devops/prefect/production/prefect-values.yaml +14 -0
  289. package/src/target-templates/.devops/prefect/staging/prefect-values.yaml +14 -0
  290. package/src/target-templates/.devops/redis/production/redis-values.yaml +20 -0
  291. package/src/target-templates/.devops/redis/staging/redis-values.yaml +8 -0
  292. package/src/target-templates/.envrc +5 -0
  293. package/src/target-templates/.github/actions/build-image@v1/action.yaml +86 -0
  294. package/src/target-templates/.github/actions/connect-to-digital-ocean@v1/action.yaml +29 -0
  295. package/src/target-templates/.github/actions/connect-to-hetzner@v1/action.yaml +31 -0
  296. package/src/target-templates/.github/actions/connect-to-infra@v1/action.yaml +46 -0
  297. package/src/target-templates/.github/actions/db-migrate@v1/action.yaml +23 -0
  298. package/src/target-templates/.github/actions/deploy-image@v1/action.yaml +33 -0
  299. package/src/target-templates/.github/actions/setup-prereq@v1/action.yaml +29 -0
  300. package/src/target-templates/.github/workflows/k8s-build.yaml +84 -0
  301. package/src/target-templates/applications/example-data-pipeline/pyproject.toml +14 -0
  302. package/src/target-templates/applications/example-data-pipeline/src/example_data_pipeline/main.py +38 -0
  303. package/src/target-templates/applications/example-node/index.ts +30 -0
  304. package/src/target-templates/applications/example-node/package.json +26 -0
  305. package/src/target-templates/applications/example-node/tsconfig.json +3 -0
  306. package/src/target-templates/applications/example-python/pyproject.toml +20 -0
  307. package/src/target-templates/applications/example-python/src/example_python/__init__.py +0 -0
  308. package/src/target-templates/applications/example-python/src/example_python/main.py +13 -0
  309. package/src/target-templates/applications/example-python/src/example_python/scripts.py +17 -0
  310. package/src/target-templates/applications/example-python/tests/__init__.py +0 -0
  311. package/src/target-templates/applications/jobs/README.md +68 -0
  312. package/src/target-templates/applications/jobs/index.ts +1 -0
  313. package/src/target-templates/applications/jobs/package.json +30 -0
  314. package/src/target-templates/applications/jobs/tsconfig.json +3 -0
  315. package/src/target-templates/config/.env.development +1 -0
  316. package/src/target-templates/config/.env.global +4 -0
  317. package/src/target-templates/config/.env.test +1 -0
  318. package/src/target-templates/db/db/__init__.py +0 -0
  319. package/src/target-templates/db/db/db_client_test.py +46 -0
  320. package/src/target-templates/db/db-client-test.ts +140 -0
  321. package/src/target-templates/db/db-client.ts +19 -0
  322. package/src/target-templates/db/env.yaml +4 -0
  323. package/src/target-templates/db/package.json +17 -0
  324. package/src/target-templates/db/prisma/schema.prisma +24 -0
  325. package/src/target-templates/db/prisma-setup-vitest.ts +27 -0
  326. package/src/target-templates/db/pyproject.toml +14 -0
  327. package/src/target-templates/db/tsconfig.json +3 -0
  328. package/src/target-templates/devops +3 -0
  329. package/src/target-templates/devopspy +3 -0
  330. package/src/target-templates/dml/package.json +7 -0
  331. package/src/target-templates/dml/tsconfig.json +3 -0
  332. package/src/target-templates/libs/example-node-lib/bun.lock +27 -0
  333. package/src/target-templates/libs/example-node-lib/index.ts +3 -0
  334. package/src/target-templates/libs/example-node-lib/package.json +12 -0
  335. package/src/target-templates/libs/example-node-lib/tsconfig.json +3 -0
  336. package/src/target-templates/libs/example-python-lib/pyproject.toml +11 -0
  337. package/src/target-templates/libs/example-python-lib/src/example_python_lib/__init__.py +2 -0
  338. package/src/target-templates/pyproject.toml +19 -0
  339. package/src/target-templates/tmp/.gitkeep +0 -0
  340. package/src/target-templates/tsconfig.json +27 -0
  341. package/src/test.ts +0 -0
  342. package/src/types/index.ts +173 -0
@@ -0,0 +1,96 @@
1
+ import fs from "fs-extra";
2
+ import os from "os";
3
+ import path from "path";
4
+ import { CLICommandParser, printUsageAndExit } from "./common";
5
+ import { getImageData, getTemplateData } from "../libs/config";
6
+ import { getMonorepoSecret } from "../libs/k8s-secrets-manager";
7
+ import { getImageDescendentData } from "../libs/discovery/images";
8
+
9
+ const oneLiner =
10
+ "Copies all dependencies of an image to a temporary folder in preparation for a Docker build";
11
+ const keyExamples = `
12
+ $ devops prep-build main-node
13
+ `.trim();
14
+
15
+ const usage = `
16
+ ${oneLiner}
17
+
18
+ USAGE
19
+ devops prep-build <image>
20
+
21
+ EXAMPLES
22
+ ${keyExamples}
23
+ `;
24
+
25
+ async function run(cmdObj: CLICommandParser) {
26
+ if (cmdObj.help || cmdObj.args.length === 0) printUsageAndExit(usage);
27
+ const [image] = cmdObj.args;
28
+ const imageData = getImageData(image);
29
+ const imageTemplate = imageData["image-template"];
30
+ const dockerFile = `${imageTemplate}.Dockerfile`;
31
+ const dockerFilePath = path.join(".devops/docker-images", dockerFile);
32
+ const dockerImagePayloadPath = path.join(".devops/docker-images", imageTemplate);
33
+ const dockerCommonPayloadPath = path.join(".devops/docker-images", "common");
34
+ const imageTemplateData = getTemplateData(imageTemplate);
35
+ const copyCommon = imageTemplateData["copy-common"] ?? false;
36
+ const imageExtraContent = imageTemplateData["extra-content"] ?? [];
37
+
38
+ if (!fs.existsSync(dockerFilePath)) {
39
+ console.error(`The dockerfile ${dockerFilePath} does not exist`);
40
+ process.exit(1);
41
+ }
42
+
43
+ imageExtraContent.forEach((file) => {
44
+ if (!fs.existsSync(file)) {
45
+ console.error(`The file ${file} is specified in the extra-content section of ${image} but does not exist`);
46
+ process.exit(1);
47
+ }
48
+ });
49
+
50
+ const destFolder = `${os.tmpdir()}/image-${image}-${Date.now()}`;
51
+ // Avoid clutter stdout, as the caller will want to capture the final output to cd into it
52
+ console.warn(`Creating build in ${destFolder}`);
53
+ fs.mkdirSync(destFolder);
54
+
55
+ // Copy Dockerfile
56
+ console.warn(`COPYING Dockerfile`);
57
+ fs.copySync(dockerFilePath, path.join(destFolder, "Dockerfile"));
58
+
59
+ if (copyCommon) {
60
+ console.warn(`COPYING Docker common`);
61
+ fs.copySync(dockerCommonPayloadPath, destFolder);
62
+ }
63
+
64
+ console.warn(`COPYING Docker image payload`);
65
+ fs.copySync(dockerImagePayloadPath, destFolder);
66
+
67
+ console.warn(`COPYING .devops/config`);
68
+ fs.mkdirSync(path.join(destFolder, ".devops"));
69
+ fs.copySync(".devops/config", path.join(destFolder, ".devops/config"));
70
+
71
+ // Create config directory. It should be deleted by the docker image so that it can be mounted as a volume when the pod is run
72
+ console.warn(`CREATING config for the build process`);
73
+ fs.mkdirSync(path.join(destFolder, "config"));
74
+ const envFileData = getMonorepoSecret(cmdObj.env);
75
+ fs.writeFileSync(path.join(destFolder, `config/.env.global`), envFileData);
76
+
77
+ // Copy all dependencies
78
+ getImageDescendentData(image).forEach((project) => {
79
+ console.warn(`COPYING ${project.rootPath}`);
80
+ if (project.rootPath === ".devops") return;
81
+ fs.copySync(project.rootPath, path.join(destFolder, project.rootPath));
82
+ });
83
+
84
+ // Copy image-extra content
85
+ console.warn(`COPYING files from image-extra-content`);
86
+ imageExtraContent.forEach((file) => {
87
+ fs.copySync(file, path.join(destFolder, file));
88
+ console.warn(` ${file}`);
89
+ });
90
+
91
+ console.log(destFolder);
92
+ }
93
+
94
+ export default {
95
+ "prep-build": { oneLiner, keyExamples, run },
96
+ };
@@ -0,0 +1,33 @@
1
+ import { CLICommandParser, printUsageAndExit } from "./common";
2
+ import url from "url";
3
+ import path from "path";
4
+
5
+ const __file__ = url.fileURLToPath(import.meta.url);
6
+ const __src__ = path.join(path.dirname(__file__), "../..", "src");
7
+ const execShPath = path.join(__src__, "cli/exec.sh");
8
+
9
+ const oneLiner = "Runs prisma commands in the db project after injecting the environment variables";
10
+ const keyExamples = `$ devops prisma migrate dev`;
11
+
12
+ const usage = `
13
+ ${oneLiner}
14
+
15
+ GENERAL USAGE
16
+ devops prisma <command>
17
+
18
+ <command> can be any command you normally set prisma for.
19
+
20
+ EXAMPLES
21
+ ${keyExamples}
22
+ `;
23
+
24
+ async function run(cmdObj: CLICommandParser) {
25
+ cmdObj.executorFromEnv(
26
+ `${execShPath} db prisma ${cmdObj.args.join(" ")}`,
27
+ { checkEnvYaml: false }
28
+ ).spawn()
29
+ }
30
+
31
+ export default {
32
+ prisma: { oneLiner, keyExamples, run },
33
+ };
@@ -0,0 +1,83 @@
1
+ import chalk from "chalk";
2
+ import { establishRedisTunnel, getRedisList, getRedisPassword } from "../libs/k8s-redis";
3
+ import { CLICommandParser, printUsageAndExit, StrongParams } from "./common";
4
+
5
+ const oneLiner =
6
+ "Utilities to help accessing production and staging redis";
7
+ const keyExamples = `
8
+ $ devops redis list
9
+ $ devops redis password redis-staging
10
+ $ devops redis tunnel redis-staging
11
+ `.trim();
12
+
13
+ const usage = `
14
+ ${oneLiner}
15
+
16
+ COMMANDS
17
+ list Lists the available redis installations
18
+ password <namespace> Shows the password for the Redis instance
19
+ tunnel <namespace> [-p <port>] Sets up a tunnel to the remote Redis instance so you can access the DB from your local machine on port 9379 by default
20
+
21
+ NOTES
22
+ This command assumes the namespace and the helm release name are the same.
23
+ The --env flag should not be used with these commands, as the Redis namespaces follow different conventions than the monorepo env.
24
+
25
+ EXAMPLES
26
+ ${keyExamples}
27
+ `;
28
+
29
+ const handlers = {
30
+ list: () => {
31
+ const res = getRedisList();
32
+ console.log(res);
33
+ },
34
+ password: (opts: StrongParams) => {
35
+ const namespace = opts.required("namespace");
36
+ const res = getRedisPassword(namespace);
37
+ if (!res) {
38
+ console.error("Failed to get the secret");
39
+ process.exit(1);
40
+ } else {
41
+ console.log();
42
+ console.log(res.password);
43
+ console.log();
44
+ }
45
+ },
46
+ tunnel: (opts: StrongParams) => {
47
+ const namespace = opts.required("namespace");
48
+ const port = opts.optional("port") ?? '9379';
49
+ const res = getRedisPassword(namespace);
50
+ console.log(
51
+ chalk.blue('\nAfter the tunnel is established, connect to Redis by running:\n\t') +
52
+ chalk.green.bold(`redis-cli -p ${port} --askpass`)
53
+ );
54
+ if (res) {
55
+ console.log(chalk.blue('\tPassword: ') + chalk.green.bold(res.password))
56
+ console.log();
57
+ }
58
+ establishRedisTunnel(namespace, port);
59
+ },
60
+ };
61
+
62
+ function run(cmdObj: CLICommandParser) {
63
+ if (cmdObj.help || cmdObj.args.length < 1) printUsageAndExit(usage);
64
+ const parsed = cmdObj.parseOptions({ params: ["-p"] });
65
+
66
+ const [command, namespace] = parsed.args;
67
+ const port = parsed.options["-p"] as string;
68
+ // @ts-expect-error left as an exercise for the reader
69
+ const handler = handlers[command];
70
+ if (!handler) {
71
+ console.error(`Unknown command: ${command}`);
72
+ printUsageAndExit(usage);
73
+ }
74
+ const params = new StrongParams(usage, {
75
+ namespace,
76
+ port,
77
+ });
78
+ handler(params);
79
+ }
80
+
81
+ export default {
82
+ redis: { oneLiner, keyExamples, run },
83
+ };
@@ -0,0 +1,76 @@
1
+ import { getConst, getImageData } from "../libs/config";
2
+ import { prune } from "../libs/digital-ocean/container-reg";
3
+ import {
4
+ containerRegistryPath,
5
+ containerRegistryRepoName,
6
+ containerRegistryRepoPath,
7
+ } from "../libs/k8s-constants";
8
+ import { CLICommandParser, StrongParams, printUsageAndExit } from "./common";
9
+
10
+ const oneLiner = "Manage container repositories";
11
+ const keyExamples = `
12
+ $ devops registry server-url
13
+ $ devops registry reg-url
14
+ $ devops registry repo-url my-image sha
15
+ $ devops registry prune my-image
16
+ `.trim();
17
+
18
+ const usage = `
19
+ ${oneLiner}
20
+
21
+ USAGE
22
+ Get base URLs
23
+ devops registry server-url
24
+ devops registry reg-url
25
+
26
+ Gets the URL of an image in the container registry:
27
+ devops registry repo-url <image> <sha> --env <env>
28
+
29
+ Prunes the repository of old images to enforce the "image-versions-to-keep" constant in config/constants.yaml:
30
+ devops registry prune <image> --env <env>
31
+
32
+ This is only relevant when the "infra" constant is set to "digitalocean".
33
+
34
+ EXAMPLES
35
+ ${keyExamples}
36
+ `;
37
+
38
+ const handlers = {
39
+ "server-url": () => console.log(getConst("registry-base-url")),
40
+ "reg-url": () => console.log(containerRegistryPath()),
41
+ "repo-url": (opts: StrongParams) => {
42
+ console.log(
43
+ containerRegistryRepoPath(
44
+ opts.required("image"),
45
+ opts.required("env"),
46
+ opts.required("sha")
47
+ )
48
+ );
49
+ },
50
+ prune: (opts: StrongParams) => {
51
+ const regName = containerRegistryPath();
52
+ const repoName = containerRegistryRepoName(
53
+ opts.required("image"),
54
+ opts.required("env")
55
+ );
56
+ prune(regName, repoName);
57
+ },
58
+ };
59
+
60
+ function run(cmdObj: CLICommandParser) {
61
+ if (cmdObj.help || cmdObj.args.length < 1) printUsageAndExit(usage);
62
+
63
+ const [command, image, sha] = cmdObj.args;
64
+ // @ts-expect-error left as an exercise for the reader
65
+ const handler = handlers[command];
66
+ if (!handler) {
67
+ console.error(`Unknown command: ${command}`);
68
+ printUsageAndExit(usage);
69
+ }
70
+ const params = new StrongParams(usage, { image, env: cmdObj.env, sha });
71
+ handler(params);
72
+ }
73
+
74
+ export default {
75
+ registry: { oneLiner, keyExamples, run },
76
+ };
@@ -0,0 +1,61 @@
1
+ import { workspaceDirectoryForLanguage } from "../libs/discovery";
2
+ import { CLICommandParser, printUsageAndExit } from "./common";
3
+ import concurrently, {
4
+ type ConcurrentlyCommandInput,
5
+ type ConcurrentlyOptions,
6
+ } from "concurrently";
7
+
8
+ const oneLiner =
9
+ "Runs a script concurrently in all projects that define it in their package.json";
10
+ const keyExamples = `
11
+ $ devops run-many build
12
+ `.trim();
13
+
14
+ const usage = `
15
+ ${oneLiner}
16
+
17
+ USAGE
18
+ devops run-many <script-name> [--kill-others-on-fail]
19
+
20
+ NOTE
21
+ Only works for node projects. Use 'devopspy' for python projects.
22
+
23
+ EXAMPLES
24
+ ${keyExamples}
25
+ `;
26
+
27
+ async function run(cmdObj: CLICommandParser) {
28
+ if (cmdObj.help || cmdObj.args.length === 0) printUsageAndExit(usage);
29
+ const parsed = cmdObj.parseOptions({ booleans: ["--kill-others-on-fail"] });
30
+ const [script] = parsed.args;
31
+ const remaining = parsed.args.slice(1).join(" ");
32
+ const commands: ConcurrentlyCommandInput[] = [];
33
+
34
+ Object.values(workspaceDirectoryForLanguage('node')).forEach(async (packageData) => {
35
+ if (packageData.scripts?.[script]) {
36
+ commands.push({
37
+ name: packageData.name,
38
+ command: `devops --env ${cmdObj.env} run ${packageData.name}:${script} ${remaining}`,
39
+ });
40
+ }
41
+ });
42
+
43
+ if (!commands.length) {
44
+ console.error(`No workspaces define the script: ${script}`);
45
+ process.exit(0);
46
+ }
47
+
48
+ // prettier-ignore
49
+ const options: Partial<ConcurrentlyOptions> = parsed.options["--kill-others-on-fail"] ? { killOthers: "failure" } : {};
50
+
51
+ concurrently(commands, options)
52
+ .result.then(() => {})
53
+ .catch((error) => {
54
+ console.error("One of the commands failed");
55
+ process.exit(1);
56
+ });
57
+ }
58
+
59
+ export default {
60
+ "run-many": { oneLiner, keyExamples, run },
61
+ };
package/src/cli/run.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { CLICommandParser, printUsageAndExit } from "./common";
2
+ import url from "url";
3
+ import path from "path";
4
+ import { getWorkspace } from "../libs/discovery";
5
+
6
+ const __file__ = url.fileURLToPath(import.meta.url);
7
+ const __src__ = path.join(path.dirname(__file__), "../..", "src");
8
+ const execShPath = path.join(__src__, "cli/exec.sh");
9
+
10
+ const oneLiner =
11
+ "Runs a script defined in package.json after injecting env variables";
12
+ const keyExamples = `$ devops run project:test`;
13
+
14
+ const usage = `
15
+ ${oneLiner}
16
+
17
+ GENERAL USAGE
18
+ devops run <project-name>:<script-name> [--] [options for script]
19
+
20
+ NOTES
21
+ - Only works for node projects. Use 'devopspy' for python projects.
22
+ - Does not allow interactive mode. If you need interactivity, use devops exec instead.
23
+
24
+ EXAMPLES
25
+ ${keyExamples}
26
+ `;
27
+
28
+ async function run(cmdObj: CLICommandParser) {
29
+ if (cmdObj.help || cmdObj.args.length === 0) printUsageAndExit(usage);
30
+ const [workspace, script] = cmdObj.args[0].split(":");
31
+ if (!workspace || !script) printUsageAndExit(usage);
32
+
33
+ const rootPath = getWorkspace(workspace).rootPath;
34
+ const remaining = cmdObj.args.slice(1).join(" ");
35
+
36
+ cmdObj
37
+ .executorFromEnv(
38
+ `${execShPath} ${rootPath} bun run ${script} ${remaining}`,
39
+ { checkEnvYaml: true }
40
+ )
41
+ .spawn();
42
+ }
43
+
44
+ export default {
45
+ run: { oneLiner, keyExamples, run },
46
+ };
@@ -0,0 +1,169 @@
1
+ import {
2
+ } from "../libs/k8s-image-config";
3
+ import { CLICommandParser, printUsageAndExit, StrongParams } from "../../src/cli/common";
4
+ import { generateDbMigrateJob, generateDebugDeployment, generateWorkspaceDeployment, ImageContextGenerator } from "../libs/k8s-generate";
5
+ import chalk from "chalk";
6
+ import { getWorkspace } from "../libs/discovery";
7
+ import { getWorkspaceImages } from "../libs/discovery/images";
8
+ import { getImageData, getImageNames } from "../libs/config";
9
+
10
+ const SUPPORTED_CONTEXT_TYPES = ['deployment', 'db-migrate', 'debug'];
11
+
12
+ const oneLiner = "Utilities to help validate manifest templates rendering.";
13
+ const keyExamples = `
14
+ $ devops template context deployment www
15
+ $ devops template context debug
16
+ $ devops template context db-migrate
17
+ $ devops template gen deployment www
18
+ $ devops template gen debug main-node
19
+ $ devops template gen db-migrate
20
+ `.trim();
21
+
22
+ const usage = `
23
+ ${oneLiner}
24
+
25
+ IMPORTANT
26
+ This command generates examples only. It's intended to help design new templates by showing what context variables are available
27
+ and how they get rendered using handlebar replacement. They should not be used to apply changes to the cluster.
28
+
29
+ SHOW CONTEXT OBJECT
30
+ devops template context deployment <workspace>
31
+ devops template context db-migrate-job|debug
32
+
33
+ Prints out a context object with dummy values for the specified template type.
34
+ For deployment, the workspace name is required.
35
+
36
+ GENERATE TEMPLATES
37
+ devops template gen deployment <workspace>
38
+ devops template gen debug <image>
39
+ devops template gen db-migrate-job
40
+
41
+ For deployment, generates an example manifest of a workspace, including override files present under the 'manifests' folder.
42
+
43
+ EXAMPLES
44
+ ${keyExamples}
45
+ `;
46
+
47
+ const handlers = {
48
+ context: {
49
+ 'deployment': (opts: StrongParams) => {
50
+ const workspace = opts.required('workspaceOrImage');
51
+ const workspaceData = getWorkspace(workspace);
52
+ const packageDataWithDeployment = workspaceData.packageDataEntries.find((entry) => entry.deployment);
53
+ if (!packageDataWithDeployment) {
54
+ console.error(`No deployment found for workspace ${workspace}`);
55
+ process.exit(1);
56
+ }
57
+ const randomImage = getWorkspaceImages(workspace)[0];
58
+ console.warn(chalk.green("\nThis is a sample context object used to render a manifest template of type deployment:\n"))
59
+ console.log(
60
+ JSON.stringify(
61
+ new ImageContextGenerator(opts.required('env'), randomImage, 'dummy-sha').getDeployment(packageDataWithDeployment),
62
+ null,
63
+ 2
64
+ )
65
+ )
66
+ },
67
+ 'db-migrate': (opts: StrongParams) => {
68
+ const randomImage = getWorkspaceImages('db').filter(image => getImageData(image)['can-db-migrate'])[0];
69
+ if (!randomImage) {
70
+ console.error("No image found with can-db-migrate=true in the db workspace.");
71
+ process.exit(1);
72
+ }
73
+ console.warn(chalk.green("\nThis is a sample context object used to render a manifest template of type db-migrate:\n"))
74
+ console.log(
75
+ JSON.stringify(
76
+ new ImageContextGenerator(opts.required('env'), randomImage, 'dummy-sha').getDbMigrate(),
77
+ null,
78
+ 2
79
+ )
80
+ )
81
+ },
82
+ 'debug': (opts: StrongParams) => {
83
+ const randomImage = getImageNames()[0];
84
+ console.warn(chalk.green("\nThis is a sample context object used to render a manifest template of type debug:\n"))
85
+ console.log(
86
+ JSON.stringify(
87
+ new ImageContextGenerator(opts.required('env'), randomImage, 'dummy-sha').getDebug(),
88
+ null,
89
+ 2
90
+ )
91
+ )
92
+ },
93
+ },
94
+ gen: {
95
+ 'deployment': (opts: StrongParams) => {
96
+ const workspace = opts.required('workspaceOrImage');
97
+ const workspaceData = getWorkspace(workspace);
98
+ const packageDataWithDeployment = workspaceData.packageDataEntries.find((entry) => entry.deployment);
99
+ if (!packageDataWithDeployment) {
100
+ console.error(`No deployment found for workspace ${workspace}`);
101
+ process.exit(1);
102
+ }
103
+ const randomImage = getWorkspaceImages(workspace)[0];
104
+ console.warn(chalk.green(`\nThis is a sample of generated manifests for the ${workspace} workspace:\n`))
105
+ console.log(
106
+ generateWorkspaceDeployment(
107
+ packageDataWithDeployment,
108
+ opts.required('env'),
109
+ randomImage,
110
+ 'dummy-sha'
111
+ )
112
+ )
113
+ },
114
+ 'db-migrate': (opts: StrongParams) => {
115
+ const randomImage = getWorkspaceImages('db').filter(image => getImageData(image)['can-db-migrate'])[0];
116
+ if (!randomImage) {
117
+ console.error("No image found with can-db-migrate=true in the db workspace.");
118
+ process.exit(1);
119
+ }
120
+ console.warn(chalk.green("\nThis is a sample of generated manifests for the db-migrate job:\n"))
121
+ console.log(
122
+ generateDbMigrateJob(
123
+ opts.required('env'),
124
+ randomImage,
125
+ 'dummy-sha'
126
+ )
127
+ )
128
+ },
129
+ 'debug': (opts: StrongParams) => {
130
+ const image = opts.required('workspaceOrImage');
131
+ console.warn(chalk.green(`\nThis is a sample of generated manifests for the debug image ${image}:\n`))
132
+ console.log(
133
+ generateDebugDeployment(
134
+ opts.required('env'),
135
+ image,
136
+ 'dummy-sha'
137
+ )
138
+ )
139
+ },
140
+ },
141
+ };
142
+
143
+ function run(cmdObj: CLICommandParser) {
144
+ if (cmdObj.help || cmdObj.args.length < 1) printUsageAndExit(usage);
145
+
146
+ const [command, contextType, param] = cmdObj.args;
147
+ const commandHandler = handlers[command as keyof typeof handlers];
148
+ if (!commandHandler) {
149
+ console.error(`Unknown command: ${command}`);
150
+ printUsageAndExit(usage);
151
+ }
152
+
153
+ if (!SUPPORTED_CONTEXT_TYPES.includes(contextType)) {
154
+ console.error(`Unknown context type: ${contextType}. Supported types: ${SUPPORTED_CONTEXT_TYPES.join(', ')}`);
155
+ process.exit(1);
156
+ }
157
+ const handler = commandHandler[contextType as keyof typeof commandHandler];
158
+
159
+ const params = new StrongParams(usage, {
160
+ env: cmdObj.env === 'development' ? 'staging' : cmdObj.env,
161
+ contextType,
162
+ workspaceOrImage: param
163
+ });
164
+ handler(params);
165
+ }
166
+
167
+ export default {
168
+ template: { oneLiner, keyExamples, run },
169
+ };
@@ -0,0 +1,30 @@
1
+ import { CLICommandParser, CommandExecutor, printUsageAndExit } from "./common";
2
+
3
+ const oneLiner = "Runs tests in all projects or one specific project";
4
+ const keyExamples = `
5
+ $ devops test
6
+ $ devops test project
7
+ `;
8
+
9
+ const usage = `
10
+ ${oneLiner}
11
+
12
+ USAGE
13
+ ${keyExamples}
14
+ `;
15
+
16
+ function run(cmdObj: CLICommandParser) {
17
+ const options = cmdObj.parseOptions({ params: ["--in"] });
18
+ if (cmdObj.help || options.args.length > 1) printUsageAndExit(usage);
19
+ const workspace = options.args[0];
20
+ const env = cmdObj.envForced ? cmdObj.env : "test";
21
+ if (workspace) {
22
+ new CommandExecutor(`devops run ${workspace}:test --env ${env}`).spawn();
23
+ } else {
24
+ new CommandExecutor(`devops run-many test --env ${env}`).spawn();
25
+ }
26
+ }
27
+
28
+ export default {
29
+ test: { oneLiner, keyExamples, run },
30
+ };