Skip to content

Commit

Permalink
feat: sample function for deno runtime (#27)
Browse files Browse the repository at this point in the history
* feat: added simple typescript sample

Signed-off-by: Thomas Schuetz <thomas.schuetz@dynatrace.com>

* doc: updated documentation

Signed-off-by: Thomas Schuetz <thomas.schuetz@dynatrace.com>

* feat: added DATA environment variable

Signed-off-by: Thomas Schuetz <thomas.schuetz@dynatrace.com>

* feat: added DATA environment variable

Signed-off-by: Thomas Schuetz <thomas.schuetz@dynatrace.com>

* feat: added slack function

Signed-off-by: Thomas Schuetz <thomas.schuetz@dynatrace.com>

* feat: added slack function

Signed-off-by: Thomas Schuetz <thomas.schuetz@dynatrace.com>

Signed-off-by: Thomas Schuetz <thomas.schuetz@dynatrace.com>
  • Loading branch information
thschue authored Sep 20, 2022
1 parent c8800ee commit 2501e46
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
14 changes: 12 additions & 2 deletions functions-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
```

2 changes: 1 addition & 1 deletion functions-runtime/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -eu

deno run --allow-net $SCRIPT
deno run --allow-net --allow-env=DATA,SECURE_DATA "$SCRIPT"
2 changes: 2 additions & 0 deletions functions-runtime/samples/ts/hello-world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let message: string = 'Hello, World!';
console.log(message);
20 changes: 20 additions & 0 deletions functions-runtime/samples/ts/schedule.ts
Original file line number Diff line number Diff line change
@@ -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);


15 changes: 15 additions & 0 deletions functions-runtime/samples/ts/slack.ts
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2501e46

Please sign in to comment.