0

Update Machine

by
Published Oct 17, 2025

Update a Machine's configuration using the details provided in the request body.

Script fly Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Fly = {
3
  token: string;
4
};
5
/**
6
 * Update Machine
7
 * Update a Machine's configuration using the details provided in the request body.
8

9
 */
10
export async function main(
11
  auth: Fly,
12
  app_name: string,
13
  machine_id: string,
14
  body: {
15
    config?: {
16
      auto_destroy?: false | true;
17
      checks?: {};
18
      containers?: {
19
        cmd?: string[];
20
        depends_on?: {
21
          condition?: "exited_successfully" | "healthy" | "started";
22
          name?: string;
23
        }[];
24
        entrypoint?: string[];
25
        env?: {};
26
        env_from?: {
27
          env_var?: string;
28
          field_ref?:
29
            | "id"
30
            | "version"
31
            | "app_name"
32
            | "private_ip"
33
            | "region"
34
            | "image";
35
        }[];
36
        exec?: string[];
37
        files?: {
38
          guest_path?: string;
39
          image_config?: string;
40
          mode?: number;
41
          raw_value?: string;
42
          secret_name?: string;
43
        }[];
44
        healthchecks?: {
45
          exec?: { command?: string[] };
46
          failure_threshold?: number;
47
          grace_period?: number;
48
          http?: {
49
            headers?: { name?: string; values?: string[] }[];
50
            method?: string;
51
            path?: string;
52
            port?: number;
53
            scheme?: "http" | "https";
54
            tls_server_name?: string;
55
            tls_skip_verify?: false | true;
56
          };
57
          interval?: number;
58
          kind?: "readiness" | "liveness";
59
          name?: string;
60
          success_threshold?: number;
61
          tcp?: { port?: number };
62
          timeout?: number;
63
          unhealthy?: "stop";
64
        }[];
65
        image?: string;
66
        name?: string;
67
        restart?: {
68
          gpu_bid_price?: number;
69
          max_retries?: number;
70
          policy?: "no" | "always" | "on-failure" | "spot-price";
71
        };
72
        secrets?: { env_var?: string; name?: string }[];
73
        stop?: { signal?: string; timeout?: { "time.Duration"?: number } };
74
        user?: string;
75
      }[];
76
      disable_machine_autostart?: false | true;
77
      dns?: {
78
        dns_forward_rules?: { addr?: string; basename?: string }[];
79
        hostname?: string;
80
        hostname_fqdn?: string;
81
        nameservers?: string[];
82
        options?: { name?: string; value?: string }[];
83
        searches?: string[];
84
        skip_registration?: false | true;
85
      };
86
      env?: {};
87
      files?: {
88
        guest_path?: string;
89
        image_config?: string;
90
        mode?: number;
91
        raw_value?: string;
92
        secret_name?: string;
93
      }[];
94
      guest?: {
95
        cpu_kind?: string;
96
        cpus?: number;
97
        gpu_kind?: string;
98
        gpus?: number;
99
        host_dedication_id?: string;
100
        kernel_args?: string[];
101
        memory_mb?: number;
102
      };
103
      image?: string;
104
      init?: {
105
        cmd?: string[];
106
        entrypoint?: string[];
107
        exec?: string[];
108
        kernel_args?: string[];
109
        swap_size_mb?: number;
110
        tty?: false | true;
111
      };
112
      metadata?: {};
113
      metrics?: { https?: false | true; path?: string; port?: number };
114
      mounts?: {
115
        add_size_gb?: number;
116
        encrypted?: false | true;
117
        extend_threshold_percent?: number;
118
        name?: string;
119
        path?: string;
120
        size_gb?: number;
121
        size_gb_limit?: number;
122
        volume?: string;
123
      }[];
124
      processes?: {
125
        cmd?: string[];
126
        entrypoint?: string[];
127
        env?: {};
128
        env_from?: {
129
          env_var?: string;
130
          field_ref?:
131
            | "id"
132
            | "version"
133
            | "app_name"
134
            | "private_ip"
135
            | "region"
136
            | "image";
137
        }[];
138
        exec?: string[];
139
        ignore_app_secrets?: false | true;
140
        secrets?: { env_var?: string; name?: string }[];
141
        user?: string;
142
      }[];
143
      restart?: {
144
        gpu_bid_price?: number;
145
        max_retries?: number;
146
        policy?: "no" | "always" | "on-failure" | "spot-price";
147
      };
148
      schedule?: string;
149
      services?: {
150
        autostart?: false | true;
151
        autostop?: "stop" | "off" | "suspend";
152
        checks?: {
153
          grace_period?: { "time.Duration"?: number };
154
          headers?: { name?: string; values?: string[] }[];
155
          interval?: { "time.Duration"?: number };
156
          method?: string;
157
          path?: string;
158
          port?: number;
159
          protocol?: string;
160
          timeout?: { "time.Duration"?: number };
161
          tls_server_name?: string;
162
          tls_skip_verify?: false | true;
163
          type?: string;
164
        }[];
165
        concurrency?: {
166
          hard_limit?: number;
167
          soft_limit?: number;
168
          type?: string;
169
        };
170
        force_instance_description?: string;
171
        force_instance_key?: string;
172
        internal_port?: number;
173
        min_machines_running?: number;
174
        ports?: {
175
          end_port?: number;
176
          force_https?: false | true;
177
          handlers?: string[];
178
          http_options?: {
179
            compress?: false | true;
180
            h2_backend?: false | true;
181
            headers_read_timeout?: number;
182
            idle_timeout?: number;
183
            response?: { headers?: {}; pristine?: false | true };
184
          };
185
          port?: number;
186
          proxy_proto_options?: { version?: string };
187
          start_port?: number;
188
          tls_options?: {
189
            alpn?: string[];
190
            default_self_signed?: false | true;
191
            versions?: string[];
192
          };
193
        }[];
194
        protocol?: string;
195
      }[];
196
      size?: string;
197
      standbys?: string[];
198
      statics?: {
199
        guest_path: string;
200
        index_document?: string;
201
        tigris_bucket?: string;
202
        url_prefix: string;
203
      }[];
204
      stop_config?: { signal?: string; timeout?: { "time.Duration"?: number } };
205
    };
206
    current_version?: string;
207
    lease_ttl?: number;
208
    lsvd?: false | true;
209
    min_secrets_version?: number;
210
    name?: string;
211
    region?: string;
212
    skip_launch?: false | true;
213
    skip_secrets?: false | true;
214
    skip_service_registration?: false | true;
215
  },
216
) {
217
  const url = new URL(
218
    `https://api.machines.dev/v1/apps/${app_name}/machines/${machine_id}`,
219
  );
220

221
  const response = await fetch(url, {
222
    method: "POST",
223
    headers: {
224
      "Content-Type": "application/json",
225
      Authorization: "Bearer " + auth.token,
226
    },
227
    body: JSON.stringify(body),
228
  });
229
  if (!response.ok) {
230
    const text = await response.text();
231
    throw new Error(`${response.status} ${text}`);
232
  }
233
  return await response.json();
234
}
235