0

Create a Custom Image

by
Published Dec 20, 2024

To create a new custom image, send a POST request to /v2/images. The body must contain a url attribute pointing to a Linux virtual machine image to be imported into DigitalOcean. The image must be in the raw, qcow2, vhdx, vdi, or vmdk format. It may be compressed using gzip or bzip2 and must be smaller than 100 GB after being decompressed.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Create a Custom Image
7
 * To create a new custom image, send a POST request to /v2/images.
8
The body must contain a url attribute pointing to a Linux virtual machine
9
image to be imported into DigitalOcean.
10
The image must be in the raw, qcow2, vhdx, vdi, or vmdk format.
11
It may be compressed using gzip or bzip2 and must be smaller than 100 GB after
12
 being decompressed.
13

14
 */
15
export async function main(
16
  auth: Digitalocean,
17
  body: {
18
    name?: string;
19
    distribution?:
20
      | "Arch Linux"
21
      | "CentOS"
22
      | "CoreOS"
23
      | "Debian"
24
      | "Fedora"
25
      | "Fedora Atomic"
26
      | "FreeBSD"
27
      | "Gentoo"
28
      | "openSUSE"
29
      | "RancherOS"
30
      | "Rocky Linux"
31
      | "Ubuntu"
32
      | "Unknown";
33
    description?: string;
34
  } & {
35
    url?: string;
36
    region?:
37
      | "ams1"
38
      | "ams2"
39
      | "ams3"
40
      | "blr1"
41
      | "fra1"
42
      | "lon1"
43
      | "nyc1"
44
      | "nyc2"
45
      | "nyc3"
46
      | "sfo1"
47
      | "sfo2"
48
      | "sfo3"
49
      | "sgp1"
50
      | "tor1"
51
      | "syd1";
52
    tags?: string[];
53
  },
54
) {
55
  const url = new URL(`https://api.digitalocean.com/v2/images`);
56

57
  const response = await fetch(url, {
58
    method: "POST",
59
    headers: {
60
      "Content-Type": "application/json",
61
      Authorization: "Bearer " + auth.token,
62
    },
63
    body: JSON.stringify(body),
64
  });
65
  if (!response.ok) {
66
    const text = await response.text();
67
    throw new Error(`${response.status} ${text}`);
68
  }
69
  return await response.json();
70
}
71