trigger.dev 0.0.0-v3-prerelease-20250108141813 → 0.0.0-v4-prerelease-20250916125920

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 (292) hide show
  1. package/README.md +28 -1
  2. package/dist/esm/apiClient.d.ts +158 -74
  3. package/dist/esm/apiClient.js +341 -76
  4. package/dist/esm/apiClient.js.map +1 -1
  5. package/dist/esm/build/buildWorker.d.ts +10 -6
  6. package/dist/esm/build/buildWorker.js +22 -38
  7. package/dist/esm/build/buildWorker.js.map +1 -1
  8. package/dist/esm/build/bundle.d.ts +18 -1
  9. package/dist/esm/build/bundle.js +142 -52
  10. package/dist/esm/build/bundle.js.map +1 -1
  11. package/dist/esm/build/entryPoints.d.ts +12 -0
  12. package/dist/esm/build/entryPoints.js +127 -0
  13. package/dist/esm/build/entryPoints.js.map +1 -0
  14. package/dist/esm/build/extensions.js +17 -0
  15. package/dist/esm/build/extensions.js.map +1 -1
  16. package/dist/esm/build/externals.js +184 -2
  17. package/dist/esm/build/externals.js.map +1 -1
  18. package/dist/esm/build/packageModules.d.ts +15 -5
  19. package/dist/esm/build/packageModules.js +154 -36
  20. package/dist/esm/build/packageModules.js.map +1 -1
  21. package/dist/esm/cli/common.d.ts +1 -1
  22. package/dist/esm/cli/common.js +38 -45
  23. package/dist/esm/cli/common.js.map +1 -1
  24. package/dist/esm/cli/index.js +19 -3
  25. package/dist/esm/cli/index.js.map +1 -1
  26. package/dist/esm/commands/analyze.d.ts +23 -0
  27. package/dist/esm/commands/analyze.js +122 -0
  28. package/dist/esm/commands/analyze.js.map +1 -0
  29. package/dist/esm/commands/deploy.d.ts +5 -2
  30. package/dist/esm/commands/deploy.js +271 -160
  31. package/dist/esm/commands/deploy.js.map +1 -1
  32. package/dist/esm/commands/dev.d.ts +36 -6
  33. package/dist/esm/commands/dev.js +71 -2
  34. package/dist/esm/commands/dev.js.map +1 -1
  35. package/dist/esm/commands/env.d.ts +2 -0
  36. package/dist/esm/commands/env.js +298 -0
  37. package/dist/esm/commands/env.js.map +1 -0
  38. package/dist/esm/commands/init.d.ts +9 -1
  39. package/dist/esm/commands/init.js +132 -65
  40. package/dist/esm/commands/init.js.map +1 -1
  41. package/dist/esm/commands/install-mcp.d.ts +50 -0
  42. package/dist/esm/commands/install-mcp.js +497 -0
  43. package/dist/esm/commands/install-mcp.js.map +1 -0
  44. package/dist/esm/commands/install-rules.d.ts +11 -0
  45. package/dist/esm/commands/install-rules.js +381 -0
  46. package/dist/esm/commands/install-rules.js.map +1 -0
  47. package/dist/esm/commands/list-profiles.d.ts +3 -7
  48. package/dist/esm/commands/list-profiles.js +7 -4
  49. package/dist/esm/commands/list-profiles.js.map +1 -1
  50. package/dist/esm/commands/login.d.ts +9 -5
  51. package/dist/esm/commands/login.js +40 -7
  52. package/dist/esm/commands/login.js.map +1 -1
  53. package/dist/esm/commands/logout.d.ts +1 -1
  54. package/dist/esm/commands/mcp.d.ts +38 -0
  55. package/dist/esm/commands/mcp.js +82 -0
  56. package/dist/esm/commands/mcp.js.map +1 -0
  57. package/dist/esm/commands/preview.d.ts +5 -0
  58. package/dist/esm/commands/preview.js +93 -0
  59. package/dist/esm/commands/preview.js.map +1 -0
  60. package/dist/esm/commands/promote.d.ts +3 -0
  61. package/dist/esm/commands/promote.js +86 -0
  62. package/dist/esm/commands/promote.js.map +1 -0
  63. package/dist/esm/commands/switch.d.ts +19 -0
  64. package/dist/esm/commands/switch.js +93 -0
  65. package/dist/esm/commands/switch.js.map +1 -0
  66. package/dist/esm/commands/trigger.d.ts +33 -0
  67. package/dist/esm/commands/trigger.js +88 -0
  68. package/dist/esm/commands/trigger.js.map +1 -0
  69. package/dist/esm/commands/update.d.ts +3 -2
  70. package/dist/esm/commands/update.js +23 -9
  71. package/dist/esm/commands/update.js.map +1 -1
  72. package/dist/esm/commands/whoami.d.ts +12 -1
  73. package/dist/esm/commands/whoami.js +36 -6
  74. package/dist/esm/commands/whoami.js.map +1 -1
  75. package/dist/esm/commands/workers/build.d.ts +4 -0
  76. package/dist/esm/commands/workers/build.js +345 -0
  77. package/dist/esm/commands/workers/build.js.map +1 -0
  78. package/dist/esm/commands/workers/create.d.ts +2 -0
  79. package/dist/esm/commands/workers/create.js +91 -0
  80. package/dist/esm/commands/workers/create.js.map +1 -0
  81. package/dist/esm/commands/workers/index.d.ts +2 -0
  82. package/dist/esm/commands/workers/index.js +13 -0
  83. package/dist/esm/commands/workers/index.js.map +1 -0
  84. package/dist/esm/commands/workers/list.d.ts +2 -0
  85. package/dist/esm/commands/workers/list.js +80 -0
  86. package/dist/esm/commands/workers/list.js.map +1 -0
  87. package/dist/esm/commands/workers/run.d.ts +2 -0
  88. package/dist/esm/commands/workers/run.js +105 -0
  89. package/dist/esm/commands/workers/run.js.map +1 -0
  90. package/dist/esm/config.d.ts +2 -1
  91. package/dist/esm/config.js +35 -8
  92. package/dist/esm/config.js.map +1 -1
  93. package/dist/esm/deploy/buildImage.d.ts +12 -11
  94. package/dist/esm/deploy/buildImage.js +360 -115
  95. package/dist/esm/deploy/buildImage.js.map +1 -1
  96. package/dist/esm/dev/backgroundWorker.d.ts +6 -245
  97. package/dist/esm/dev/backgroundWorker.js +11 -320
  98. package/dist/esm/dev/backgroundWorker.js.map +1 -1
  99. package/dist/esm/dev/devOutput.js +48 -9
  100. package/dist/esm/dev/devOutput.js.map +1 -1
  101. package/dist/esm/dev/devSession.d.ts +2 -1
  102. package/dist/esm/dev/devSession.js +68 -65
  103. package/dist/esm/dev/devSession.js.map +1 -1
  104. package/dist/esm/dev/devSupervisor.d.ts +12 -0
  105. package/dist/esm/dev/devSupervisor.js +568 -0
  106. package/dist/esm/dev/devSupervisor.js.map +1 -0
  107. package/dist/esm/dev/lock.d.ts +1 -0
  108. package/dist/esm/dev/lock.js +80 -0
  109. package/dist/esm/dev/lock.js.map +1 -0
  110. package/dist/esm/dev/mcpServer.d.ts +10 -0
  111. package/dist/esm/dev/mcpServer.js +201 -0
  112. package/dist/esm/dev/mcpServer.js.map +1 -0
  113. package/dist/esm/dev/taskRunProcessPool.d.ts +39 -0
  114. package/dist/esm/dev/taskRunProcessPool.js +220 -0
  115. package/dist/esm/dev/taskRunProcessPool.js.map +1 -0
  116. package/dist/esm/dev/workerRuntime.d.ts +2 -2
  117. package/dist/esm/dev/workerRuntime.js +1 -265
  118. package/dist/esm/dev/workerRuntime.js.map +1 -1
  119. package/dist/esm/entryPoints/dev-index-worker.js +45 -8
  120. package/dist/esm/entryPoints/dev-index-worker.js.map +1 -1
  121. package/dist/esm/entryPoints/dev-run-controller.d.ts +58 -0
  122. package/dist/esm/entryPoints/dev-run-controller.js +652 -0
  123. package/dist/esm/entryPoints/dev-run-controller.js.map +1 -0
  124. package/dist/esm/entryPoints/dev-run-worker.js +394 -199
  125. package/dist/esm/entryPoints/dev-run-worker.js.map +1 -1
  126. package/dist/esm/entryPoints/managed/controller.d.ts +63 -0
  127. package/dist/esm/entryPoints/managed/controller.js +482 -0
  128. package/dist/esm/entryPoints/managed/controller.js.map +1 -0
  129. package/dist/esm/entryPoints/managed/env.d.ts +170 -0
  130. package/dist/esm/entryPoints/managed/env.js +199 -0
  131. package/dist/esm/entryPoints/managed/env.js.map +1 -0
  132. package/dist/esm/entryPoints/managed/execution.d.ts +141 -0
  133. package/dist/esm/entryPoints/managed/execution.js +869 -0
  134. package/dist/esm/entryPoints/managed/execution.js.map +1 -0
  135. package/dist/esm/entryPoints/managed/logger.d.ts +30 -0
  136. package/dist/esm/entryPoints/managed/logger.js +47 -0
  137. package/dist/esm/entryPoints/managed/logger.js.map +1 -0
  138. package/dist/esm/entryPoints/managed/notifier.d.ts +30 -0
  139. package/dist/esm/entryPoints/managed/notifier.js +63 -0
  140. package/dist/esm/entryPoints/managed/notifier.js.map +1 -0
  141. package/dist/esm/entryPoints/managed/overrides.d.ts +18 -0
  142. package/dist/esm/entryPoints/managed/overrides.js +19 -0
  143. package/dist/esm/entryPoints/managed/overrides.js.map +1 -0
  144. package/dist/esm/entryPoints/managed/poller.d.ts +31 -0
  145. package/dist/esm/entryPoints/managed/poller.js +89 -0
  146. package/dist/esm/entryPoints/managed/poller.js.map +1 -0
  147. package/dist/esm/entryPoints/managed/snapshot.d.ts +54 -0
  148. package/dist/esm/entryPoints/managed/snapshot.js +293 -0
  149. package/dist/esm/entryPoints/managed/snapshot.js.map +1 -0
  150. package/dist/esm/entryPoints/managed/taskRunProcessProvider.d.ts +62 -0
  151. package/dist/esm/entryPoints/managed/taskRunProcessProvider.js +252 -0
  152. package/dist/esm/entryPoints/managed/taskRunProcessProvider.js.map +1 -0
  153. package/dist/esm/entryPoints/{deploy-index-controller.js → managed-index-controller.js} +27 -3
  154. package/dist/esm/entryPoints/managed-index-controller.js.map +1 -0
  155. package/dist/esm/entryPoints/{deploy-index-worker.js → managed-index-worker.js} +50 -21
  156. package/dist/esm/entryPoints/managed-index-worker.js.map +1 -0
  157. package/dist/esm/entryPoints/managed-run-controller.js +13 -0
  158. package/dist/esm/entryPoints/managed-run-controller.js.map +1 -0
  159. package/dist/esm/entryPoints/managed-run-worker.js +512 -0
  160. package/dist/esm/entryPoints/managed-run-worker.js.map +1 -0
  161. package/dist/esm/executions/taskRunProcess.d.ts +28 -82
  162. package/dist/esm/executions/taskRunProcess.js +130 -74
  163. package/dist/esm/executions/taskRunProcess.js.map +1 -1
  164. package/dist/esm/indexing/indexWorkerManifest.d.ts +21 -5
  165. package/dist/esm/indexing/indexWorkerManifest.js +4 -4
  166. package/dist/esm/indexing/indexWorkerManifest.js.map +1 -1
  167. package/dist/esm/indexing/registerResources.d.ts +5 -0
  168. package/dist/esm/indexing/registerResources.js +44 -0
  169. package/dist/esm/indexing/registerResources.js.map +1 -0
  170. package/dist/esm/mcp/auth.d.ts +12 -0
  171. package/dist/esm/mcp/auth.js +152 -0
  172. package/dist/esm/mcp/auth.js.map +1 -0
  173. package/dist/esm/mcp/capabilities.d.ts +4 -0
  174. package/dist/esm/mcp/capabilities.js +22 -0
  175. package/dist/esm/mcp/capabilities.js.map +1 -0
  176. package/dist/esm/mcp/config.d.ts +82 -0
  177. package/dist/esm/mcp/config.js +87 -0
  178. package/dist/esm/mcp/config.js.map +1 -0
  179. package/dist/esm/mcp/context.d.ts +45 -0
  180. package/dist/esm/mcp/context.js +129 -0
  181. package/dist/esm/mcp/context.js.map +1 -0
  182. package/dist/esm/mcp/formatters.d.ts +7 -0
  183. package/dist/esm/mcp/formatters.js +330 -0
  184. package/dist/esm/mcp/formatters.js.map +1 -0
  185. package/dist/esm/mcp/logger.d.ts +11 -0
  186. package/dist/esm/mcp/logger.js +34 -0
  187. package/dist/esm/mcp/logger.js.map +1 -0
  188. package/dist/esm/mcp/mintlifyClient.d.ts +1 -0
  189. package/dist/esm/mcp/mintlifyClient.js +65 -0
  190. package/dist/esm/mcp/mintlifyClient.js.map +1 -0
  191. package/dist/esm/mcp/schemas.d.ts +324 -0
  192. package/dist/esm/mcp/schemas.js +144 -0
  193. package/dist/esm/mcp/schemas.js.map +1 -0
  194. package/dist/esm/mcp/tools/deploys.d.ts +174 -0
  195. package/dist/esm/mcp/tools/deploys.js +161 -0
  196. package/dist/esm/mcp/tools/deploys.js.map +1 -0
  197. package/dist/esm/mcp/tools/docs.d.ts +77 -0
  198. package/dist/esm/mcp/tools/docs.js +18 -0
  199. package/dist/esm/mcp/tools/docs.js.map +1 -0
  200. package/dist/esm/mcp/tools/orgs.d.ts +172 -0
  201. package/dist/esm/mcp/tools/orgs.js +172 -0
  202. package/dist/esm/mcp/tools/orgs.js.map +1 -0
  203. package/dist/esm/mcp/tools/previewBranches.d.ts +78 -0
  204. package/dist/esm/mcp/tools/previewBranches.js +28 -0
  205. package/dist/esm/mcp/tools/previewBranches.js.map +1 -0
  206. package/dist/esm/mcp/tools/runs.d.ts +335 -0
  207. package/dist/esm/mcp/tools/runs.js +160 -0
  208. package/dist/esm/mcp/tools/runs.js.map +1 -0
  209. package/dist/esm/mcp/tools/tasks.d.ts +200 -0
  210. package/dist/esm/mcp/tools/tasks.js +117 -0
  211. package/dist/esm/mcp/tools/tasks.js.map +1 -0
  212. package/dist/esm/mcp/tools.d.ts +2 -0
  213. package/dist/esm/mcp/tools.js +40 -0
  214. package/dist/esm/mcp/tools.js.map +1 -0
  215. package/dist/esm/mcp/types.d.ts +6 -0
  216. package/dist/esm/mcp/types.js +2 -0
  217. package/dist/esm/mcp/types.js.map +1 -0
  218. package/dist/esm/mcp/utils.d.ts +89 -0
  219. package/dist/esm/mcp/utils.js +95 -0
  220. package/dist/esm/mcp/utils.js.map +1 -0
  221. package/dist/esm/rules/install.d.ts +1 -0
  222. package/dist/esm/rules/install.js +2 -0
  223. package/dist/esm/rules/install.js.map +1 -0
  224. package/dist/esm/rules/manifest.d.ts +145 -0
  225. package/dist/esm/rules/manifest.js +110 -0
  226. package/dist/esm/rules/manifest.js.map +1 -0
  227. package/dist/esm/rules/types.d.ts +3 -0
  228. package/dist/esm/rules/types.js +3 -0
  229. package/dist/esm/rules/types.js.map +1 -0
  230. package/dist/esm/utilities/accessTokens.d.ts +12 -0
  231. package/dist/esm/utilities/accessTokens.js +30 -0
  232. package/dist/esm/utilities/accessTokens.js.map +1 -0
  233. package/dist/esm/utilities/analyze.d.ts +13 -0
  234. package/dist/esm/utilities/analyze.js +463 -0
  235. package/dist/esm/utilities/analyze.js.map +1 -0
  236. package/dist/esm/utilities/cliOutput.d.ts +6 -1
  237. package/dist/esm/utilities/cliOutput.js +11 -2
  238. package/dist/esm/utilities/cliOutput.js.map +1 -1
  239. package/dist/esm/utilities/configFiles.d.ts +65 -15
  240. package/dist/esm/utilities/configFiles.js +124 -26
  241. package/dist/esm/utilities/configFiles.js.map +1 -1
  242. package/dist/esm/utilities/eventBus.d.ts +7 -3
  243. package/dist/esm/utilities/eventBus.js.map +1 -1
  244. package/dist/esm/utilities/fileSystem.d.ts +7 -1
  245. package/dist/esm/utilities/fileSystem.js +42 -4
  246. package/dist/esm/utilities/fileSystem.js.map +1 -1
  247. package/dist/esm/utilities/gitMeta.d.ts +2 -0
  248. package/dist/esm/utilities/gitMeta.js +220 -0
  249. package/dist/esm/utilities/gitMeta.js.map +1 -0
  250. package/dist/esm/utilities/githubActions.d.ts +4 -0
  251. package/dist/esm/utilities/githubActions.js +18 -0
  252. package/dist/esm/utilities/githubActions.js.map +1 -0
  253. package/dist/esm/utilities/initialBanner.js +18 -6
  254. package/dist/esm/utilities/initialBanner.js.map +1 -1
  255. package/dist/esm/utilities/localEnvVars.d.ts +3 -0
  256. package/dist/esm/utilities/localEnvVars.js +19 -0
  257. package/dist/esm/utilities/localEnvVars.js.map +1 -0
  258. package/dist/esm/utilities/sanitizeEnvVars.d.ts +16 -3
  259. package/dist/esm/utilities/sanitizeEnvVars.js +15 -0
  260. package/dist/esm/utilities/sanitizeEnvVars.js.map +1 -1
  261. package/dist/esm/utilities/session.d.ts +14 -0
  262. package/dist/esm/utilities/session.js +44 -47
  263. package/dist/esm/utilities/session.js.map +1 -1
  264. package/dist/esm/utilities/supportsHyperlinks.d.ts +15 -0
  265. package/dist/esm/utilities/supportsHyperlinks.js +122 -0
  266. package/dist/esm/utilities/supportsHyperlinks.js.map +1 -0
  267. package/dist/esm/utilities/tempDirectories.d.ts +1 -0
  268. package/dist/esm/utilities/tempDirectories.js +19 -2
  269. package/dist/esm/utilities/tempDirectories.js.map +1 -1
  270. package/dist/esm/utilities/terminalLink.d.ts +56 -0
  271. package/dist/esm/utilities/terminalLink.js +76 -0
  272. package/dist/esm/utilities/terminalLink.js.map +1 -0
  273. package/dist/esm/utilities/windows.js +51 -1
  274. package/dist/esm/utilities/windows.js.map +1 -1
  275. package/dist/esm/version.js +1 -1
  276. package/package.json +44 -25
  277. package/dist/esm/entryPoints/deploy-index-controller.js.map +0 -1
  278. package/dist/esm/entryPoints/deploy-index-worker.js.map +0 -1
  279. package/dist/esm/entryPoints/deploy-run-controller.js +0 -1099
  280. package/dist/esm/entryPoints/deploy-run-controller.js.map +0 -1
  281. package/dist/esm/entryPoints/deploy-run-worker.js +0 -366
  282. package/dist/esm/entryPoints/deploy-run-worker.js.map +0 -1
  283. package/dist/esm/indexing/registerTasks.d.ts +0 -2
  284. package/dist/esm/indexing/registerTasks.js +0 -62
  285. package/dist/esm/indexing/registerTasks.js.map +0 -1
  286. package/dist/esm/telemetry/tracing.d.ts +0 -3
  287. package/dist/esm/telemetry/tracing.js +0 -58
  288. package/dist/esm/telemetry/tracing.js.map +0 -1
  289. /package/dist/esm/entryPoints/{deploy-index-controller.d.ts → managed-index-controller.d.ts} +0 -0
  290. /package/dist/esm/entryPoints/{deploy-index-worker.d.ts → managed-index-worker.d.ts} +0 -0
  291. /package/dist/esm/entryPoints/{deploy-run-controller.d.ts → managed-run-controller.d.ts} +0 -0
  292. /package/dist/esm/entryPoints/{deploy-run-worker.d.ts → managed-run-worker.d.ts} +0 -0
@@ -1,77 +1,77 @@
1
- import { intro, outro } from "@clack/prompts";
2
- import { prepareDeploymentError } from "@trigger.dev/core/v3";
1
+ import { intro, log, outro } from "@clack/prompts";
2
+ import { getBranch, prepareDeploymentError, tryCatch } from "@trigger.dev/core/v3";
3
3
  import { Option as CommandOption } from "commander";
4
- import { writeFile } from "node:fs/promises";
5
- import { join, relative, resolve } from "node:path";
6
- import { readPackageJSON, writePackageJSON } from "pkg-types";
4
+ import { resolve } from "node:path";
5
+ import { isCI } from "std-env";
6
+ import { x } from "tinyexec";
7
7
  import { z } from "zod";
8
8
  import { buildWorker } from "../build/buildWorker.js";
9
+ import { resolveAlwaysExternal } from "../build/externals.js";
9
10
  import { CommonCommandOptions, commonOptions, handleTelemetry, SkipLoggingError, wrapCommandAction, } from "../cli/common.js";
10
11
  import { loadConfig } from "../config.js";
11
- import { buildImage, generateContainerfile } from "../deploy/buildImage.js";
12
+ import { buildImage } from "../deploy/buildImage.js";
12
13
  import { checkLogsForErrors, checkLogsForWarnings, printErrors, printWarnings, saveLogs, } from "../deploy/logs.js";
