Skip to content

Commit c385db6

Browse files
authored
v3: cli deploy command (#931)
* WIP proxy/deploy * WIP, registry proxy in express working * A couple of notes, preparing for indexing * Move the changes to prod-worker into the new file * Deploy command working with indexing and runs (docker provider only for now) * Removed ts-expect-error directive * Fixed build command
1 parent 86b2674 commit c385db6

60 files changed

Lines changed: 2301 additions & 532 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@ CLOUD_SLACK_CLIENT_SECRET=
4949

5050
# v3 variables
5151
PROVIDER_SECRET=provider-secret # generate the actual secret with `openssl rand -hex 32`
52-
COORDINATOR_SECRET=coordinator-secret # generate the actual secret with `openssl rand -hex 32`
52+
COORDINATOR_SECRET=coordinator-secret # generate the actual secret with `openssl rand -hex 32`
53+
54+
# Uncomment the following line to enable the registry proxy
55+
# ENABLE_REGISTRY_PROXY=true
56+
# DEPOT_TOKEN=<Depot org token>
57+
# DEPOT_PROJECT_ID=<Depot project id>
58+
# CONTAINER_REGISTRY_ORIGIN=<Container registry origin e.g. https://registry.digitalocean.com>
59+
# CONTAINER_REGISTRY_USERNAME=<Container registry username e.g. Digital ocean email address>
60+
# CONTAINER_REGISTRY_PASSWORD=<Container registry password e.g. Digital ocean PAT>

.vscode/launch.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
"cwd": "${workspaceFolder}/references/v3-catalog",
3838
"sourceMaps": true
3939
},
40+
{
41+
"type": "node-terminal",
42+
"request": "launch",
43+
"name": "Debug V3 Deploy CLI",
44+
"command": "pnpm exec trigger.dev deploy",
45+
"cwd": "${workspaceFolder}/references/v3-catalog",
46+
"sourceMaps": true
47+
},
4048
{
4149
"type": "node",
4250
"request": "attach",

apps/coordinator/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
HTTP_SERVER_PORT=8020
2-
32
PLATFORM_ENABLED=true
43
PLATFORM_WS_PORT=3030

apps/coordinator/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,10 @@ class TaskCoordinator {
286286
try {
287287
setSocketDataFromHeader("podName", "x-pod-name");
288288
setSocketDataFromHeader("contentHash", "x-trigger-content-hash");
289-
setSocketDataFromHeader("cliPackageVersion", "x-trigger-cli-package-version");
290289
setSocketDataFromHeader("projectRef", "x-trigger-project-ref");
291290
setSocketDataFromHeader("attemptId", "x-trigger-attempt-id");
292291
setSocketDataFromHeader("envId", "x-trigger-env-id");
292+
setSocketDataFromHeader("deploymentId", "x-trigger-deployment-id");
293293
} catch (error) {
294294
logger(error);
295295
socket.disconnect(true);
@@ -390,8 +390,8 @@ class TaskCoordinator {
390390
version: "v1",
391391
projectRef: socket.data.projectRef,
392392
envId: socket.data.envId,
393+
deploymentId: message.deploymentId,
393394
metadata: {
394-
cliPackageVersion: socket.data.cliPackageVersion,
395395
contentHash: socket.data.contentHash,
396396
packageVersion: message.packageVersion,
397397
tasks: message.tasks,

apps/coordinator/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"include": ["./src/**/*.ts"],
3+
"exclude": ["node_modules"],
24
"compilerOptions": {
35
"target": "es2016",
46
"module": "commonjs",

apps/docker-provider/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
HTTP_SERVER_PORT=8050
22

33
PLATFORM_WS_PORT=3030
4-
PLATFORM_SECRET=provider-secret
4+
PLATFORM_SECRET=provider-secret
5+
# Use this if you are on macOS
6+
# COORDINATOR_HOST="host.docker.internal"
7+
# OTEL_EXPORTER_OTLP_ENDPOINT="http://host.docker.internal:4318"

apps/docker-provider/src/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,29 @@ import { SimpleLogger, TaskOperations, ProviderShell } from "@trigger.dev/core-a
44

55
const MACHINE_NAME = process.env.MACHINE_NAME || "local";
66
const COORDINATOR_PORT = process.env.COORDINATOR_PORT || 8020;
7+
const COORDINATOR_HOST = process.env.COORDINATOR_HOST || "127.0.0.1";
8+
const OTEL_EXPORTER_OTLP_ENDPOINT =
9+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://0.0.0.0:4318";
710

811
const logger = new SimpleLogger(`[${MACHINE_NAME}]`);
912

1013
class DockerTaskOperations implements TaskOperations {
11-
async index(opts: { contentHash: string; imageTag: string; envId: string }) {
14+
async index(opts: {
15+
contentHash: string;
16+
imageTag: string;
17+
envId: string;
18+
apiKey: string;
19+
apiUrl: string;
20+
}) {
1221
const containerName = this.#getIndexContainerName(opts.contentHash);
1322

23+
logger.log(`Indexing task ${opts.imageTag}`, {
24+
host: COORDINATOR_HOST,
25+
port: COORDINATOR_PORT,
26+
});
27+
1428
const { exitCode } = logger.debug(
15-
await $`docker run --rm -e COORDINATOR_PORT=${COORDINATOR_PORT} -e POD_NAME=${containerName} -e TRIGGER_ENV_ID=${opts.envId} -e INDEX_TASKS=true --network=host --pull=never --name=${containerName} ${opts.imageTag}`
29+
await $`docker run --rm -e TRIGGER_SECRET_KEY=${opts.apiKey} -e TRIGGER_API_URL=${opts.apiUrl} -e COORDINATOR_HOST=${COORDINATOR_HOST} -e COORDINATOR_PORT=${COORDINATOR_PORT} -e POD_NAME=${containerName} -e TRIGGER_ENV_ID=${opts.envId} -e INDEX_TASKS=true --name=${containerName} ${opts.imageTag}`
1630
);
1731

1832
if (exitCode !== 0) {
@@ -24,7 +38,7 @@ class DockerTaskOperations implements TaskOperations {
2438
const containerName = this.#getRunContainerName(opts.attemptId);
2539

2640
const { exitCode } = logger.debug(
27-
await $`docker run -d -e COORDINATOR_PORT=${COORDINATOR_PORT} -e POD_NAME=${containerName} -e TRIGGER_ENV_ID=${opts.envId} -e TRIGGER_ATTEMPT_ID=${opts.attemptId} --network=host --pull=never --name=${containerName} ${opts.image}`
41+
await $`docker run -d -e OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT} -e COORDINATOR_HOST=${COORDINATOR_HOST} -e COORDINATOR_PORT=${COORDINATOR_PORT} -e POD_NAME=${containerName} -e TRIGGER_ENV_ID=${opts.envId} -e TRIGGER_ATTEMPT_ID=${opts.attemptId} --name=${containerName} ${opts.image}`
2842
);
2943

3044
if (exitCode !== 0) {

apps/webapp/app/entry.server.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,4 @@ const sqsEventConsumer = singleton("sqsEventConsumer", getSharedSqsEventConsumer
197197

198198
export { wss } from "./v3/handleWebsockets.server";
199199
export { socketIo } from "./v3/handleSocketIo.server";
200+
export { registryProxy } from "./v3/registryProxy.server";

apps/webapp/app/env.server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ const EnvironmentSchema = z.object({
7676
IMAGE_REPO: z.string().default("task"),
7777
PROVIDER_SECRET: z.string().default("provider-secret"),
7878
COORDINATOR_SECRET: z.string().default("coordinator-secret"),
79+
DEPOT_TOKEN: z.string().optional(),
80+
DEPOT_PROJECT_ID: z.string().optional(),
81+
CONTAINER_REGISTRY_ORIGIN: z.string().optional(),
82+
CONTAINER_REGISTRY_USERNAME: z.string().optional(),
83+
CONTAINER_REGISTRY_PASSWORD: z.string().optional(),
7984
});
8085

8186
export type Environment = z.infer<typeof EnvironmentSchema>;

apps/webapp/app/routes/api.v1.projects.$projectRef.image-details.ts renamed to apps/webapp/app/routes/api.v1.deployments.$deploymentId.start-indexing.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ActionFunctionArgs, json } from "@remix-run/server-runtime";
2-
import { CreateImageDetailsRequestBody } from "@trigger.dev/core/v3";
2+
import { StartDeploymentIndexingRequestBody } from "@trigger.dev/core/v3";
33
import { z } from "zod";
44
import { authenticateApiRequest } from "~/services/apiAuth.server";
55
import { logger } from "~/services/logger.server";
6-
import { CreateImageDetailsService } from "~/v3/services/createImageDetails.server";
6+
import { StartDeploymentIndexing } from "~/v3/services/startDeploymentIndexing.server";
77

88
const ParamsSchema = z.object({
9-
projectRef: z.string(),
9+
deploymentId: z.string(),
1010
});
1111

1212
export async function action({ request, params }: ActionFunctionArgs) {
@@ -31,23 +31,23 @@ export async function action({ request, params }: ActionFunctionArgs) {
3131

3232
const authenticatedEnv = authenticationResult.environment;
3333

34-
const { projectRef } = parsedParams.data;
34+
const { deploymentId } = parsedParams.data;
3535

3636
const rawBody = await request.json();
37-
const body = CreateImageDetailsRequestBody.safeParse(rawBody);
37+
const body = StartDeploymentIndexingRequestBody.safeParse(rawBody);
3838

3939
if (!body.success) {
4040
return json({ error: "Invalid body", issues: body.error.issues }, { status: 400 });
4141
}
4242

43-
const service = new CreateImageDetailsService();
43+
const service = new StartDeploymentIndexing();
4444

45-
const imageDetails = await service.call(projectRef, authenticatedEnv, body.data);
45+
const deployment = await service.call(authenticatedEnv, deploymentId, body.data);
4646

4747
return json(
4848
{
49-
id: imageDetails.friendlyId,
50-
contentHash: imageDetails.contentHash,
49+
id: deployment.friendlyId,
50+
contentHash: deployment.contentHash,
5151
},
5252
{ status: 200 }
5353
);

0 commit comments

Comments
 (0)