vast-ai-provisioner 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +23 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/types.d.ts +54 -0
- package/lib/utils.d.ts +4 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2024 ayan4m1 <andrew@bulletlogic.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# vast-ai-provisioner
|
|
2
|
+
|
|
3
|
+
This script will provision a [Vast.ai](https://vast.ai) instance with a specific template which can be overridden and customized beyond what is available with Vast's template system. The repo currently provides the following templates:
|
|
4
|
+
|
|
5
|
+
- "Complete" ComfyUI install - Flux, WAN, Hunyuan, SDXL + variants, ControlNets, and LoRAs
|
|
6
|
+
- SDXL ComfyUI install - all of the above minus Flux, WAN, and Hunyuan
|
|
7
|
+
- Flux Kontext ComfyUI install - Just Flux Kontext
|
|
8
|
+
- [FP-Studio](https://github.com/FP-Studio/FramePack-Studio) - A FramePack-based video editor
|
|
9
|
+
|
|
10
|
+
# Requirements
|
|
11
|
+
|
|
12
|
+
- Node >=22
|
|
13
|
+
|
|
14
|
+
# Usage
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
corepack enable
|
|
18
|
+
yarn install
|
|
19
|
+
yarn run build
|
|
20
|
+
node lib/index.js <template>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Template is an optional argument - if you do not provide it, the application will ask you which one you want to deploy.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'dotenv/config';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"dotenv/config";import{program as e}from"@commander-js/extra-typings";import{existsSync as t}from"fs";import{fileURLToPath as o}from"url";import{filesize as n}from"filesize";import{sprintf as a}from"sprintf-js";import{resolve as s,dirname as r,join as i}from"path";import{readFile as c,readdir as p}from"fs/promises";import{ExitPromptError as l}from"@inquirer/core";import m from"@npmcli/package-json";import{formatDistanceToNow as d,fromUnixTime as f}from"date-fns";import{select as h,confirm as u,checkbox as y}from"@inquirer/prompts";import g from"lodash.uniq";import w from"chalk";import{interpolateRgb as _}from"d3-interpolate";const $="https://console.vast.ai/api/v0",x=/rtx\s*5[0-9]{3}/i,S=()=>s(r(o(import.meta.url)),".."),b=e=>e?e.map(e=>` "${e}"`).join("\n"):"",v=async e=>{const t=await fetch(e);return parseInt(t.headers.get("Content-Length")??"0",10)},I=async e=>{const t=new Map,o=await p(e),n=(await Promise.all(o.map(t=>c(i(e,t),"utf-8")))).map(e=>JSON.parse(e));for(let e=0;e<o.length;e++)t.set(o[e],n[e]);return t},T=(e,t)=>{const o=t.reduce((e,t)=>e<t.search.totalHour?e:t.search.totalHour,100),s=t.reduce((e,t)=>e>t.search.totalHour?e:t.search.totalHour,0);return t.filter(e=>!x.test(e.gpu_name)).filter(t=>t.search.totalHour<=e.maxHourlyCost).map(e=>{const t=n(1e6*e.gpu_ram,{exponent:3,round:0,roundingMethod:"floor"}),r=_("#00ff00","#ff0000")((e.search.totalHour-o)/(s-o)).replace("rgb(","").replace(")","").split(",").map(e=>parseInt(e,10)),i=`#${((1<<24)+(r[0]<<16)+(r[1]<<8)+r[2]).toString(16).slice(1)}`;return{name:a("%-6s %-12s %-16s %8s %s",t,e.gpu_name,e.geolocation,`${Math.floor(e.inet_down)} Mbps`,w.bgHex(i)(`$${e.search.totalHour.toFixed(3)}/hr`)),value:e}})},P=async e=>{try{const o=await(async e=>{try{const o=i(S(),"templates");let n;if(e.template)n=i(o,`${e.template}.json`);else{const e=await I(o),t=await h({message:"Please choose a template to deploy.",choices:Array.from(e.entries().map(([e,t])=>({name:t.description?`${t.name} - ${t.description}`:t.name,value:e})))});n=i(o,t)}if(!t(n))throw new Error(`Unable to find template at ${n}!`);return JSON.parse(await c(n,"utf-8"))}catch(e){console.error(e),process.exit(1)}})(e),a=await(async e=>{try{const t=i(S(),"modules");console.log("Reading module JSON from ./modules");const o=await I(t);console.log("Fetching file sizes...");const a=Array.from(await Promise.all(o.entries().map(async([,t])=>{if(t.template!==e.name)return[];t.fileSizes=new Map,t.totalSize=0;for(const[,e]of Object.entries(t.files))for(const o of e){const e=await v(o);t.fileSizes.set(o,e),t.totalSize+=e}return[{name:`${t.name} (${n(t.totalSize)})`,value:t}]}))).flat();return a.length?await y({loop:!1,message:"Please choose the modules you would like to include.",choices:a}):[]}catch(e){console.error(e),process.exit(1)}})(o),s=await(async e=>{try{const t=await fetch(`${$}/search/asks`,{method:"PUT",body:JSON.stringify({q:{type:"on-demand",verified:{eq:!0},rentable:{eq:!0},rented:{eq:!1},num_gpus:{eq:1},gpu_ram:{gte:1024*e.minVram},inet_down:{gte:1e3},direct_port_count:{lte:e.maxPorts},limit:25,order:[["dph_total","asc"],["inet_down","asc"]]}}),headers:{Accept:"application/json","Content-Type":"application/json"},redirect:"follow"}),{offers:o}=await t.json();return o}catch(e){console.error(e),process.exit(1)}})(e),r=await h({message:"Choose the instance you would like to request.",choices:T(e,s),loop:!1});let p=o.size;if(a.length){const e=[];for(const t of a)for(const[o,n]of t.fileSizes.entries())e.includes(o)||(e.push(o),p+=n)}p/=1e9,p=Math.ceil(p),p*=1e9;const l=r.search.diskHour*(p/1e10),m=`$${(r.search.gpuCostPerHour+l).toFixed(3)}/hr`,w=`$${l.toFixed(3)}/hr`,_=`\nTemplate: ${o.name}\nModules:\n${a.map(e=>` * ${e.name} (${n(e.totalSize)})`).join("\n")}\nDisk Size: ${n(p)}\n\nAre you SURE you want create the instance?\n\nIt will be automatically destroyed in ${d(f(r.end_date))}.\n\nYou will be charged ${m} while it is running and ${w} while it is stopped!\n\nIt is YOUR responsibility to make sure that it has been stopped or destroyed correctly!\n`;if(!await u({message:_,default:!1}))return console.log("Exiting because user declined to deploy.");console.log(`Deploying ${o.name} to instance ${r}...`);const x={...o.environment};o.script&&(x.PROVISIONER_SCRIPT=await(async(e,o)=>{try{const n=i(S(),"scripts",e.script);if(!t(n))throw new Error(`Could not find script at ${n}!`);let a=await c(n,"utf-8");if(e.fileTypes.length&&o.length){const t=Object.fromEntries(e.fileTypes.map(e=>[e,[]]));for(const n of o)for(const o of e.fileTypes)t[o]=g([...t[o],...n.files[o]??[]]);for(const o of e.fileTypes)t[o].length&&(a=a.replace(`{{ ${o.toUpperCase()} }}`,b(t[o])))}const s=new FormData;s.append("api_dev_key",process.env.PASTEBIN_API_KEY),s.append("api_option","paste"),s.append("api_paste_code",a),s.append("api_paste_private","1"),s.append("api_paste_format","bash"),s.append("api_paste_name","provision.sh"),s.append("api_paste_expire_date","10M");const r=await fetch("https://pastebin.com/api/api_post.php",{method:"POST",body:s});return(await r.text()).replace("pastebin.com/","pastebin.com/raw/")}catch(e){console.error(e),process.exit(1)}})(o,a));const P={extra_env:x,disk:p/1e9,target_state:"running",cancel_unavail:!0,vm:!1};o.hash?P.template_hash_id=o.hash:o.tag&&(P.image=o.tag,P.runtype=o.runType);const A=await fetch(`${$}/asks/${r.id}`,{method:"PUT",headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(P)}),E=await A.json();E.success?console.log(`Instance ${E.new_contract} created!`):console.log("Failed to create instance!"),console.log("\nPress Ctrl-D to stop the instance, or Ctrl-C to destroy it..."),process.stdin.resume(),process.on("SIGQUIT",async()=>{if(!E.new_contract)return console.error("No instance to stop! Exiting..."),process.exit(0);try{await fetch(`${$}/instances/${E.new_contract}`,{method:"PUT",headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,"Content-Type":"application/json"},body:JSON.stringify({state:"stopped"})}),console.log(`Instance ${E.new_contract} stopped! Exiting...`),process.exit(0)}catch(e){console.error(e),process.exit(1)}}),process.on("SIGINT",async()=>{if(!E.new_contract)return console.error("No instance to destroy! Exiting..."),process.exit(0);try{await fetch(`${$}/instances/${E.new_contract}`,{headers:{Authorization:`Bearer ${process.env.VAST_API_KEY}`,"Content-Type":"application/json"},method:"DELETE"}),console.log(`Instance ${E.new_contract} destroyed! Exiting...`),process.exit(0)}catch(e){console.error(e),process.exit(1)}})}catch(e){e instanceof l?console.log("User requested cancellation of the provisioning process..."):console.error(e)}};try{const{name:t,version:o,description:n}=await(async()=>(await m.load(S()))?.content)();await e.name(t).version(o).description(n).argument("[template]","Specify template to deploy").option("--min-vram <gb>","Min. amount of GPU VRAM in GB",e=>parseInt(e,10),16).option("--max-hourly-cost <cost>","Max. instance cost in $/hr",e=>parseInt(e,10),1).option("--max-ports <count>","Max. number of ports on machine",e=>parseInt(e,10),1e3).action((e,t)=>P({template:e,...t})).parseAsync()}catch(e){console.error(e),process.exit(1)}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type Offer = {
|
|
2
|
+
direct_port_count: number;
|
|
3
|
+
disk_bw: number;
|
|
4
|
+
dlperf_per_dphtotal: number;
|
|
5
|
+
end_date: number;
|
|
6
|
+
geolocation: string;
|
|
7
|
+
gpu_name: string;
|
|
8
|
+
gpu_ram: number;
|
|
9
|
+
id: number;
|
|
10
|
+
inet_down: number;
|
|
11
|
+
search: {
|
|
12
|
+
gpuCostPerHour: number;
|
|
13
|
+
diskHour: number;
|
|
14
|
+
totalHour: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type Offers = {
|
|
18
|
+
offers: Offer[];
|
|
19
|
+
};
|
|
20
|
+
export declare enum RunType {
|
|
21
|
+
SSH = "ssh",
|
|
22
|
+
Jupyter = "jupyter",
|
|
23
|
+
Args = "args"
|
|
24
|
+
}
|
|
25
|
+
export type ModuleDependencies = Partial<Record<string, string[]>>;
|
|
26
|
+
export type Module = {
|
|
27
|
+
description: string;
|
|
28
|
+
files: ModuleDependencies;
|
|
29
|
+
name: string;
|
|
30
|
+
template: string;
|
|
31
|
+
fileSizes: Map<string, number>;
|
|
32
|
+
totalSize: number;
|
|
33
|
+
};
|
|
34
|
+
export type Template = {
|
|
35
|
+
description?: string;
|
|
36
|
+
environment?: Record<string, string>;
|
|
37
|
+
fileTypes: string[];
|
|
38
|
+
hash?: string;
|
|
39
|
+
name: string;
|
|
40
|
+
runType?: RunType;
|
|
41
|
+
script?: string;
|
|
42
|
+
size: number;
|
|
43
|
+
tag?: string;
|
|
44
|
+
};
|
|
45
|
+
export type CreateInstanceResponse = {
|
|
46
|
+
new_contract?: number;
|
|
47
|
+
success: boolean;
|
|
48
|
+
};
|
|
49
|
+
export type ProvisionOptions = {
|
|
50
|
+
maxHourlyCost?: number;
|
|
51
|
+
maxPorts?: number;
|
|
52
|
+
minVram?: number;
|
|
53
|
+
template?: string;
|
|
54
|
+
};
|
package/lib/utils.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "ayan4m1 <andrew@bulletlogic.com>",
|
|
3
|
+
"bin": "lib/index.js",
|
|
4
|
+
"bugs": {
|
|
5
|
+
"url": "https://github.com/ayan4m1/vast-ai-provisioner/issues"
|
|
6
|
+
},
|
|
7
|
+
"config": {
|
|
8
|
+
"commitizen": {
|
|
9
|
+
"path": "@commitlint/cz-commitlint"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@commander-js/extra-typings": "^14.0.0",
|
|
14
|
+
"@inquirer/core": "^10.1.14",
|
|
15
|
+
"@inquirer/prompts": "^7.6.0",
|
|
16
|
+
"@npmcli/package-json": "^6.2.0",
|
|
17
|
+
"chalk": "^5.4.1",
|
|
18
|
+
"commander": "^14.0.0",
|
|
19
|
+
"d3-interpolate": "^3.0.1",
|
|
20
|
+
"date-fns": "^4.1.0",
|
|
21
|
+
"dotenv": "^17.2.0",
|
|
22
|
+
"filesize": "^11.0.0",
|
|
23
|
+
"lodash.uniq": "^4.5.0",
|
|
24
|
+
"sprintf-js": "^1.1.3"
|
|
25
|
+
},
|
|
26
|
+
"description": "Deploy a ComfyUI instance to Vast.ai with one click",
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
29
|
+
"@commitlint/cz-commitlint": "^19.8.1",
|
|
30
|
+
"@eslint/js": "^9.30.1",
|
|
31
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
32
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
33
|
+
"@types/d3-interpolate": "^3",
|
|
34
|
+
"@types/eslint__js": "^8.42.3",
|
|
35
|
+
"@types/lodash.uniq": "^4",
|
|
36
|
+
"@types/node": "24.0.10",
|
|
37
|
+
"@types/npmcli__package-json": "^4.0.4",
|
|
38
|
+
"@types/sprintf-js": "^1",
|
|
39
|
+
"commitizen": "^4.3.1",
|
|
40
|
+
"commitlint": "^19.8.1",
|
|
41
|
+
"eslint": "^9.30.1",
|
|
42
|
+
"eslint-config-prettier": "^10.1.5",
|
|
43
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
44
|
+
"eslint-plugin-import-x": "^4.16.1",
|
|
45
|
+
"eslint-plugin-prettier": "^5.5.1",
|
|
46
|
+
"husky": "^9.1.7",
|
|
47
|
+
"inquirer": "9",
|
|
48
|
+
"lint-staged": "^16.1.2",
|
|
49
|
+
"prettier": "^3.6.2",
|
|
50
|
+
"rollup": "^4.44.2",
|
|
51
|
+
"rollup-plugin-auto-external": "^2.0.0",
|
|
52
|
+
"semantic-release": "^24.2.7",
|
|
53
|
+
"tslib": "^2.8.1",
|
|
54
|
+
"typescript": "^5.8.3",
|
|
55
|
+
"typescript-eslint": "^8.35.1"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=22"
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"lib/"
|
|
62
|
+
],
|
|
63
|
+
"homepage": "https://github.com/ayan4m1/vast-ai-provisioner#readme",
|
|
64
|
+
"license": "MIT",
|
|
65
|
+
"main": "n/a",
|
|
66
|
+
"module": "lib/index.js",
|
|
67
|
+
"name": "vast-ai-provisioner",
|
|
68
|
+
"packageManager": "yarn@4.9.4",
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "git+https://github.com/ayan4m1/vast-ai-provisioner.git"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "rollup -c --configPlugin typescript",
|
|
75
|
+
"develop": "rollup -c -w --configPlugin typescript",
|
|
76
|
+
"lint": "eslint ./src/**/*.ts",
|
|
77
|
+
"prepack": "rollup -c --configPlugin typescript",
|
|
78
|
+
"test": "jest"
|
|
79
|
+
},
|
|
80
|
+
"type": "module",
|
|
81
|
+
"types": "lib/index.d.ts",
|
|
82
|
+
"version": "1.0.0"
|
|
83
|
+
}
|