13
- import { buildManifestToJSON } from "../utilities/buildManifest.js";
14
14
  import { chalkError, cliLink, isLinksSupported, prettyError } from "../utilities/cliOutput.js";
15
15
  import { loadDotEnvVars } from "../utilities/dotEnv.js";
16
- import { writeJSONFile } from "../utilities/fileSystem.js";
16
+ import { isDirectory } from "../utilities/fileSystem.js";
17
+ import { setGithubActionsOutputAndEnvVars } from "../utilities/githubActions.js";
18
+ import { createGitMeta } from "../utilities/gitMeta.js";
17
19
  import { printStandloneInitialBanner } from "../utilities/initialBanner.js";
20
+ import { resolveLocalEnvVars } from "../utilities/localEnvVars.js";
18
21
  import { logger } from "../utilities/logger.js";
19
- import { getProjectClient } from "../utilities/session.js";
22
+ import { getProjectClient, upsertBranch } from "../utilities/session.js";
20
23
  import { getTmpDir } from "../utilities/tempDirectories.js";
21
24
  import { spinner } from "../utilities/windows.js";
22
25
  import { login } from "./login.js";
26
+ import { archivePreviewBranch } from "./preview.js";
23
27
  import { updateTriggerPackages } from "./update.js";
24
- import { resolveAlwaysExternal } from "../build/externals.js";
25
- import { x } from "tinyexec";
26
28
  const DeployCommandOptions = CommonCommandOptions.extend({
27
29
  dryRun: z.boolean().default(false),
28
30
  skipSyncEnvVars: z.boolean().default(false),
29
- env: z.enum(["prod", "staging"]),
30
- loadImage: z.boolean().default(false),
31
- buildPlatform: z.enum(["linux/amd64", "linux/arm64"]).default("linux/amd64"),
32
- namespace: z.string().optional(),
33
- selfHosted: z.boolean().default(false),
34
- registry: z.string().optional(),
35
- push: z.boolean().default(false),
31
+ env: z.enum(["prod", "staging", "preview", "production"]),
32
+ branch: z.string().optional(),
33
+ load: z.boolean().optional(),
36
34
  config: z.string().optional(),
37
35
  projectRef: z.string().optional(),
38
- apiUrl: z.string().optional(),
39
36
  saveLogs: z.boolean().default(false),
40
37
  skipUpdateCheck: z.boolean().default(false),
38
+ skipPromotion: z.boolean().default(false),
41
39
  noCache: z.boolean().default(false),
42
40
  envFile: z.string().optional(),
41
+ // Local build options
43
42
  network: z.enum(["default", "none", "host"]).optional(),
43
+ push: z.boolean().optional(),
44
+ builder: z.string().default("trigger"),
44
45
  });
