0

Rollback App

by
Published Dec 20, 2024

Rollback an app to a previous deployment. A new deployment will be created to perform the rollback. The app will be pinned to the rollback deployment preventing any new deployments from being created, either manually or through Auto Deploy on Push webhooks. To resume deployments, the rollback must be either committed or reverted. It is recommended to use the Validate App Rollback endpoint to double check if the rollback is valid and if there are any warnings.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Rollback App
7
 * Rollback an app to a previous deployment. A new deployment will be created to perform the rollback.
8
The app will be pinned to the rollback deployment preventing any new deployments from being created,
9
either manually or through Auto Deploy on Push webhooks. To resume deployments, the rollback must be
10
either committed or reverted.
11

12
It is recommended to use the Validate App Rollback endpoint to double check if the rollback is
13
valid and if there are any warnings.
14

15
 */
16
export async function main(
17
  auth: Digitalocean,
18
  app_id: string,
19
  body: { deployment_id?: string; skip_pin?: false | true },
20
) {
21
  const url = new URL(
22
    `https://api.digitalocean.com/v2/apps/${app_id}/rollback`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39