Skip to content

Commit e155aad

Browse files
committed
block some actions for projects on previous run engine
1 parent 476b20f commit e155aad

File tree

6 files changed

+51
-21
lines changed

6 files changed

+51
-21
lines changed

apps/webapp/app/routes/api.v1.deployments.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { env } from "~/env.server";
77
import { authenticateApiRequest } from "~/services/apiAuth.server";
88
import { logger } from "~/services/logger.server";
9+
import { ServiceValidationError } from "~/v3/services/baseService.server";
910
import { InitializeDeploymentService } from "~/v3/services/initializeDeployment.server";
1011

1112
export async function action({ request, params }: ActionFunctionArgs) {
@@ -33,18 +34,30 @@ export async function action({ request, params }: ActionFunctionArgs) {
3334

3435
const service = new InitializeDeploymentService();
3536

36-
const { deployment, imageTag } = await service.call(authenticatedEnv, body.data);
37-
38-
const responseBody: InitializeDeploymentResponseBody = {
39-
id: deployment.friendlyId,
40-
contentHash: deployment.contentHash,
41-
shortCode: deployment.shortCode,
42-
version: deployment.version,
43-
externalBuildData:
44-
deployment.externalBuildData as InitializeDeploymentResponseBody["externalBuildData"],
45-
imageTag,
46-
registryHost: body.data.registryHost ?? env.DEPLOY_REGISTRY_HOST,
47-
};
48-
49-
return json(responseBody, { status: 200 });
37+
try {
38+
const { deployment, imageTag } = await service.call(authenticatedEnv, body.data);
39+
40+
const responseBody: InitializeDeploymentResponseBody = {
41+
id: deployment.friendlyId,
42+
contentHash: deployment.contentHash,
43+
shortCode: deployment.shortCode,
44+
version: deployment.version,
45+
externalBuildData:
46+
deployment.externalBuildData as InitializeDeploymentResponseBody["externalBuildData"],
47+
imageTag,
48+
registryHost: body.data.registryHost ?? env.DEPLOY_REGISTRY_HOST,
49+
};
50+
51+
return json(responseBody, { status: 200 });
52+
} catch (error) {
53+
if (error instanceof ServiceValidationError) {
54+
return json({ error: error.message }, { status: 400 });
55+
} else if (error instanceof Error) {
56+
logger.error("Error initializing deployment", { error: error.message });
57+
return json({ error: `Internal server error: ${error.message}` }, { status: 500 });
58+
} else {
59+
logger.error("Error initializing deployment", { error: String(error) });
60+
return json({ error: "Internal server error" }, { status: 500 });
61+
}
62+
}
5063
}

apps/webapp/app/routes/api.v1.workers.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ export const loader = createLoaderApiRoute(
1515
corsStrategy: "all",
1616
findResource: async () => 1, // This is a dummy function, we don't need to find a resource
1717
},
18-
async ({ authentication }): Promise<TypedResponse<WorkersListResponseBody>> => {
18+
async ({
19+
authentication,
20+
}): Promise<TypedResponse<WorkersListResponseBody | { error: string }>> => {
21+
if (authentication.environment.project.engine !== "V2") {
22+
return json({ error: "Not supported for V1 projects" }, { status: 400 });
23+
}
24+
1925
const service = new WorkerGroupService();
2026
const workers = await service.listWorkerGroups({
2127
projectId: authentication.environment.projectId,
@@ -33,12 +39,19 @@ export const loader = createLoaderApiRoute(
3339
}
3440
);
3541

36-
export const action = createActionApiRoute(
42+
export const { action } = createActionApiRoute(
3743
{
3844
corsStrategy: "all",
3945
body: WorkersCreateRequestBody,
4046
},
41-
async ({ authentication, body }): Promise<TypedResponse<WorkersCreateResponseBody>> => {
47+
async ({
48+
authentication,
49+
body,
50+
}): Promise<TypedResponse<WorkersCreateResponseBody | { error: string }>> => {
51+
if (authentication.environment.project.engine !== "V2") {
52+
return json({ error: "Not supported" }, { status: 400 });
53+
}
54+
4255
const service = new WorkerGroupService();
4356
const { workerGroup, token } = await service.createWorkerGroup({
4457
projectId: authentication.environment.projectId,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
44
import { generateFriendlyId } from "../friendlyIdentifiers";
55
import { createRemoteImageBuild } from "../remoteImageBuilder.server";
66
import { calculateNextBuildVersion } from "../utils/calculateNextBuildVersion";
7-
import { BaseService } from "./baseService.server";
7+
import { BaseService, ServiceValidationError } from "./baseService.server";
88
import { TimeoutDeploymentService } from "./timeoutDeployment.server";
99
import { env } from "~/env.server";
1010
import { WorkerDeploymentType } from "@trigger.dev/database";
@@ -18,6 +18,10 @@ export class InitializeDeploymentService extends BaseService {
1818
payload: InitializeDeploymentRequestBody
1919
) {
2020
return this.traceWithEnv("call", environment, async (span) => {
21+
if (payload.type !== "V1" && environment.project.engine !== "V2") {
22+
throw new ServiceValidationError("Only V1 deployments are supported for this project");
23+
}
24+
2125
const latestDeployment = await this._prisma.workerDeployment.findFirst({
2226
where: {
2327
environmentId: environment.id,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class RollbackDeploymentService extends BaseService {
1212
}
1313

1414
if (deployment.type !== WorkerInstanceGroupType.MANAGED) {
15-
logger.error("Can only roll back shared deployments", {
15+
logger.error("Can only roll back managed deployments", {
1616
id: deployment.id,
1717
type: deployment.type,
1818
});

packages/cli-v3/src/commands/workers/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async function _workersCreateCommand(dir: string, options: WorkersCreateCommandO
126126
});
127127

128128
if (!newWorker.success) {
129-
throw new Error("Failed to create worker");
129+
throw new Error(`Failed to create worker: ${newWorker.error}`);
130130
}
131131

132132
outro(

packages/cli-v3/src/commands/workers/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async function _workersListCommand(dir: string, options: WorkersListCommandOptio
104104
const workers = await projectClient.client.workers.list();
105105

106106
if (!workers.success) {
107-
throw new Error("Failed to list workers");
107+
throw new Error(`Failed to list workers: ${workers.error}`);
108108
}
109109

110110
logger.table(

0 commit comments

Comments
 (0)