45
46
  export function configureDeployCommand(program) {
46
- return commonOptions(program
47
+ return (commonOptions(program
47
48
  .command("deploy")
48
- .description("Deploy your Trigger.dev v3 project to the cloud.")
49
+ .description("Deploy your Trigger.dev project to the cloud.")
49
50
  .argument("[path]", "The path to the project", ".")
50
51
  .option("-e, --env <env>", "Deploy to a specific environment (currently only prod and staging are supported)", "prod")
52
+ .option("-b, --branch <branch>", "The preview branch to deploy to when passing --env preview. If not provided, we'll detect your git branch.")
51
53
  .option("--skip-update-check", "Skip checking for @trigger.dev package updates")
52
54
  .option("-c, --config <config file>", "The name of the config file, found at [path]")
53
55
  .option("-p, --project-ref <project ref>", "The project ref. Required if there is no config file. This will override the project specified in the config file.")
54
56
  .option("--dry-run", "Do a dry run of the deployment. This will not actually deploy the project, but will show you what would be deployed.")
55
57
  .option("--skip-sync-env-vars", "Skip syncing environment variables when using the syncEnvVars extension.")
56
- .option("--env-file <env file>", "Path to the .env file to load into the CLI process. Defaults to .env in the project directory."))
57
- .addOption(new CommandOption("--self-hosted", "Build and load the image using your local Docker. Use the --registry option to specify the registry to push the image to when using --self-hosted, or just use --push to push to the default registry.").hideHelp())
58
+ .option("--env-file <env file>", "Path to the .env file to load into the CLI process. Defaults to .env in the project directory.")
59
+ .option("--skip-promotion", "Skip promoting the deployment to the current deployment for the environment."))
58
60
  .addOption(new CommandOption("--no-cache", "Do not use the cache when building the image. This will slow down the build process but can be useful if you are experiencing issues with the cache.").hideHelp())
59
- .addOption(new CommandOption("--push", "When using the --self-hosted flag, push the image to the default registry. (defaults to false when not using --registry)").hideHelp())
60
- .addOption(new CommandOption("--registry <registry>", "The registry to push the image to when using --self-hosted").hideHelp())
61
- .addOption(new CommandOption("--tag <tag>", "(Coming soon) Specify the tag to use when pushing the image to the registry").hideHelp())
62
- .addOption(new CommandOption("--namespace <namespace>", "Specify the namespace to use when pushing the image to the registry").hideHelp())
63
- .addOption(new CommandOption("--load-image", "Load the built image into your local docker").hideHelp())
64
- .addOption(new CommandOption("--build-platform <platform>", "The platform to build the deployment image for")
65
- .default("linux/amd64")
66
- .hideHelp())
61
+ .addOption(new CommandOption("--load", "Load the built image into your local docker").hideHelp())
62
+ .addOption(new CommandOption("--no-load", "Do not load the built image into your local docker").hideHelp())
67
63
  .addOption(new CommandOption("--save-logs", "If provided, will save logs even for successful builds").hideHelp())
68
- .option("--network <mode>", "The networking mode for RUN instructions when using --self-hosted")
64
+ // Local build options
65
+ .addOption(new CommandOption("--push", "Push the image after local builds").hideHelp())
66
+ .addOption(new CommandOption("--no-push", "Do not push the image after local builds").hideHelp())
67
+ .addOption(new CommandOption("--network <mode>", "The networking mode for RUN instructions when building locally").hideHelp())
68
+ .addOption(new CommandOption("--builder <builder>", "The builder to use when building locally").hideHelp())
69
69
  .action(async (path, options) => {
70
70
  await handleTelemetry(async () => {
71
71
  await printStandloneInitialBanner(true);
72
72
  await deployCommand(path, options);
73
73
  });
74
- });
74
+ }));
75
75
  }
