diff --git a/functions-runtime/README.md b/functions-runtime/README.md index 05e922e57d..868c90b36d 100644 --- a/functions-runtime/README.md +++ b/functions-runtime/README.md @@ -7,8 +7,18 @@ docker build -t keptnsandbox/klc-runtime:${VERSION} . ## Usage -### Docker +### Docker with function on webserver (function in this repo) ``` -docker run -e SCRIPT=https://deno.land/std/examples/welcome.ts -it keptnsandbox/klc-runtime:${VERSION} +docker run -e SCRIPT=https://raw.githubusercontent.com/keptn-sandbox/lifecycle-controller/main/functions-runtime/samples/ts/hello-world.ts -it keptnsandbox/klc-runtime:${VERSION} +``` + +### Docker with function and external data - scheduler +``` +docker run -e SCRIPT=https://raw.githubusercontent.com/keptn-sandbox/lifecycle-controller/main/functions-runtime/samples/ts/scheduler.ts -e DATA='{ "targetDate":"2025-04-16T06:55:31.820Z" }' -it keptnsandbox/klc-runtime:${VERSION} +``` + +### Docker with function and external secure data - slack +``` +docker run -e SCRIPT=https://raw.githubusercontent.com/keptn-sandbox/lifecycle-controller/main/functions-runtime/samples/ts/slack.ts -e SECURE_DATA='{ "slack_hook":"hook/parts","text":"this is my test message" }' -it keptnsandbox/klc-runtime:${VERSION} ``` diff --git a/functions-runtime/entrypoint.sh b/functions-runtime/entrypoint.sh index 894005a045..7a43492478 100755 --- a/functions-runtime/entrypoint.sh +++ b/functions-runtime/entrypoint.sh @@ -2,4 +2,4 @@ set -eu -deno run --allow-net $SCRIPT +deno run --allow-net --allow-env=DATA,SECURE_DATA "$SCRIPT" diff --git a/functions-runtime/samples/ts/hello-world.ts b/functions-runtime/samples/ts/hello-world.ts new file mode 100644 index 0000000000..ad656e6397 --- /dev/null +++ b/functions-runtime/samples/ts/hello-world.ts @@ -0,0 +1,2 @@ +let message: string = 'Hello, World!'; +console.log(message); diff --git a/functions-runtime/samples/ts/schedule.ts b/functions-runtime/samples/ts/schedule.ts new file mode 100644 index 0000000000..dc04ee02ea --- /dev/null +++ b/functions-runtime/samples/ts/schedule.ts @@ -0,0 +1,20 @@ +let text = Deno.env.get("DATA"); +let data; +if (text != "") { + data = JSON.parse(text); +} + +let targetDate = new Date(data.targetDate) +let dateTime = new Date(); + +if(targetDate < dateTime){ + console.log("Date has passed - ok"); + Deno.exit(0); +} else { + console.log("It's too early - failing"); + Deno.exit(1); +} + +console.log(targetDate); + + diff --git a/functions-runtime/samples/ts/slack.ts b/functions-runtime/samples/ts/slack.ts new file mode 100644 index 0000000000..453839155c --- /dev/null +++ b/functions-runtime/samples/ts/slack.ts @@ -0,0 +1,15 @@ +let text = Deno.env.get("SECURE_DATA"); +let data; +if (text != undefined) { + data = JSON.parse(text); +} + +const body = `{"text": "${data.text}"}`; + +console.log(body) +let resp = await fetch("https://hooks.slack.com/services/" + data.slack_hook, { + method: "POST", + body, +}); + +console.log(resp) \ No newline at end of file