Skip to content

Commit 1fe4b05

Browse files
authored
Merge pull request #71 from webup/main
feat(node): initialize knative and async samples
2 parents 02038be + 5fffe54 commit 1fe4b05

5 files changed

Lines changed: 175 additions & 0 deletions

File tree

functions/node/async-bindings.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
apiVersion: core.openfunction.io/v1beta1
2+
kind: Function
3+
metadata:
4+
name: sample-node-async-bindings
5+
spec:
6+
version: v2.0.0
7+
image: your-docker-registry/image:tag
8+
# imageCredentials:
9+
# name: your-docker-registry-secret
10+
# build:
11+
# builder: openfunction/builder-node:v2-16.13
12+
# env:
13+
# FUNC_NAME: tryKnative
14+
# srcRepo:
15+
# url: https://github.com/OpenFunction/samples.git
16+
# sourceSubPath: functions/node/src
17+
# revision: main
18+
# app port default to "8080"
19+
# port: 8080
20+
serving:
21+
# default to knative
22+
runtime: async
23+
annotations:
24+
# Dapr annotations: https://docs.dapr.io/reference/arguments-annotations-overview/
25+
# default to "grpc"
26+
dapr.io/app-protocol: http
27+
# default to "info"
28+
dapr.io/log-level: debug
29+
# default to "true"
30+
dapr.io/log-as-json: 'false'
31+
template:
32+
containers:
33+
- name: function
34+
imagePullPolicy: Always
35+
params:
36+
# default to FUNC_NAME value
37+
FUNCTION_TARGET: tryAsync
38+
DEBUG: common:*,ofn:*
39+
inputs:
40+
- name: mqtt-input
41+
component: mqtt-in
42+
outputs:
43+
- name: mqtt-output
44+
component: mqtt-out
45+
operation: create
46+
bindings:
47+
# Dapr MQTT Binding: https://docs.dapr.io/reference/components-reference/supported-bindings/mqtt/
48+
mqtt-in:
49+
type: bindings.mqtt
50+
version: v1
51+
metadata:
52+
- name: consumerID
53+
value: '{uuid}'
54+
- name: url
55+
value: tcp://admin:public@emqx:1883
56+
- name: topic
57+
value: in
58+
mqtt-out:
59+
type: bindings.mqtt
60+
version: v1
61+
metadata:
62+
- name: consumerID
63+
value: '{uuid}'
64+
- name: url
65+
value: tcp://admin:public@emqx:1883
66+
- name: topic
67+
value: out

functions/node/async-pubsub.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
apiVersion: core.openfunction.io/v1beta1
2+
kind: Function
3+
metadata:
4+
name: sample-node-async-pubsub
5+
spec:
6+
version: v2.0.0
7+
image: your-docker-registry/image:tag
8+
# imageCredentials:
9+
# name: your-docker-registry-secret
10+
# build:
11+
# builder: openfunction/builder-node:v2-16.13
12+
# env:
13+
# FUNC_NAME: tryKnative
14+
# srcRepo:
15+
# url: https://github.com/OpenFunction/samples.git
16+
# sourceSubPath: functions/node/src
17+
# revision: main
18+
# app port default to "8080"
19+
# port: 8080
20+
serving:
21+
# default to knative
22+
runtime: async
23+
annotations:
24+
# Dapr annotations: https://docs.dapr.io/reference/arguments-annotations-overview/
25+
# default to "grpc"
26+
dapr.io/app-protocol: http
27+
# default to "info"
28+
dapr.io/log-level: debug
29+
# default to "true"
30+
dapr.io/log-as-json: 'false'
31+
template:
32+
containers:
33+
- name: function
34+
imagePullPolicy: Always
35+
params:
36+
# default to FUNC_NAME value
37+
FUNCTION_TARGET: tryAsync
38+
DEBUG: common:*,ofn:*
39+
inputs:
40+
- name: mqtt-sub
41+
component: mqtt-pubsub
42+
topic: sub
43+
outputs:
44+
- name: mqtt-pub
45+
component: mqtt-pubsub
46+
topic: pub
47+
pubsub:
48+
# Dapr MQTT PubSub: https://docs.dapr.io/reference/components-reference/supported-pubsub/setup-mqtt/
49+
mqtt-pubsub:
50+
type: pubsub.mqtt
51+
version: v1
52+
metadata:
53+
- name: consumerID
54+
value: '{uuid}'
55+
- name: url
56+
value: tcp://admin:public@emqx:1883
57+
- name: qos
58+
value: 1

functions/node/knative.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: core.openfunction.io/v1beta1
2+
kind: Function
3+
metadata:
4+
name: sample-node-knative
5+
spec:
6+
version: v2.0.0
7+
image: your-docker-registry/image:tag
8+
# imageCredentials:
9+
# name: your-docker-registry-secret
10+
# build:
11+
# builder: openfunction/builder-node:v2-16.13
12+
# env:
13+
# FUNC_NAME: tryKnative
14+
# srcRepo:
15+
# url: https://github.com/OpenFunction/samples.git
16+
# sourceSubPath: functions/node/src
17+
# revision: main
18+
# app port default to "8080"
19+
# port: 8080
20+
serving:
21+
runtime: knative
22+
scaleOptions:
23+
minReplicas: 0
24+
maxReplicas: 2
25+
template:
26+
containers:
27+
- name: function
28+
imagePullPolicy: Always
29+
params:
30+
# default to "production"
31+
NODE_ENV: dev
32+
# Node.js debug wildcards
33+
DEBUG: common:*,ofn:*

functions/node/src/index.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const tryKnative = (req, res) => {
2+
res.send(`Hello, ${req.query.u || 'World'}!`);
3+
};
4+
5+
export const tryAsync = (ctx, data) => {
6+
console.log('Data received: %o', data);
7+
ctx.send(data);
8+
};

functions/node/src/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"main": "index.mjs",
3+
"scripts": {
4+
"start": "functions-framework --target=tryKnative"
5+
},
6+
"dependencies": {
7+
"@openfunction/functions-framework": "^0.4.1"
8+
}
9+
}

0 commit comments

Comments
 (0)