Skip to content

Commit

Permalink
Merge pull request #96 from golemfactory/mgordel/JST-812/local-gvmi-e…
Browse files Browse the repository at this point in the history
…xample

docs: added example for serving local gvmi
  • Loading branch information
mgordel authored Jul 18, 2024
2 parents 920e96e + c81738c commit 3d3428a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/local-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:latest
WORKDIR /golem/work
RUN echo "hello from my local image 👋" > /golem/work/hello.txt
Binary file added examples/local-image/alpine.gvmi
Binary file not shown.
34 changes: 34 additions & 0 deletions examples/local-image/serveLocalGvmi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { TaskExecutor } from "@golem-sdk/task-executor";
import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
import { fileURLToPath } from "url";

const DIR_NAME = fileURLToPath(new URL(".", import.meta.url));

(async function main() {
const executor = await TaskExecutor.create({
logger: pinoPrettyLogger({ level: "info" }),
demand: {
workload: {
// if the image url starts with "file://" it will be treated as a local file
// and the sdk will automatically serve it to the provider
imageUrl: `file://${DIR_NAME}/alpine.gvmi`,
},
},
market: {
rentHours: 0.5,
pricing: {
model: "linear",
maxStartPrice: 0.5,
maxCpuPerHourPrice: 1.0,
maxEnvPerHourPrice: 0.5,
},
},
});
try {
await executor.run(async (exe) => console.log((await exe.run("cat hello.txt")).stdout));
} catch (error) {
console.error("Computation failed:", error);
} finally {
await executor.shutdown();
}
})();
3 changes: 2 additions & 1 deletion tests/examples/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@
{ "cmd": "node", "path": "examples/docs-examples/examples/executing-tasks/observing-events.mjs" },
{ "cmd": "node", "path": "examples/docs-examples/examples/outbound/npm-install.mjs" },
{ "cmd": "node", "path": "examples/docs-examples/examples/outbound/outbound-basic.mjs" },
{ "cmd": "node", "path": "examples/docs-examples/examples/outbound/whitelist-checker.mjs" }
{ "cmd": "node", "path": "examples/docs-examples/examples/outbound/whitelist-checker.mjs" },
{ "cmd": "tsx", "path": "examples/local-image/serveLocalGvmi.ts" }
]

0 comments on commit 3d3428a

Please sign in to comment.