1 | |
2 | type Render = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Create service |
7 | * Create a service. |
8 |
|
9 | */ |
10 | export async function main( |
11 | auth: Render, |
12 | body: { |
13 | type: 'static_site' | 'web_service' | 'private_service' | 'background_worker' | 'cron_job' |
14 | name: string |
15 | ownerId: string |
16 | repo?: string |
17 | autoDeploy?: 'yes' | 'no' |
18 | branch?: string |
19 | image?: { |
20 | ownerId: string |
21 | registryCredentialId?: string |
22 | imagePath: string |
23 | } |
24 | buildFilter?: { paths: string[]; ignoredPaths: string[] } |
25 | rootDir?: string |
26 | envVars?: { key: string; value: string } | { key: string; generateValue: false | true }[] |
27 | secretFiles?: { name: string; content: string }[] |
28 | environmentId?: string |
29 | serviceDetails?: |
30 | | { |
31 | buildCommand?: string |
32 | headers?: { path: string; name: string; value: string }[] |
33 | publishPath?: string |
34 | pullRequestPreviewsEnabled?: 'yes' | 'no' |
35 | previews?: { generation?: 'off' | 'manual' | 'automatic' } |
36 | routes?: { |
37 | type: 'redirect' | 'rewrite' |
38 | source: string |
39 | destination: string |
40 | priority?: number |
41 | }[] |
42 | renderSubdomainPolicy?: 'enabled' | 'disabled' |
43 | } |
44 | | { |
45 | autoscaling?: { |
46 | enabled: false | true |
47 | min: number |
48 | max: number |
49 | criteria: { |
50 | cpu: { enabled: false | true; percentage: number } |
51 | memory: { enabled: false | true; percentage: number } |
52 | } |
53 | } |
54 | disk?: { name: string; mountPath: string; sizeGB?: number } |
55 | env?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image' |
56 | runtime: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image' |
57 | envSpecificDetails?: |
58 | | { |
59 | dockerCommand?: string |
60 | dockerContext?: string |
61 | dockerfilePath?: string |
62 | registryCredentialId?: string |
63 | } |
64 | | { buildCommand: string; startCommand: string } |
65 | healthCheckPath?: string |
66 | maintenanceMode?: { enabled: false | true; uri: string } |
67 | numInstances?: number |
68 | plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra' |
69 | preDeployCommand?: string |
70 | pullRequestPreviewsEnabled?: 'yes' | 'no' |
71 | previews?: { generation?: 'off' | 'manual' | 'automatic' } |
72 | region?: 'frankfurt' | 'oregon' | 'ohio' | 'singapore' | 'virginia' |
73 | maxShutdownDelaySeconds?: number |
74 | renderSubdomainPolicy?: 'enabled' | 'disabled' |
75 | } |
76 | | { |
77 | autoscaling?: { |
78 | enabled: false | true |
79 | min: number |
80 | max: number |
81 | criteria: { |
82 | cpu: { enabled: false | true; percentage: number } |
83 | memory: { enabled: false | true; percentage: number } |
84 | } |
85 | } |
86 | disk?: { name: string; mountPath: string; sizeGB?: number } |
87 | env?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image' |
88 | runtime: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image' |
89 | envSpecificDetails?: |
90 | | { |
91 | dockerCommand?: string |
92 | dockerContext?: string |
93 | dockerfilePath?: string |
94 | registryCredentialId?: string |
95 | } |
96 | | { buildCommand: string; startCommand: string } |
97 | numInstances?: number |
98 | plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra' |
99 | preDeployCommand?: string |
100 | pullRequestPreviewsEnabled?: 'yes' | 'no' |
101 | previews?: { generation?: 'off' | 'manual' | 'automatic' } |
102 | region?: 'frankfurt' | 'oregon' | 'ohio' | 'singapore' | 'virginia' |
103 | maxShutdownDelaySeconds?: number |
104 | } |
105 | | { |
106 | env?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image' |
107 | runtime: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image' |
108 | envSpecificDetails?: |
109 | | { |
110 | dockerCommand: string |
111 | dockerContext: string |
112 | dockerfilePath: string |
113 | preDeployCommand?: string |
114 | registryCredential?: { |
115 | id: string |
116 | name: string |
117 | registry: 'GITHUB' | 'GITLAB' | 'DOCKER' | 'GOOGLE_ARTIFACT' | 'AWS_ECR' |
118 | username: string |
119 | updatedAt: string |
120 | } |
121 | } |
122 | | { |
123 | buildCommand: string |
124 | startCommand: string |
125 | preDeployCommand?: string |
126 | } |
127 | plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra' |
128 | region?: 'frankfurt' | 'oregon' | 'ohio' | 'singapore' | 'virginia' |
129 | schedule: string |
130 | } |
131 | } |
132 | ) { |
133 | const url = new URL(`https://api.render.com/v1/services`) |
134 |
|
135 | const response = await fetch(url, { |
136 | method: 'POST', |
137 | headers: { |
138 | 'Content-Type': 'application/json', |
139 | Authorization: 'Bearer ' + auth.apiKey |
140 | }, |
141 | body: JSON.stringify(body) |
142 | }) |
143 | if (!response.ok) { |
144 | const text = await response.text() |
145 | throw new Error(`${response.status} ${text}`) |
146 | } |
147 | return await response.json() |
148 | } |
149 |
|