Skip to content

Commit bf9b894

Browse files
committed
fix(deploy): adapt build env vars flow to reused deployments and scoped auth
Two adaptations to changes that landed on main: - the version-skew ack guard now runs after the reused-deployment early return, since an externally reused deployment builds nothing and never stores build env vars - the build-env-vars endpoint uses the same scoped api key auth as the sibling deployment route, which migrated to authenticateApiKeyWithScope
1 parent 8abbe05 commit bf9b894

2 files changed

Lines changed: 39 additions & 34 deletions

File tree

apps/webapp/app/routes/api.v1.deployments.$deploymentId.build-env-vars.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { type GetDeploymentBuildEnvVarsResponseBody } from "@trigger.dev/core/v3
33
import { z } from "zod";
44
import { prisma } from "~/db.server";
55
import { env } from "~/env.server";
6-
import { authenticateApiRequest } from "~/services/apiAuth.server";
6+
import { authenticateApiKeyWithScope } from "~/services/apiAuth.server";
77
import { logger } from "~/services/logger.server";
88
import { decryptSecret, EncryptedSecretValueSchema } from "~/services/secrets/secretStore.server";
99
import { FINAL_DEPLOYMENT_STATUSES } from "~/v3/services/failDeployment.server";
@@ -25,15 +25,19 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
2525
}
2626

2727
try {
28-
// Next authenticate the request
29-
const authenticationResult = await authenticateApiRequest(request);
28+
// Same auth as the sibling GET deployment route: env-key principals with
29+
// read scope on deployments, no JWT.
30+
const authResult = await authenticateApiKeyWithScope(request, {
31+
action: "read",
32+
resource: { type: "deployments" },
33+
});
3034

31-
if (!authenticationResult) {
35+
if (!authResult.ok) {
3236
logger.info("Invalid or missing api key", { url: request.url });
33-
return json({ error: "Invalid or Missing API key" }, { status: 401 });
37+
return json({ error: authResult.error }, { status: authResult.status });
3438
}
3539

36-
const authenticatedEnv = authenticationResult.environment;
40+
const authenticatedEnv = authResult.authentication.environment;
3741

3842
const { deploymentId } = parsedParams.data;
3943

packages/cli-v3/src/commands/deploy.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,9 +1547,37 @@ async function handleNativeBuildServerDeploy({
15471547

15481548
const deployment = initializeDeploymentResult.data;
15491549

1550+
const rawDeploymentLink = `${dashboardUrl}/projects/v3/${config.project}/deployments/${deployment.shortCode}`;
1551+
const rawTestLink = `${dashboardUrl}/projects/v3/${config.project}/test?environment=${
1552+
options.env === "prod" ? "prod" : "stg"
1553+
}`;
1554+
1555+
if (deployment.outcome === "existing") {
1556+
$deploymentSpinner.stop(`Version ${deployment.version} was already deployed`);
1557+
1558+
setDeploymentGithubActionsOutput({
1559+
version: deployment.version,
1560+
shortCode: deployment.shortCode,
1561+
rawDeploymentLink,
1562+
rawTestLink,
1563+
needsPromotion: !deployment.isPromoted,
1564+
});
1565+
1566+
warnAboutSkippedBuild(options.externalId, deployment.isPromoted);
1567+
1568+
outro(
1569+
`Version ${deployment.version} was already deployed for --external-id ${options.externalId} — nothing to build ${
1570+
isLinksSupported ? `| ${cliLink("View deployment", rawDeploymentLink)}` : rawDeploymentLink
1571+
}`
1572+
);
1573+
1574+
return;
1575+
}
1576+
15501577
// Version-skew guard: an older server silently strips unknown fields, so if we sent
15511578
// build env vars and the server didn't ack storing them, the remote build would run
1552-
// without them and fail in a confusing way. Fail fast instead.
1579+
// without them and fail in a confusing way. Fail fast instead. Deliberately after
1580+
// the outcome=existing return: a reused deployment builds nothing, so no ack is due.
15531581
if (
15541582
options.localBundle &&
15551583
bundleBuildEnvVars &&
@@ -1579,33 +1607,6 @@ async function handleNativeBuildServerDeploy({
15791607
throw new OutroCommandError(`Deployment failed`);
15801608
}
15811609

1582-
const rawDeploymentLink = `${dashboardUrl}/projects/v3/${config.project}/deployments/${deployment.shortCode}`;
1583-
const rawTestLink = `${dashboardUrl}/projects/v3/${config.project}/test?environment=${
1584-
options.env === "prod" ? "prod" : "stg"
1585-
}`;
1586-
1587-
if (deployment.outcome === "existing") {
1588-
$deploymentSpinner.stop(`Version ${deployment.version} was already deployed`);
1589-
1590-
setDeploymentGithubActionsOutput({
1591-
version: deployment.version,
1592-
shortCode: deployment.shortCode,
1593-
rawDeploymentLink,
1594-
rawTestLink,
1595-
needsPromotion: !deployment.isPromoted,
1596-
});
1597-
1598-
warnAboutSkippedBuild(options.externalId, deployment.isPromoted);
1599-
1600-
outro(
1601-
`Version ${deployment.version} was already deployed for --external-id ${options.externalId} — nothing to build ${
1602-
isLinksSupported ? `| ${cliLink("View deployment", rawDeploymentLink)}` : rawDeploymentLink
1603-
}`
1604-
);
1605-
1606-
return;
1607-
}
1608-
16091610
const exposedDeploymentLink = isLinksSupported
16101611
? cliLink(chalk.bold(rawDeploymentLink), rawDeploymentLink)
16111612
: chalk.bold(rawDeploymentLink);

0 commit comments

Comments
 (0)