0

Create Container Registry

by
Published Dec 20, 2024

To create your container registry, send a POST request to `/v2/registry`. The `name` becomes part of the URL for images stored in the registry. For example, if your registry is called `example`, an image in it will have the URL `registry.digitalocean.com/example/image:tag`.

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 Container Registry
7
 * To create your container registry, send a POST request to `/v2/registry`.
8

9
The `name` becomes part of the URL for images stored in the registry. For
10
example, if your registry is called `example`, an image in it will have the
11
URL `registry.digitalocean.com/example/image:tag`.
12

13
 */
14
export async function main(
15
  auth: Digitalocean,
16
  body: {
17
    name: string;
18
    subscription_tier_slug: "starter" | "basic" | "professional";
19
    region?: "nyc3" | "sfo3" | "ams3" | "sgp1" | "fra1";
20
  },
21
) {
22
  const url = new URL(`https://api.digitalocean.com/v2/registry`);
23

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