//native
type Fly = {
token: string;
};
/**
* Create Machine
* Create a Machine within a specific app using the details provided in the request body.
**Important**: This request can fail, and you’re responsible for handling that failure. If you ask for a large Machine, or a Machine in a region we happen to be at capacity for, you might need to retry the request, or to fall back to another region. If you’re working directly with the Machines API, you’re taking some responsibility for your own orchestration!
*/
export async function main(
auth: Fly,
app_name: string,
body: {
config?: {
auto_destroy?: false | true;
checks?: {};
containers?: {
cmd?: string[];
depends_on?: {
condition?: "exited_successfully" | "healthy" | "started";
name?: string;
}[];
entrypoint?: string[];
env?: {};
env_from?: {
env_var?: string;
field_ref?:
| "id"
| "version"
| "app_name"
| "private_ip"
| "region"
| "image";
}[];
exec?: string[];
files?: {
guest_path?: string;
image_config?: string;
mode?: number;
raw_value?: string;
secret_name?: string;
}[];
healthchecks?: {
exec?: { command?: string[] };
failure_threshold?: number;
grace_period?: number;
http?: {
headers?: { name?: string; values?: string[] }[];
method?: string;
path?: string;
port?: number;
scheme?: "http" | "https";
tls_server_name?: string;
tls_skip_verify?: false | true;
};
interval?: number;
kind?: "readiness" | "liveness";
name?: string;
success_threshold?: number;
tcp?: { port?: number };
timeout?: number;
unhealthy?: "stop";
}[];
image?: string;
name?: string;
restart?: {
gpu_bid_price?: number;
max_retries?: number;
policy?: "no" | "always" | "on-failure" | "spot-price";
};
secrets?: { env_var?: string; name?: string }[];
stop?: { signal?: string; timeout?: { "time.Duration"?: number } };
user?: string;
}[];
disable_machine_autostart?: false | true;
dns?: {
dns_forward_rules?: { addr?: string; basename?: string }[];
hostname?: string;
hostname_fqdn?: string;
nameservers?: string[];
options?: { name?: string; value?: string }[];
searches?: string[];
skip_registration?: false | true;
};
env?: {};
files?: {
guest_path?: string;
image_config?: string;
mode?: number;
raw_value?: string;
secret_name?: string;
}[];
guest?: {
cpu_kind?: string;
cpus?: number;
gpu_kind?: string;
gpus?: number;
host_dedication_id?: string;
kernel_args?: string[];
memory_mb?: number;
};
image?: string;
init?: {
cmd?: string[];
entrypoint?: string[];
exec?: string[];
kernel_args?: string[];
swap_size_mb?: number;
tty?: false | true;
};
metadata?: {};
metrics?: { https?: false | true; path?: string; port?: number };
mounts?: {
add_size_gb?: number;
encrypted?: false | true;
extend_threshold_percent?: number;
name?: string;
path?: string;
size_gb?: number;
size_gb_limit?: number;
volume?: string;
}[];
processes?: {
cmd?: string[];
entrypoint?: string[];
env?: {};
env_from?: {
env_var?: string;
field_ref?:
| "id"
| "version"
| "app_name"
| "private_ip"
| "region"
| "image";
}[];
exec?: string[];
ignore_app_secrets?: false | true;
secrets?: { env_var?: string; name?: string }[];
user?: string;
}[];
restart?: {
gpu_bid_price?: number;
max_retries?: number;
policy?: "no" | "always" | "on-failure" | "spot-price";
};
schedule?: string;
services?: {
autostart?: false | true;
autostop?: "stop" | "off" | "suspend";
checks?: {
grace_period?: { "time.Duration"?: number };
headers?: { name?: string; values?: string[] }[];
interval?: { "time.Duration"?: number };
method?: string;
path?: string;
port?: number;
protocol?: string;
timeout?: { "time.Duration"?: number };
tls_server_name?: string;
tls_skip_verify?: false | true;
type?: string;
}[];
concurrency?: {
hard_limit?: number;
soft_limit?: number;
type?: string;
};
force_instance_description?: string;
force_instance_key?: string;
internal_port?: number;
min_machines_running?: number;
ports?: {
end_port?: number;
force_https?: false | true;
handlers?: string[];
http_options?: {
compress?: false | true;
h2_backend?: false | true;
headers_read_timeout?: number;
idle_timeout?: number;
response?: { headers?: {}; pristine?: false | true };
};
port?: number;
proxy_proto_options?: { version?: string };
start_port?: number;
tls_options?: {
alpn?: string[];
default_self_signed?: false | true;
versions?: string[];
};
}[];
protocol?: string;
}[];
size?: string;
standbys?: string[];
statics?: {
guest_path: string;
index_document?: string;
tigris_bucket?: string;
url_prefix: string;
}[];
stop_config?: { signal?: string; timeout?: { "time.Duration"?: number } };
};
lease_ttl?: number;
lsvd?: false | true;
min_secrets_version?: number;
name?: string;
region?: string;
skip_launch?: false | true;
skip_secrets?: false | true;
skip_service_registration?: false | true;
},
) {
const url = new URL(`https://api.machines.dev/v1/apps/${app_name}/machines`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago