Skip to content

Commit bcd2e0a

Browse files
committed
Runpod: New action components
1 parent 1910739 commit bcd2e0a

File tree

10 files changed

+654
-8
lines changed

10 files changed

+654
-8
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import app from "../../runpod.app.mjs";
2+
import mutations from "../../common/mutations.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "runpod-create-pod",
7+
name: "Create Pod",
8+
description: "Creates a new pod with the specified parameters. [See the documentation](https://docs.runpod.io/sdks/graphql/manage-pods#create-spot-pod)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
bidPerGpu: {
14+
propDefinition: [
15+
app,
16+
"bidPerGpu",
17+
],
18+
},
19+
cloudType: {
20+
type: "string",
21+
label: "Cloud Type",
22+
description: "The type of cloud to use for the pod.",
23+
options: [
24+
"SECURE",
25+
"COMMUNITY",
26+
"ALL",
27+
],
28+
},
29+
gpuCount: {
30+
propDefinition: [
31+
app,
32+
"gpuCount",
33+
],
34+
},
35+
volumeInGb: {
36+
type: "integer",
37+
label: "Volume In GB",
38+
description: "The size of the volume in GB.",
39+
},
40+
containerDiskInGb: {
41+
type: "integer",
42+
label: "Container Disk In GB",
43+
description: "The size of the container disk in GB.",
44+
},
45+
minVcpuCount: {
46+
type: "integer",
47+
label: "Minimum VCPU Count",
48+
description: "The minimum number of VCPUs.",
49+
},
50+
minMemoryInGb: {
51+
type: "integer",
52+
label: "Minimum Memory In GB",
53+
description: "The minimum memory size in GB.",
54+
},
55+
gpuTypeId: {
56+
propDefinition: [
57+
app,
58+
"gpuTypeId",
59+
],
60+
},
61+
name: {
62+
type: "string",
63+
label: "Name",
64+
description: "The name of the pod.",
65+
},
66+
imageName: {
67+
type: "string",
68+
label: "Image Name",
69+
description: "The name of the image to use for the pod.",
70+
},
71+
ports: {
72+
type: "string",
73+
label: "Ports",
74+
description: "The ports to use for the pod.",
75+
},
76+
volumeMountPath: {
77+
type: "string",
78+
label: "Volume Mount Path",
79+
description: "The path where the volume will be mounted.",
80+
},
81+
env: {
82+
type: "string[]",
83+
label: "Environment Variables",
84+
description: "The environment variables to set for the pod. Each row should be formated with JSON string like this `{\"key\": \"ENV_NAME\", \"value\": \"ENV_VALUE\"}`",
85+
optional: true,
86+
},
87+
dockerArgs: {
88+
type: "string",
89+
label: "Docker Args",
90+
description: "The arguments to pass to the docker command.",
91+
optional: true,
92+
},
93+
startJupyter: {
94+
type: "boolean",
95+
label: "Start Jupyter",
96+
description: "Whether to start Jupyter for the pod.",
97+
optional: true,
98+
},
99+
startSsh: {
100+
type: "boolean",
101+
label: "Start SSH",
102+
description: "Whether to start SSH for the pod.",
103+
optional: true,
104+
},
105+
stopAfter: {
106+
type: "string",
107+
label: "Stop After",
108+
description: "The duration after which the pod will be stopped.",
109+
optional: true,
110+
},
111+
supportPublicIp: {
112+
type: "boolean",
113+
label: "Support Public IP",
114+
description: "Whether to support public IP for the pod.",
115+
optional: true,
116+
},
117+
templateId: {
118+
type: "string",
119+
label: "Template ID",
120+
description: "The ID of the template to use for the pod.",
121+
optional: true,
122+
},
123+
},
124+
methods: {
125+
createPod(variables) {
126+
return this.app.makeRequest({
127+
query: mutations.createPod,
128+
variables,
129+
});
130+
},
131+
},
132+
async run({ $ }) {
133+
const {
134+
createPod,
135+
bidPerGpu,
136+
cloudType,
137+
gpuCount,
138+
volumeInGb,
139+
containerDiskInGb,
140+
minVcpuCount,
141+
minMemoryInGb,
142+
gpuTypeId,
143+
name,
144+
imageName,
145+
ports,
146+
volumeMountPath,
147+
env,
148+
dockerArgs,
149+
startJupyter,
150+
startSsh,
151+
stopAfter,
152+
supportPublicIp,
153+
templateId,
154+
} = this;
155+
156+
const response = await createPod({
157+
input: utils.cleanInput({
158+
bidPerGpu,
159+
cloudType,
160+
gpuCount,
161+
volumeInGb,
162+
containerDiskInGb,
163+
minVcpuCount,
164+
minMemoryInGb,
165+
gpuTypeId,
166+
name,
167+
imageName,
168+
ports,
169+
volumeMountPath,
170+
env: utils.parseArray(env),
171+
dockerArgs,
172+
startJupyter,
173+
startSsh,
174+
stopAfter,
175+
supportPublicIp,
176+
templateId,
177+
}),
178+
});
179+
$.export("$summary", `Successfully created a new pod with ID \`${response.id}\`.`);
180+
return response;
181+
},
182+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import app from "../../runpod.app.mjs";
2+
import queries from "../../common/queries.mjs";
3+
4+
export default {
5+
key: "runpod-get-pod",
6+
name: "Get Pod Details",
7+
description: "Get details of a pod by ID. [See the documentation](https://docs.runpod.io/sdks/graphql/manage-pods#get-pod-by-id).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
podId: {
13+
description: "The ID of the pod to get details for.",
14+
propDefinition: [
15+
app,
16+
"podId",
17+
],
18+
},
19+
},
20+
methods: {
21+
getPodDetails(variables) {
22+
return this.app.makeRequest({
23+
query: queries.getPod,
24+
variables,
25+
});
26+
},
27+
},
28+
async run({ $ }) {
29+
const {
30+
getPodDetails,
31+
podId,
32+
} = this;
33+
34+
const response = await getPodDetails({
35+
input: {
36+
podId,
37+
},
38+
});
39+
$.export("$summary", `Succesfully retrieved details for pod with ID \`${response.id}\`.`);
40+
return response;
41+
},
42+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import app from "../../runpod.app.mjs";
2+
import mutations from "../../common/mutations.mjs";
3+
4+
export default {
5+
key: "runpod-start-pod",
6+
name: "Start Pod",
7+
description: "Starts a stopped pod, making it available for use. [See the documentation](https://docs.runpod.io/sdks/graphql/manage-pods#start-spot-pod)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
podId: {
13+
propDefinition: [
14+
app,
15+
"podId",
16+
],
17+
},
18+
gpuCount: {
19+
propDefinition: [
20+
app,
21+
"gpuCount",
22+
],
23+
},
24+
bidPerGpu: {
25+
propDefinition: [
26+
app,
27+
"bidPerGpu",
28+
],
29+
},
30+
},
31+
methods: {
32+
startPod(variables) {
33+
return this.app.makeRequest({
34+
query: mutations.startPod,
35+
variables,
36+
});
37+
},
38+
},
39+
async run({ $ }) {
40+
const {
41+
startPod,
42+
podId,
43+
gpuCount,
44+
bidPerGpu,
45+
} = this;
46+
47+
const response = await startPod({
48+
input: {
49+
podId,
50+
gpuCount,
51+
bidPerGpu: parseFloat(bidPerGpu),
52+
},
53+
});
54+
55+
$.export("$summary", `Sucessfully started pod with ID \`${response.id}\`.`);
56+
return response;
57+
},
58+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import app from "../../runpod.app.mjs";
2+
import mutations from "../../common/mutations.mjs";
3+
4+
export default {
5+
key: "runpod-stop-pod",
6+
name: "Stop Pod",
7+
description: "Stops a running pod, freeing up resources and preventing further charges. [See the documentation](https://docs.runpod.io/sdks/graphql/manage-pods#stop-pods)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
podId: {
13+
description: "The ID of the pod to stop.",
14+
propDefinition: [
15+
app,
16+
"podId",
17+
],
18+
},
19+
incrementVersion: {
20+
type: "boolean",
21+
label: "Increment Version",
22+
description: "Whether to increment the pod version after stopping it.",
23+
optional: true,
24+
},
25+
},
26+
methods: {
27+
stopPod(variables) {
28+
return this.app.makeRequest({
29+
query: mutations.stopPod,
30+
variables,
31+
});
32+
},
33+
},
34+
async run({ $ }) {
35+
const {
36+
stopPod,
37+
podId,
38+
incrementVersion,
39+
} = this;
40+
41+
const response = await stopPod({
42+
input: {
43+
podId,
44+
incrementVersion,
45+
},
46+
});
47+
48+
$.export("$summary", `Succesfully stopped pod with ID \`${response.id}\`.`);
49+
50+
return response;
51+
},
52+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { gql } from "graphql-request";
2+
3+
export default {
4+
createPod: gql`
5+
mutation createPod($input: PodRentInterruptableInput!) {
6+
podRentInterruptable(input: $input) {
7+
id
8+
}
9+
}
10+
`,
11+
startPod: gql`
12+
mutation startPod($input: PodBidResumeInput!) {
13+
podResume(input: $input) {
14+
id
15+
}
16+
}
17+
`,
18+
stopPod: gql`
19+
mutation stopPod($input: PodStopInput!) {
20+
podStop(input: $input) {
21+
id
22+
}
23+
}
24+
`,
25+
};

0 commit comments

Comments
 (0)