76
76
  export async function deployCommand(dir, options) {
77
77
  return await wrapCommandAction("deployCommand", DeployCommandOptions, options, async (opts) => {
@@ -79,11 +79,13 @@ export async function deployCommand(dir, options) {
79
79
  });
80
80
  }
81
81
  async function _deployCommand(dir, options) {
82
- intro("Deploying project");
82
+ intro(`Deploying project${options.skipPromotion ? " (without promotion)" : ""}`);
83
83
  if (!options.skipUpdateCheck) {
84
84
  await updateTriggerPackages(dir, { ...options }, true, true);
85
85
  }
86
- const projectPath = resolve(process.cwd(), dir);
86
+ const cwd = process.cwd();
87
+ const projectPath = resolve(cwd, dir);
88
+ verifyDirectory(dir, projectPath);
87
89
  const authorization = await login({
88
90
  embedded: true,
89
91
  defaultApiUrl: options.apiUrl,
@@ -97,17 +99,56 @@ async function _deployCommand(dir, options) {
97
99
  throw new Error(`You must login first. Use the \`login\` CLI command.\n\n${authorization.error}`);
98
100
  }
99
101
  }
102
+ //coerce env from production to prod
103
+ if (options.env === "production") {
104
+ options.env = "prod";
105
+ }
106
+ const envVars = resolveLocalEnvVars(options.envFile);
107
+ if (envVars.TRIGGER_PROJECT_REF) {
108
+ logger.debug("Using project ref from env", { ref: envVars.TRIGGER_PROJECT_REF });
109
+ }
100
110
  const resolvedConfig = await loadConfig({
101
111
  cwd: projectPath,
102
- overrides: { project: options.projectRef },
112
+ overrides: { project: options.projectRef ?? envVars.TRIGGER_PROJECT_REF },
103
113
  configFile: options.config,
104
114
  });
105
115
  logger.debug("Resolved config", resolvedConfig);
116
+ const gitMeta = await createGitMeta(resolvedConfig.workspaceDir);
117
+ logger.debug("gitMeta", gitMeta);
118
+ const branch = options.env === "preview" ? getBranch({ specified: options.branch, gitMeta }) : undefined;
119
+ if (options.env === "preview" && !branch) {
120
+ throw new Error("Didn't auto-detect preview branch, so you need to specify one. Pass --branch <branch>.");
121
+ }
122
+ if (options.env === "preview" && branch) {
123
+ //auto-archive a branch if the PR is merged or closed
124
+ if (gitMeta?.pullRequestState === "merged" || gitMeta?.pullRequestState === "closed") {
125
+ log.message(`Pull request ${gitMeta?.pullRequestNumber} is ${gitMeta?.pullRequestState}.`);
126
+ const $buildSpinner = spinner();
127
+ $buildSpinner.start(`Archiving preview branch: "${branch}"`);
128
+ const result = await archivePreviewBranch(authorization, branch, resolvedConfig.project);
129
+ $buildSpinner.stop(result ? `Successfully archived "${branch}"` : `Failed to archive "${branch}".`);
130
+ return;
131
+ }
132
+ logger.debug("Upserting branch", { env: options.env, branch });
133
+ const branchEnv = await upsertBranch({
134
+ accessToken: authorization.auth.accessToken,
135
+ apiUrl: authorization.auth.apiUrl,
136
+ projectRef: resolvedConfig.project,
137
+ branch,
138
+ gitMeta,
139
+ });
140
+ logger.debug("Upserted branch env", branchEnv);
141
+ log.success(`Using preview branch "${branch}"`);
142
+ if (!branchEnv) {
143
+ throw new Error(`Failed to create branch "${branch}"`);
144
+ }
145
+ }
106
146
  const projectClient = await getProjectClient({
107
147
  accessToken: authorization.auth.accessToken,
108
148
  apiUrl: authorization.auth.apiUrl,
109
149
  projectRef: resolvedConfig.project,
110
150
  env: options.env,
151
+ branch,
111
152
  profile: options.profile,
112
153
  });
113
154
  if (!projectClient) {
@@ -118,9 +159,11 @@ async function _deployCommand(dir, options) {
118
159
  const destination = getTmpDir(resolvedConfig.workingDir, "build", options.dryRun);
119
160
  const $buildSpinner = spinner();
120
161
  const forcedExternals = await resolveAlwaysExternal(projectClient.client);
121
- const buildManifest = await buildWorker({
162
+ const { features } = resolvedConfig;
163
+ const [error, buildManifest] = await tryCatch(buildWorker({
122
164
  target: "deploy",
123
165
  environment: options.env,
166
+ branch,
124
167
  destination: destination.path,
125
168
  resolvedConfig,
126
169
  rewritePaths: true,
@@ -128,55 +171,55 @@ async function _deployCommand(dir, options) {
128
171
  forcedExternals,
129
172
  listener: {
130
173
  onBundleStart() {
131
- $buildSpinner.start("Building project");
174
+ $buildSpinner.start("Building trigger code");
132
175
  },
133
176
  onBundleComplete(result) {
134
- $buildSpinner.stop("Successfully built project");
177
+ $buildSpinner.stop("Successfully built code");
135
178
  logger.debug("Bundle result", result);
136
179
  },
137
180
  },
138
- });
181
+ }));
182
+ if (error) {
183
+ $buildSpinner.stop("Failed to build code");
184
+ throw error;
185
+ }
139
186
  logger.debug("Successfully built project to", destination.path);
140
187
  if (options.dryRun) {
141
188
  logger.info(`Dry run complete. View the built project at ${destination.path}`);
142
189
  return;
143
190
  }
144
- const deploymentResponse = await projectClient.client.initializeDeployment({
191
+ const deployment = await initializeOrAttachDeployment(projectClient.client, {
145
192
  contentHash: buildManifest.contentHash,
146
- userId: authorization.userId,
147
- selfHosted: options.selfHosted,
148
- registryHost: options.registry,
149
- namespace: options.namespace,
150
- });
151
- if (!deploymentResponse.success) {
152
- throw new Error(`Failed to start deployment: ${deploymentResponse.error}`);
153
- }
154
- const deployment = deploymentResponse.data;
155
- // If the deployment doesn't have any externalBuildData, then we can't use the remote image builder
156
- // TODO: handle this and allow the user to the build and push the image themselves
157
- if (!deployment.externalBuildData && !options.selfHosted) {
158
- throw new Error(`Failed to start deployment, as your instance of trigger.dev does not support hosting. To deploy this project, you must use the --self-hosted flag to build and push the image yourself.`);
159
- }
160
- if (options.selfHosted) {
193
+ userId: authorization.auth.tokenType === "personal" ? authorization.userId : undefined,
194
+ gitMeta,
195
+ type: features.run_engine_v2 ? "MANAGED" : "V1",
196
+ runtime: buildManifest.runtime,
197
+ }, envVars.TRIGGER_EXISTING_DEPLOYMENT_ID);
198
+ const isLocalBuild = !deployment.externalBuildData;
199
+ // Fail fast if we know local builds will fail
200
+ if (isLocalBuild) {
161
201
  const result = await x("docker", ["buildx", "version"]);
162
202
  if (result.exitCode !== 0) {
163
203
  logger.debug(`"docker buildx version" failed (${result.exitCode}):`, result);
164
204
  throw new Error("Failed to find docker buildx. Please install it: https://github.com/docker/buildx#installing.");
165
205
  }
166
206
  }
167
- if (buildManifest.deploy.sync &&
168
- buildManifest.deploy.sync.env &&
169
- Object.keys(buildManifest.deploy.sync.env).length > 0) {
170
- const numberOfEnvVars = Object.keys(buildManifest.deploy.sync.env).length;
207
+ const hasVarsToSync = Object.keys(buildManifest.deploy.sync?.env || {}).length > 0 ||
208
+ // Only sync parent variables if this is a branch environment
209
+ (branch && Object.keys(buildManifest.deploy.sync?.parentEnv || {}).length > 0);
210
+ if (hasVarsToSync) {
211
+ const childVars = buildManifest.deploy.sync?.env ?? {};
212
+ const parentVars = buildManifest.deploy.sync?.parentEnv ?? {};
213
+ const numberOfEnvVars = Object.keys(childVars).length + Object.keys(parentVars).length;
171
214
  const vars = numberOfEnvVars === 1 ? "var" : "vars";
172
215
  if (!options.skipSyncEnvVars) {
173
216
  const $spinner = spinner();
174
217
  $spinner.start(`Syncing ${numberOfEnvVars} env ${vars} with the server`);
175
- const success = await syncEnvVarsWithServer(projectClient.client, resolvedConfig.project, options.env, buildManifest.deploy.sync.env);
176
- if (!success) {
218
+ const uploadResult = await syncEnvVarsWithServer(projectClient.client, resolvedConfig.project, options.env, childVars, parentVars);
219
+ if (!uploadResult.success) {
177
220
  await failDeploy(projectClient.client, deployment, {
178
221
  name: "SyncEnvVarsError",
179
- message: `Failed to sync ${numberOfEnvVars} env ${vars} with the server`,
222
+ message: `Failed to sync ${numberOfEnvVars} env ${vars} with the server: ${uploadResult.error}`,
180
223
  }, "", $spinner);
181
224
  }
182
225
  else {
@@ -188,28 +231,32 @@ async function _deployCommand(dir, options) {
188
231
  }
189
232
  }
190
233
  const version = deployment.version;
191
- const deploymentLink = cliLink("View deployment", `${authorization.dashboardUrl}/projects/v3/${resolvedConfig.project}/deployments/${deployment.shortCode}`);
192
- const testLink = cliLink("Test tasks", `${authorization.dashboardUrl}/projects/v3/${resolvedConfig.project}/test?environment=${options.env === "prod" ? "prod" : "stg"}`);
234
+ const rawDeploymentLink = `${authorization.dashboardUrl}/projects/v3/${resolvedConfig.project}/deployments/${deployment.shortCode}`;
235
+ const rawTestLink = `${authorization.dashboardUrl}/projects/v3/${resolvedConfig.project}/test?environment=${options.env === "prod" ? "prod" : "stg"}`;
236
+ const deploymentLink = cliLink("View deployment", rawDeploymentLink);
237
+ const testLink = cliLink("Test tasks", rawTestLink);
193
238
  const $spinner = spinner();
194
- if (isLinksSupported) {
195
- $spinner.start(`Deploying version ${version} ${deploymentLink}`);
239
+ const buildSuffix = isLocalBuild ? " (local)" : "";
240
+ const deploySuffix = isLocalBuild ? " (local build)" : "";
241
+ if (isCI) {
242
+ log.step(`Building version ${version}\n`);
196
243
  }
197
244
  else {
198
- $spinner.start(`Deploying version ${version}`);
245
+ if (isLinksSupported) {
246
+ $spinner.start(`Building version ${version}${buildSuffix} ${deploymentLink}`);
247
+ }
248
+ else {
249
+ $spinner.start(`Building version ${version}${buildSuffix}`);
250
+ }
199
251
  }
200
- const selfHostedRegistryHost = deployment.registryHost ?? options.registry;
201
- const registryHost = selfHostedRegistryHost ?? "registry.trigger.dev";
202
252
  const buildResult = await buildImage({
203
- selfHosted: options.selfHosted,
204
- buildPlatform: options.buildPlatform,
253
+ isLocalBuild,
205
254
  noCache: options.noCache,
206
- push: options.push,
207
- registryHost,
208
- registry: options.registry,
209
255
  deploymentId: deployment.id,
210
256
  deploymentVersion: deployment.version,
211
257
  imageTag: deployment.imageTag,
212
- loadImage: options.loadImage,
258
+ imagePlatform: deployment.imagePlatform,
259
+ load: options.load,
213
260
  contentHash: deployment.contentHash,
214
261
  externalBuildId: deployment.externalBuildData?.buildId,
215
262
  externalBuildToken: deployment.externalBuildData?.buildToken,
@@ -218,10 +265,26 @@ async function _deployCommand(dir, options) {
218
265
  projectRef: resolvedConfig.project,
219
266
  apiUrl: projectClient.client.apiURL,
220
267
  apiKey: projectClient.client.accessToken,
268
+ branchName: branch,
221
269
  authAccessToken: authorization.auth.accessToken,
222
270
  compilationPath: destination.path,
223
271
  buildEnvVars: buildManifest.build.env,
272
+ onLog: (logMessage) => {
273
+ if (isCI) {
274
+ console.log(logMessage);
275
+ return;
276
+ }
277
+ if (isLinksSupported) {
278
+ $spinner.message(`Building version ${version}${buildSuffix} ${deploymentLink}: ${logMessage}`);
279
+ }
280
+ else {
281
+ $spinner.message(`Building version ${version}${buildSuffix}: ${logMessage}`);
282
+ }
283
+ },
284
+ // Local build options
224
285
  network: options.network,
286
+ builder: options.builder,
287
+ push: options.push,
225
288
  });
226
289
  logger.debug("Build result", buildResult);
227
290
  const warnings = checkLogsForWarnings(buildResult.logs);
@@ -236,109 +299,95 @@ async function _deployCommand(dir, options) {
236
299
  const getDeploymentResponse = await projectClient.client.getDeployment(deployment.id);
237
300
  if (!getDeploymentResponse.success) {
238
301
  await failDeploy(projectClient.client, deployment, { name: "DeploymentError", message: getDeploymentResponse.error }, buildResult.logs, $spinner);
239
- throw new SkipLoggingError("Failed to get deployment with worker");
302
+ throw new SkipLoggingError(getDeploymentResponse.error);
240
303
  }
241
304
  const deploymentWithWorker = getDeploymentResponse.data;
242
305
  if (!deploymentWithWorker.worker) {
243
- await failDeploy(projectClient.client, deployment, { name: "DeploymentError", message: "Failed to get deployment with worker" }, buildResult.logs, $spinner);
244
- throw new SkipLoggingError("Failed to get deployment with worker");
306
+ const errorData = deploymentWithWorker.errorData
307
+ ? prepareDeploymentError(deploymentWithWorker.errorData)
308
+ : undefined;
309
+ await failDeploy(projectClient.client, deployment, {
310
+ name: "DeploymentError",
311
+ message: errorData?.message ?? "Failed to get deployment with worker",
312
+ }, buildResult.logs, $spinner);
313
+ throw new SkipLoggingError(errorData?.message ?? "Failed to get deployment with worker");
314
+ }
315
+ if (isCI) {
316
+ log.step(`Deploying version ${version}${deploySuffix}\n`);
317
+ }
318
+ else {
319
+ if (isLinksSupported) {
320
+ $spinner.message(`Deploying version ${version}${deploySuffix} ${deploymentLink}`);
321
+ }
322
+ else {
323
+ $spinner.message(`Deploying version ${version}${deploySuffix}`);
324
+ }
245
325
  }
246
- const imageReference = options.selfHosted
247
- ? `${selfHostedRegistryHost ? `${selfHostedRegistryHost}/` : ""}${buildResult.image}${buildResult.digest ? `@${buildResult.digest}` : ""}`
248
- : `${registryHost}/${buildResult.image}${buildResult.digest ? `@${buildResult.digest}` : ""}`;
249
326
  const finalizeResponse = await projectClient.client.finalizeDeployment(deployment.id, {
250
- imageReference,
251
- selfHosted: options.selfHosted,
327
+ imageDigest: buildResult.digest,
328
+ skipPromotion: options.skipPromotion,
329
+ }, (logMessage) => {
330
+ if (isCI) {
331
+ console.log(logMessage);
332
+ return;
333
+ }
334
+ if (isLinksSupported) {
335
+ $spinner.message(`Deploying version ${version}${deploySuffix} ${deploymentLink}: ${logMessage}`);
336
+ }
337
+ else {
338
+ $spinner.message(`Deploying version ${version}${deploySuffix}: ${logMessage}`);
339
+ }
252
340
  });
253
341
  if (!finalizeResponse.success) {
254
342
  await failDeploy(projectClient.client, deployment, { name: "FinalizeError", message: finalizeResponse.error }, buildResult.logs, $spinner);
255
343
  throw new SkipLoggingError("Failed to finalize deployment");
256
344
  }
257
- $spinner.stop(`Successfully deployed version ${version}`);
345
+ if (isCI) {
346
+ log.step(`Successfully deployed version ${version}${deploySuffix}`);
347
+ }
348
+ else {
349
+ $spinner.stop(`Successfully deployed version ${version}${deploySuffix}`);
350
+ }
258
351
  const taskCount = deploymentWithWorker.worker?.tasks.length ?? 0;
259
352
  outro(`Version ${version} deployed with ${taskCount} detected task${taskCount === 1 ? "" : "s"} ${isLinksSupported ? `| ${deploymentLink} | ${testLink}` : ""}`);
260
- }
261
- function rewriteBuildManifestPaths(buildManifest, destinationDir) {
262
- return {
263
- ...buildManifest,
264
- files: buildManifest.files.map((file) => ({
265
- ...file,
266
- entry: cleanEntryPath(file.entry),
267
- out: rewriteOutputPath(destinationDir, file.out),
268
- })),
269
- outputPath: rewriteOutputPath(destinationDir, buildManifest.outputPath),
270
- configPath: rewriteOutputPath(destinationDir, buildManifest.configPath),
271
- runControllerEntryPoint: buildManifest.runControllerEntryPoint
272
- ? rewriteOutputPath(destinationDir, buildManifest.runControllerEntryPoint)
273
- : undefined,
274
- runWorkerEntryPoint: rewriteOutputPath(destinationDir, buildManifest.runWorkerEntryPoint),
275
- indexControllerEntryPoint: buildManifest.indexControllerEntryPoint
276
- ? rewriteOutputPath(destinationDir, buildManifest.indexControllerEntryPoint)
277
- : undefined,
278
- indexWorkerEntryPoint: rewriteOutputPath(destinationDir, buildManifest.indexWorkerEntryPoint),
279
- loaderEntryPoint: buildManifest.loaderEntryPoint
280
- ? rewriteOutputPath(destinationDir, buildManifest.loaderEntryPoint)
281
- : undefined,
282
- };
283
- }
284
- async function writeProjectFiles(buildManifest, resolvedConfig, outputPath) {
285
- // Step 1. Read the package.json file
286
- const packageJson = await readProjectPackageJson(resolvedConfig.packageJsonPath);
287
- if (!packageJson) {
288
- throw new Error("Could not read the package.json file");
353
+ if (!isLinksSupported) {
354
+ console.log("View deployment");
355
+ console.log(rawDeploymentLink);
356
+ console.log(); // new line
357
+ console.log("Test tasks");
358
+ console.log(rawTestLink);
289
359
  }
290
- const dependencies = buildManifest.externals?.reduce((acc, external) => {
291
- acc[external.name] = external.version;
292
- return acc;
293
- }, {}) ?? {};
294
- // Step 3: Write the resolved dependencies to the package.json file
295
- await writePackageJSON(join(outputPath, "package.json"), {
296
- ...packageJson,
297
- name: packageJson.name ?? "trigger-project",
298
- dependencies: {
299
- ...dependencies,
300
- },
301
- trustedDependencies: Object.keys(dependencies),
302
- devDependencies: {},
303
- peerDependencies: {},
304
- scripts: {},
305
- });
306
- await writeJSONFile(join(outputPath, "build.json"), buildManifestToJSON(buildManifest));
307
- await writeContainerfile(outputPath, buildManifest);
308
- }
309
- async function readProjectPackageJson(packageJsonPath) {
310
- const packageJson = await readPackageJSON(packageJsonPath);
311
- return packageJson;
312
- }
313
- // Remove any query parameters from the entry path
314
- // For example, src/trigger/ai.ts?sentryProxyModule=true -> src/trigger/ai.ts
315
- function cleanEntryPath(entry) {
316
- return entry.split("?")[0];
317
- }
318
- function rewriteOutputPath(destinationDir, filePath) {
319
- return `/app/${relative(destinationDir, filePath)}`;
320
- }
321
- async function writeContainerfile(outputPath, buildManifest) {
322
- if (!buildManifest.runControllerEntryPoint || !buildManifest.indexControllerEntryPoint) {
323
- throw new Error("Something went wrong with the build. Aborting deployment. [code 7789]");
360
+ if (options.saveLogs) {
361
+ const logPath = await saveLogs(deployment.shortCode, buildResult.logs);
362
+ console.log(`Full build logs have been saved to ${logPath}`);
324
363
  }
325
- const containerfile = await generateContainerfile({
326
- runtime: buildManifest.runtime,
327
- entrypoint: buildManifest.runControllerEntryPoint,
328
- build: buildManifest.build,
329
- image: buildManifest.image,
330
- indexScript: buildManifest.indexControllerEntryPoint,
364
+ setGithubActionsOutputAndEnvVars({
365
+ envVars: {
366
+ TRIGGER_DEPLOYMENT_VERSION: version,
367
+ TRIGGER_VERSION: version,
368
+ TRIGGER_DEPLOYMENT_SHORT_CODE: deployment.shortCode,
369
+ TRIGGER_DEPLOYMENT_URL: `${authorization.dashboardUrl}/projects/v3/${resolvedConfig.project}/deployments/${deployment.shortCode}`,
370
+ TRIGGER_TEST_URL: `${authorization.dashboardUrl}/projects/v3/${resolvedConfig.project}/test?environment=${options.env === "prod" ? "prod" : "stg"}`,
371
+ },
372
+ outputs: {
373
+ deploymentVersion: version,
374
+ workerVersion: version,
375
+ deploymentShortCode: deployment.shortCode,
376
+ deploymentUrl: `${authorization.dashboardUrl}/projects/v3/${resolvedConfig.project}/deployments/${deployment.shortCode}`,
377
+ testUrl: `${authorization.dashboardUrl}/projects/v3/${resolvedConfig.project}/test?environment=${options.env === "prod" ? "prod" : "stg"}`,
378
+ needsPromotion: options.skipPromotion ? "true" : "false",
379
+ },
331
380
  });
332
- await writeFile(join(outputPath, "Containerfile"), containerfile);
333
381
  }
334
- export async function syncEnvVarsWithServer(apiClient, projectRef, environmentSlug, envVars) {
335
- const uploadResult = await apiClient.importEnvVars(projectRef, environmentSlug, {
382
+ export async function syncEnvVarsWithServer(apiClient, projectRef, environmentSlug, envVars, parentEnvVars) {
383
+ return await apiClient.importEnvVars(projectRef, environmentSlug, {
336
384
  variables: envVars,
385
+ parentVariables: parentEnvVars,
337
386
  override: true,
338
387
  });
339
- return uploadResult.success;
340
388
  }
341
389
  async function failDeploy(client, deployment, error, logs, $spinner, warnings, errors) {
390
+ logger.debug("failDeploy", { error, logs, warnings, errors });
342
391
  $spinner.stop(`Failed to deploy project`);
343
392
  const doOutputLogs = async (prefix = "Error") => {
344
393
  if (logs.trim() !== "") {
@@ -347,9 +396,20 @@ async function failDeploy(client, deployment, error, logs, $spinner, warnings, e
347
396
  printErrors(errors);
348
397
  checkLogsForErrors(logs);
349
398
  outro(`${chalkError(`${prefix}:`)} ${error.message}. Full build logs have been saved to ${logPath}`);
399
+ // Display the last few lines of the logs, remove #-prefixed ones
400
+ const lastFewLines = logs
401
+ .split("\n")
402
+ .filter((line) => !line.startsWith("#"))
403
+ .filter((line) => line.trim() !== "")
404
+ .slice(-5)
405
+ .join("\n");
406
+ if (lastFewLines.trim() !== "") {
407
+ console.log("Last few lines of logs:\n");
408
+ console.log(lastFewLines);
409
+ }
350
410
  }
351
411
  else {
352
- outro(`${chalkError(`${prefix}:`)} ${error.message}.`);
412
+ outro(`${chalkError(`${prefix}:`)} ${error.message}`);
353
413
  }
354
414
  };
355
415
  const exitCommand = (message) => {
@@ -382,7 +442,7 @@ async function failDeploy(client, deployment, error, logs, $spinner, warnings, e
382
442
  ? prepareDeploymentError(serverDeployment.errorData)
383
443
  : undefined;
384
444
  if (errorData) {
385
- prettyError(errorData.name, errorData.stack, errorData.stderr);
445
+ prettyError(errorData.message, errorData.stack, errorData.stderr);
386
446
  if (logs.trim() !== "") {
387
447
  const logPath = await saveLogs(deployment.shortCode, logs);
388
448
  outro(`Aborting deployment. Full build logs have been saved to ${logPath}`);
@@ -410,4 +470,55 @@ async function failDeploy(client, deployment, error, logs, $spinner, warnings, e
410
470
  }
411
471
  }
412
472
  }
473
+ async function initializeOrAttachDeployment(apiClient, data, existingDeploymentId) {
474
+ if (existingDeploymentId) {
475
+ // In the build server we initialize the deployment before installing the project dependencies,
476
+ // so that the status is correctly reflected in the dashboard. In this case, we need to attach
477
+ // to the existing deployment and continue with the remote build process.
478
+ // This is a workaround to avoid major changes in the deploy command and workflow. In the future,
479
+ // we'll likely make the build server the entry point of the flow for building and deploying and also
480
+ // adapt the related deployment API endpoints.
481
+ const existingDeploymentOrError = await apiClient.getDeployment(existingDeploymentId);
482
+ if (!existingDeploymentOrError.success) {
483
+ throw new Error(`Failed to attach to existing deployment: ${existingDeploymentOrError.error}`);
484
+ }
485
+ const { imageReference, status } = existingDeploymentOrError.data;
486
+ if (!imageReference) {
487
+ // this is just an artifact of our current DB schema
488
+ // `imageReference` is stored as nullable, but it should always exist
489
+ throw new Error("Existing deployment does not have an image reference");
490
+ }
491
+ if (status === "CANCELED" ||
492
+ status === "FAILED" ||
493
+ status === "TIMED_OUT" ||
494
+ status === "DEPLOYED") {
495
+ throw new Error(`Existing deployment is in an unexpected state: ${status}`);
496
+ }
497
+ return {
498
+ ...existingDeploymentOrError.data,
499
+ imageTag: imageReference,
500
+ };
501
+ }
502
+ const newDeploymentOrError = await apiClient.initializeDeployment({
503
+ ...data,
504
+ });
505
+ if (!newDeploymentOrError.success) {
506
+ throw new Error(`Failed to start deployment: ${newDeploymentOrError.error}`);
507
+ }
508
+ return newDeploymentOrError.data;
509
+ }
510
+ export function verifyDirectory(dir, projectPath) {
511
+ if (dir !== "." && !isDirectory(projectPath)) {
512
+ if (dir === "staging" || dir === "prod" || dir === "preview") {
513
+ throw new Error(`To deploy to ${dir}, you need to pass "--env ${dir}", not just "${dir}".`);
514
+ }
515
+ if (dir === "production") {
516
+ throw new Error(`To deploy to production, you need to pass "--env prod", not "production".`);
517
+ }
518
+ if (dir === "stg") {
519
+ throw new Error(`To deploy to staging, you need to pass "--env staging", not "stg".`);
520
+ }
521
+ throw new Error(`Directory "${dir}" not found at ${projectPath}`);
522
+ }
523
+ }
413
524
  //# sourceMappingURL=deploy.js.map