Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .server-changes/allow-rollbacks-promote-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: feature
---

Add allowRollbacks query param to the promote deployment API to enable version downgrades
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export async function action({ request, params }: ActionFunctionArgs) {

const authenticatedEnv = authenticationResult.environment;

const url = new URL(request.url);
const allowRollbacks = url.searchParams.get("allowRollbacks") === "true";

const { deploymentVersion } = parsedParams.data;

const deployment = await prisma.workerDeployment.findFirst({
Expand All @@ -47,7 +50,7 @@ export async function action({ request, params }: ActionFunctionArgs) {

try {
const service = new ChangeCurrentDeploymentService();
await service.call(deployment, "promote");
await service.call(deployment, "promote", allowRollbacks);

return json(
{
Expand Down
50 changes: 31 additions & 19 deletions apps/webapp/app/v3/services/changeCurrentDeployment.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { CURRENT_DEPLOYMENT_LABEL } from "@trigger.dev/core/v3/isomorphic";
export type ChangeCurrentDeploymentDirection = "promote" | "rollback";

export class ChangeCurrentDeploymentService extends BaseService {
public async call(deployment: WorkerDeployment, direction: ChangeCurrentDeploymentDirection) {
public async call(
deployment: WorkerDeployment,
direction: ChangeCurrentDeploymentDirection,
disableVersionCheck?: boolean
) {
if (!deployment.workerId) {
throw new ServiceValidationError(
direction === "promote"
Expand Down Expand Up @@ -42,26 +46,34 @@ export class ChangeCurrentDeploymentService extends BaseService {
}

// if there is a current promotion, we have to validate we are moving in the right direction based on the deployment versions
switch (direction) {
case "promote": {
if (
compareDeploymentVersions(currentPromotion.deployment.version, deployment.version) >= 0
) {
throw new ServiceValidationError(
"Cannot promote a deployment that is older than the current deployment."
);
if (!disableVersionCheck) {
switch (direction) {
case "promote": {
if (
compareDeploymentVersions(
currentPromotion.deployment.version,
deployment.version
) >= 0
) {
throw new ServiceValidationError(
"Cannot promote a deployment that is older than the current deployment."
);
}
break;
}
break;
}
case "rollback": {
if (
compareDeploymentVersions(currentPromotion.deployment.version, deployment.version) <= 0
) {
throw new ServiceValidationError(
"Cannot rollback to a deployment that is newer than the current deployment."
);
case "rollback": {
if (
compareDeploymentVersions(
currentPromotion.deployment.version,
deployment.version
) <= 0
) {
throw new ServiceValidationError(
"Cannot rollback to a deployment that is newer than the current deployment."
);
}
break;
}
break;
}
}
}
Expand Down
Loading