Skip to content

Commit 7d17730

Browse files
authored
feat(api): handle build server deployment init gracefully for older cli versionsi (#2526)
This PR adapts the deployment initialization endpoint to handle build server deployments with older CLI versions gracefully. When we introduced automatic deployments via the build server, we slightly changed the deployment flow mainly in the initialization and starting step: now deployments are first initialized in the `PENDING` status and updated to `BUILDING` once the build server dequeues the build job. Newer versions of the `deploy` command in the CLI will automatically attach to the existing deployment and continue with the build process. For older versions, we can't change the command's client-side behavior, so we need to handle this case here in the initialization endpoint. As we control the env variables which the git meta is extracted from in the build server, we can use those to pass the existing deployment ID to this endpoint. This doesn't affect the git meta on the deployment as it is set prior to this step using the /start endpoint. It's a rather hacky solution, but it will do for now as it enables us to avoid degrading the build server experience for users with older CLI versions. We'll eventually be able to remove this workaround once we stop supporting 3.x CLI versions.
1 parent e4982bf commit 7d17730

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

apps/webapp/app/v3/services/initializeDeployment.server.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,40 @@ export class InitializeDeploymentService extends BaseService {
1919
environment: AuthenticatedEnvironment,
2020
payload: InitializeDeploymentRequestBody
2121
) {
22-
return this.traceWithEnv("call", environment, async (span) => {
22+
return this.traceWithEnv("call", environment, async () => {
23+
if (payload.gitMeta?.commitSha?.startsWith("deployment_")) {
24+
// When we introduced automatic deployments via the build server, we slightly changed the deployment flow
25+
// mainly in the initialization and starting step: now deployments are first initialized in the `PENDING` status
26+
// and updated to `BUILDING` once the build server dequeues the build job.
27+
// Newer versions of the `deploy` command in the CLI will automatically attach to the existing deployment
28+
// and continue with the build process. For older versions, we can't change the command's client-side behavior,
29+
// so we need to handle this case here in the initialization endpoint. As we control the env variables which
30+
// the git meta is extracted from in the build server, we can use those to pass the existing deployment ID
31+
// to this endpoint. This doesn't affect the git meta on the deployment as it is set prior to this step using the
32+
// /start endpoint. It's a rather hacky solution, but it will do for now as it enables us to avoid degrading the
33+
// build server experience for users with older CLI versions. We'll eventually be able to remove this workaround
34+
// once we stop supporting 3.x CLI versions.
35+
36+
const existingDeploymentId = payload.gitMeta.commitSha;
37+
const existingDeployment = await this._prisma.workerDeployment.findFirst({
38+
where: {
39+
environmentId: environment.id,
40+
friendlyId: existingDeploymentId,
41+
},
42+
});
43+
44+
if (!existingDeployment) {
45+
throw new ServiceValidationError(
46+
"Existing deployment not found during deployment initialization"
47+
);
48+
}
49+
50+
return {
51+
deployment: existingDeployment,
52+
imageRef: existingDeployment.imageReference ?? "",
53+
};
54+
}
55+
2356
if (payload.type === "UNMANAGED") {
2457
throw new ServiceValidationError("UNMANAGED deployments are not supported");
2558
}

0 commit comments

Comments
 (0)