1 | |
2 | type Digitalocean = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a New App |
7 | * Create a new app by submitting an app specification. For documentation on app specifications (`AppSpec` objects), please refer to [the product documentation](https://docs.digitalocean.com/products/app-platform/reference/app-spec/). |
8 | */ |
9 | export async function main( |
10 | auth: Digitalocean, |
11 | Accept: string, |
12 | body: { |
13 | spec: { |
14 | name: string; |
15 | region?: |
16 | | "ams" |
17 | | "nyc" |
18 | | "fra" |
19 | | "sfo" |
20 | | "sgp" |
21 | | "blr" |
22 | | "tor" |
23 | | "lon" |
24 | | "syd"; |
25 | domains?: { |
26 | domain: string; |
27 | type?: "UNSPECIFIED" | "DEFAULT" | "PRIMARY" | "ALIAS"; |
28 | wildcard?: false | true; |
29 | zone?: string; |
30 | minimum_tls_version?: "1.2" | "1.3"; |
31 | }[]; |
32 | services?: { |
33 | name?: string; |
34 | git?: { branch?: string; repo_clone_url?: string }; |
35 | github?: { |
36 | branch?: string; |
37 | deploy_on_push?: false | true; |
38 | repo?: string; |
39 | }; |
40 | gitlab?: { |
41 | branch?: string; |
42 | deploy_on_push?: false | true; |
43 | repo?: string; |
44 | }; |
45 | image?: { |
46 | registry?: string; |
47 | registry_type?: "DOCKER_HUB" | "DOCR" | "GHCR"; |
48 | registry_credentials?: string; |
49 | repository?: string; |
50 | tag?: string; |
51 | digest?: string; |
52 | deploy_on_push?: { enabled?: false | true }; |
53 | }; |
54 | dockerfile_path?: string; |
55 | build_command?: string; |
56 | run_command?: string; |
57 | source_dir?: string; |
58 | envs?: { |
59 | key: string; |
60 | scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME"; |
61 | type?: "GENERAL" | "SECRET"; |
62 | value?: string; |
63 | }[]; |
64 | environment_slug?: string; |
65 | log_destinations?: { |
66 | name: string; |
67 | papertrail?: { endpoint: string }; |
68 | datadog?: { endpoint?: string; api_key: string }; |
69 | logtail?: { token?: string }; |
70 | open_search?: { |
71 | endpoint?: string; |
72 | basic_auth?: { user?: string; password?: {} }; |
73 | index_name?: string; |
74 | cluster_name?: string; |
75 | }; |
76 | }[]; |
77 | } & { |
78 | instance_count?: number; |
79 | instance_size_slug?: |
80 | | "apps-s-1vcpu-0.5gb" |
81 | | "apps-s-1vcpu-1gb-fixed" |
82 | | "apps-s-1vcpu-1gb" |
83 | | "apps-s-1vcpu-2gb" |
84 | | "apps-s-2vcpu-4gb" |
85 | | "apps-d-1vcpu-0.5gb" |
86 | | "apps-d-1vcpu-1gb" |
87 | | "apps-d-1vcpu-2gb" |
88 | | "apps-d-1vcpu-4gb" |
89 | | "apps-d-2vcpu-4gb" |
90 | | "apps-d-2vcpu-8gb" |
91 | | "apps-d-4vcpu-8gb" |
92 | | "apps-d-4vcpu-16gb" |
93 | | "apps-d-8vcpu-32gb" |
94 | | "basic-xxs" |
95 | | "basic-xs" |
96 | | "basic-s" |
97 | | "basic-m" |
98 | | "professional-xs" |
99 | | "professional-s" |
100 | | "professional-m" |
101 | | "professional-1l" |
102 | | "professional-l" |
103 | | "professional-xl"; |
104 | autoscaling?: { |
105 | min_instance_count?: number; |
106 | max_instance_count?: number; |
107 | metrics?: { cpu?: { percent?: number } }; |
108 | }; |
109 | } & { |
110 | cors?: { |
111 | allow_origins?: { |
112 | exact?: string; |
113 | prefix?: string; |
114 | regex?: string; |
115 | }[]; |
116 | allow_methods?: string[]; |
117 | allow_headers?: string[]; |
118 | expose_headers?: string[]; |
119 | max_age?: string; |
120 | allow_credentials?: false | true; |
121 | } & {} & {}; |
122 | health_check?: { |
123 | failure_threshold?: number; |
124 | port?: number; |
125 | http_path?: string; |
126 | initial_delay_seconds?: number; |
127 | period_seconds?: number; |
128 | success_threshold?: number; |
129 | timeout_seconds?: number; |
130 | }; |
131 | protocol?: "HTTP" | "HTTP2"; |
132 | http_port?: number; |
133 | internal_ports?: number[]; |
134 | routes?: { path?: string; preserve_path_prefix?: false | true }[]; |
135 | termination?: { |
136 | drain_seconds?: number; |
137 | grace_period_seconds?: number; |
138 | }; |
139 | }[]; |
140 | static_sites?: { |
141 | name?: string; |
142 | git?: { branch?: string; repo_clone_url?: string }; |
143 | github?: { |
144 | branch?: string; |
145 | deploy_on_push?: false | true; |
146 | repo?: string; |
147 | }; |
148 | gitlab?: { |
149 | branch?: string; |
150 | deploy_on_push?: false | true; |
151 | repo?: string; |
152 | }; |
153 | image?: { |
154 | registry?: string; |
155 | registry_type?: "DOCKER_HUB" | "DOCR" | "GHCR"; |
156 | registry_credentials?: string; |
157 | repository?: string; |
158 | tag?: string; |
159 | digest?: string; |
160 | deploy_on_push?: { enabled?: false | true }; |
161 | }; |
162 | dockerfile_path?: string; |
163 | build_command?: string; |
164 | run_command?: string; |
165 | source_dir?: string; |
166 | envs?: { |
167 | key: string; |
168 | scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME"; |
169 | type?: "GENERAL" | "SECRET"; |
170 | value?: string; |
171 | }[]; |
172 | environment_slug?: string; |
173 | log_destinations?: { |
174 | name: string; |
175 | papertrail?: { endpoint: string }; |
176 | datadog?: { endpoint?: string; api_key: string }; |
177 | logtail?: { token?: string }; |
178 | open_search?: { |
179 | endpoint?: string; |
180 | basic_auth?: { user?: string; password?: {} }; |
181 | index_name?: string; |
182 | cluster_name?: string; |
183 | }; |
184 | }[]; |
185 | } & { |
186 | index_document?: string; |
187 | error_document?: string; |
188 | catchall_document?: string; |
189 | output_dir?: string; |
190 | cors?: { |
191 | allow_origins?: { exact?: string; prefix?: string; regex?: string }[]; |
192 | allow_methods?: string[]; |
193 | allow_headers?: string[]; |
194 | expose_headers?: string[]; |
195 | max_age?: string; |
196 | allow_credentials?: false | true; |
197 | } & {} & {}; |
198 | routes?: { path?: string; preserve_path_prefix?: false | true }[]; |
199 | }[]; |
200 | jobs?: { |
201 | name?: string; |
202 | git?: { branch?: string; repo_clone_url?: string }; |
203 | github?: { |
204 | branch?: string; |
205 | deploy_on_push?: false | true; |
206 | repo?: string; |
207 | }; |
208 | gitlab?: { |
209 | branch?: string; |
210 | deploy_on_push?: false | true; |
211 | repo?: string; |
212 | }; |
213 | image?: { |
214 | registry?: string; |
215 | registry_type?: "DOCKER_HUB" | "DOCR" | "GHCR"; |
216 | registry_credentials?: string; |
217 | repository?: string; |
218 | tag?: string; |
219 | digest?: string; |
220 | deploy_on_push?: { enabled?: false | true }; |
221 | }; |
222 | dockerfile_path?: string; |
223 | build_command?: string; |
224 | run_command?: string; |
225 | source_dir?: string; |
226 | envs?: { |
227 | key: string; |
228 | scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME"; |
229 | type?: "GENERAL" | "SECRET"; |
230 | value?: string; |
231 | }[]; |
232 | environment_slug?: string; |
233 | log_destinations?: { |
234 | name: string; |
235 | papertrail?: { endpoint: string }; |
236 | datadog?: { endpoint?: string; api_key: string }; |
237 | logtail?: { token?: string }; |
238 | open_search?: { |
239 | endpoint?: string; |
240 | basic_auth?: { user?: string; password?: {} }; |
241 | index_name?: string; |
242 | cluster_name?: string; |
243 | }; |
244 | }[]; |
245 | } & { |
246 | instance_count?: number; |
247 | instance_size_slug?: |
248 | | "apps-s-1vcpu-0.5gb" |
249 | | "apps-s-1vcpu-1gb-fixed" |
250 | | "apps-s-1vcpu-1gb" |
251 | | "apps-s-1vcpu-2gb" |
252 | | "apps-s-2vcpu-4gb" |
253 | | "apps-d-1vcpu-0.5gb" |
254 | | "apps-d-1vcpu-1gb" |
255 | | "apps-d-1vcpu-2gb" |
256 | | "apps-d-1vcpu-4gb" |
257 | | "apps-d-2vcpu-4gb" |
258 | | "apps-d-2vcpu-8gb" |
259 | | "apps-d-4vcpu-8gb" |
260 | | "apps-d-4vcpu-16gb" |
261 | | "apps-d-8vcpu-32gb" |
262 | | "basic-xxs" |
263 | | "basic-xs" |
264 | | "basic-s" |
265 | | "basic-m" |
266 | | "professional-xs" |
267 | | "professional-s" |
268 | | "professional-m" |
269 | | "professional-1l" |
270 | | "professional-l" |
271 | | "professional-xl"; |
272 | autoscaling?: { |
273 | min_instance_count?: number; |
274 | max_instance_count?: number; |
275 | metrics?: { cpu?: { percent?: number } }; |
276 | }; |
277 | } & { |
278 | kind?: "UNSPECIFIED" | "PRE_DEPLOY" | "POST_DEPLOY" | "FAILED_DEPLOY"; |
279 | termination?: { grace_period_seconds?: number }; |
280 | }[]; |
281 | workers?: { |
282 | name?: string; |
283 | git?: { branch?: string; repo_clone_url?: string }; |
284 | github?: { |
285 | branch?: string; |
286 | deploy_on_push?: false | true; |
287 | repo?: string; |
288 | }; |
289 | gitlab?: { |
290 | branch?: string; |
291 | deploy_on_push?: false | true; |
292 | repo?: string; |
293 | }; |
294 | image?: { |
295 | registry?: string; |
296 | registry_type?: "DOCKER_HUB" | "DOCR" | "GHCR"; |
297 | registry_credentials?: string; |
298 | repository?: string; |
299 | tag?: string; |
300 | digest?: string; |
301 | deploy_on_push?: { enabled?: false | true }; |
302 | }; |
303 | dockerfile_path?: string; |
304 | build_command?: string; |
305 | run_command?: string; |
306 | source_dir?: string; |
307 | envs?: { |
308 | key: string; |
309 | scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME"; |
310 | type?: "GENERAL" | "SECRET"; |
311 | value?: string; |
312 | }[]; |
313 | environment_slug?: string; |
314 | log_destinations?: { |
315 | name: string; |
316 | papertrail?: { endpoint: string }; |
317 | datadog?: { endpoint?: string; api_key: string }; |
318 | logtail?: { token?: string }; |
319 | open_search?: { |
320 | endpoint?: string; |
321 | basic_auth?: { user?: string; password?: {} }; |
322 | index_name?: string; |
323 | cluster_name?: string; |
324 | }; |
325 | }[]; |
326 | } & { |
327 | instance_count?: number; |
328 | instance_size_slug?: |
329 | | "apps-s-1vcpu-0.5gb" |
330 | | "apps-s-1vcpu-1gb-fixed" |
331 | | "apps-s-1vcpu-1gb" |
332 | | "apps-s-1vcpu-2gb" |
333 | | "apps-s-2vcpu-4gb" |
334 | | "apps-d-1vcpu-0.5gb" |
335 | | "apps-d-1vcpu-1gb" |
336 | | "apps-d-1vcpu-2gb" |
337 | | "apps-d-1vcpu-4gb" |
338 | | "apps-d-2vcpu-4gb" |
339 | | "apps-d-2vcpu-8gb" |
340 | | "apps-d-4vcpu-8gb" |
341 | | "apps-d-4vcpu-16gb" |
342 | | "apps-d-8vcpu-32gb" |
343 | | "basic-xxs" |
344 | | "basic-xs" |
345 | | "basic-s" |
346 | | "basic-m" |
347 | | "professional-xs" |
348 | | "professional-s" |
349 | | "professional-m" |
350 | | "professional-1l" |
351 | | "professional-l" |
352 | | "professional-xl"; |
353 | autoscaling?: { |
354 | min_instance_count?: number; |
355 | max_instance_count?: number; |
356 | metrics?: { cpu?: { percent?: number } }; |
357 | }; |
358 | } & { termination?: { grace_period_seconds?: number } }[]; |
359 | functions?: { |
360 | cors?: { |
361 | allow_origins?: { exact?: string; prefix?: string; regex?: string }[]; |
362 | allow_methods?: string[]; |
363 | allow_headers?: string[]; |
364 | expose_headers?: string[]; |
365 | max_age?: string; |
366 | allow_credentials?: false | true; |
367 | } & {} & {}; |
368 | routes?: { path?: string; preserve_path_prefix?: false | true }[]; |
369 | name: string; |
370 | source_dir?: string; |
371 | alerts?: { |
372 | rule?: |
373 | | "UNSPECIFIED_RULE" |
374 | | "CPU_UTILIZATION" |
375 | | "MEM_UTILIZATION" |
376 | | "RESTART_COUNT" |
377 | | "DEPLOYMENT_FAILED" |
378 | | "DEPLOYMENT_LIVE" |
379 | | "DOMAIN_FAILED" |
380 | | "DOMAIN_LIVE" |
381 | | "FUNCTIONS_ACTIVATION_COUNT" |
382 | | "FUNCTIONS_AVERAGE_DURATION_MS" |
383 | | "FUNCTIONS_ERROR_RATE_PER_MINUTE" |
384 | | "FUNCTIONS_AVERAGE_WAIT_TIME_MS" |
385 | | "FUNCTIONS_ERROR_COUNT" |
386 | | "FUNCTIONS_GB_RATE_PER_SECOND"; |
387 | disabled?: false | true; |
388 | operator?: "UNSPECIFIED_OPERATOR" | "GREATER_THAN" | "LESS_THAN"; |
389 | value?: number; |
390 | window?: |
391 | | "UNSPECIFIED_WINDOW" |
392 | | "FIVE_MINUTES" |
393 | | "TEN_MINUTES" |
394 | | "THIRTY_MINUTES" |
395 | | "ONE_HOUR"; |
396 | }[]; |
397 | envs?: { |
398 | key: string; |
399 | scope?: "UNSET" | "RUN_TIME" | "BUILD_TIME" | "RUN_AND_BUILD_TIME"; |
400 | type?: "GENERAL" | "SECRET"; |
401 | value?: string; |
402 | }[]; |
403 | git?: { branch?: string; repo_clone_url?: string }; |
404 | github?: { |
405 | branch?: string; |
406 | deploy_on_push?: false | true; |
407 | repo?: string; |
408 | }; |
409 | gitlab?: { |
410 | branch?: string; |
411 | deploy_on_push?: false | true; |
412 | repo?: string; |
413 | }; |
414 | log_destinations?: { |
415 | name: string; |
416 | papertrail?: { endpoint: string }; |
417 | datadog?: { endpoint?: string; api_key: string }; |
418 | logtail?: { token?: string }; |
419 | open_search?: { |
420 | endpoint?: string; |
421 | basic_auth?: { user?: string; password?: {} }; |
422 | index_name?: string; |
423 | cluster_name?: string; |
424 | }; |
425 | }[]; |
426 | }[]; |
427 | databases?: { |
428 | cluster_name?: string; |
429 | db_name?: string; |
430 | db_user?: string; |
431 | engine?: |
432 | | "UNSET" |
433 | | "MYSQL" |
434 | | "PG" |
435 | | "REDIS" |
436 | | "MONGODB" |
437 | | "KAFKA" |
438 | | "OPENSEARCH"; |
439 | name: string; |
440 | production?: false | true; |
441 | version?: string; |
442 | }[]; |
443 | ingress?: { |
444 | rules?: { |
445 | match?: { path: { prefix: string } }; |
446 | cors?: { |
447 | allow_origins?: { |
448 | exact?: string; |
449 | prefix?: string; |
450 | regex?: string; |
451 | }[]; |
452 | allow_methods?: string[]; |
453 | allow_headers?: string[]; |
454 | expose_headers?: string[]; |
455 | max_age?: string; |
456 | allow_credentials?: false | true; |
457 | }; |
458 | component?: { |
459 | name: string; |
460 | preserve_path_prefix?: string; |
461 | rewrite?: string; |
462 | }; |
463 | redirect?: { |
464 | uri?: string; |
465 | authority?: string; |
466 | port?: number; |
467 | scheme?: string; |
468 | redirect_code?: number; |
469 | }; |
470 | }[]; |
471 | }; |
472 | egress?: { type?: "AUTOASSIGN" | "DEDICATED_IP" }; |
473 | maintenance?: { enabled?: false | true; archive?: false | true }; |
474 | }; |
475 | project_id?: string; |
476 | }, |
477 | ) { |
478 | const url = new URL(`https://api.digitalocean.com/v2/apps`); |
479 |
|
480 | const response = await fetch(url, { |
481 | method: "POST", |
482 | headers: { |
483 | Accept: Accept, |
484 | "Content-Type": "application/json", |
485 | Authorization: "Bearer " + auth.token, |
486 | }, |
487 | body: JSON.stringify(body), |
488 | }); |
489 | if (!response.ok) { |
490 | const text = await response.text(); |
491 | throw new Error(`${response.status} ${text}`); |
492 | } |
493 | return await response.json(); |
494 | } |
495 |
|