You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lab5.md
+69-35Lines changed: 69 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ We're going to use OpenFaaS functions to create a GitHub bot named `issue-bot`.
13
13
14
14
The job of issue-bot is to triage new issues by analysing the sentiment of the "description" field, it will then apply a label of *positive* or *review*. This will help the maintainers with their busy schedule so they can prioritize which issues to look at first.
15
15
16
-

16
+

17
17
18
18
## Get a GitHub account
19
19
@@ -23,58 +23,92 @@ The job of issue-bot is to triage new issues by analysing the sentiment of the "
23
23
24
24
Note: we will only use this repository as a testing ground for creating Issues. You don't need to commit any code there.
25
25
26
-
## Set up a tunnel with ngrok
26
+
## Set up a tunnel with inlets
27
27
28
-
You will need to receive incoming webhooks from GitHub. In production you will have a clear route for incoming traffic but within the constraints of a workshop we have to be creative.
28
+
You will need to receive incoming webhooks from GitHub. Fortunately, inlets makes this very quick and simple. It's available on a monthly or annual subscription, so if you are not sure if you are going to need it all year, you can just pay for a single month.
29
29
30
-
Open a new Terminal and type in:
30
+
inlets has a Kubernetes integration called the inlets-operator. You can use it to setup LoadBalancers or Ingress with TLS. It works by creating a cloud VM for you and running a tunnel server there, it then runs a tunnel client as a Pod for you and you get incoming traffic.
31
31
32
+
Create a write access token under the API page of your preferred cloud provider, such as DigitalOcean, then save the contents to `digital-ocean-api-token.txt`.
33
+
34
+
After setting your subscription, save your key to `$HOME/.inlets/LICENSE` and run the following:
35
+
36
+
```bash
37
+
arkade install inlets-operator \
38
+
--provider digitalocean \
39
+
--region lon1 \
40
+
--token-file $HOME/digital-ocean-api-token.txt
32
41
```
33
-
$ kubectl -n openfaas run \
34
-
--image=alexellis2/ngrok-admin \
35
-
--port=4040 \
36
-
ngrok -- http gateway:8080
37
42
38
-
$ kubectl -n openfaas expose deployment ngrok \
39
-
--type=NodePort \
40
-
--name=ngrok
43
+
This will deploy the inlets-operator and instruct it to provision new hosts on DigitalOcean into the London region for your tunnel servers. Other providers and regions are available, [see the docs for more](https://docs.inlets.dev/reference/inlets-operator/).
44
+
45
+
## Log into your gateway with the Gateway's public IP
46
+
47
+
Retrieve your gateway password with the message from:
Use the built-in UI of `ngrok` at http://127.0.0.1:4040 to find your HTTP URL. You will be given a URL that you can access over the Internet, it will connect directly to your OpenFaaS API Gateway.
53
+
The public IP for the LoadBalancer will take around 10-30 seconds to appear:
46
54
47
-
> Note: `ngrok` also provides a JSON API at `http://127.0.0.1:4040/api/tunnels`
> Note: you will notice that because we used the HTTPS url, that the warning about using an insecure certificate disappeared. The OpenFaaS documentation shows [how to setup Ingress with TLS for OpenFaaS](https://docs.openfaas.com/reference/ssl/kubernetes-with-cert-manager/). If you're using a remote cluster then you can try this after completing all the labs.
99
+
That'll now give you a custom TLS record for `https://openfaas.example.com`
68
100
69
101
## Create a webhook receiver `issue-bot`
70
102
71
-
```
72
-
$ faas-cli new --lang python3 issue-bot --prefix="<your-docker-username-here>"
103
+
```bash
104
+
export OPENFAAS_PREFIX="docker.io/your-username"
105
+
$ faas-cli new --lang python3 \
106
+
issue-bot
73
107
```
74
108
75
109
Now edit the function's YAML file `issue-bot.yml` and add an environmental variable of `write_debug: true`:
76
110
77
-
```
111
+
```yaml
78
112
provider:
79
113
name: openfaas
80
114
gateway: http://127.0.0.1:8080
@@ -83,14 +117,14 @@ functions:
83
117
issue-bot:
84
118
lang: python3
85
119
handler: ./issue-bot
86
-
image: <user-name>/issue-bot
120
+
image: docker.io/your-username/issue-bot
87
121
environment:
88
122
write_debug: true
89
123
```
90
124
91
125
* Build, push and deploy the function with
92
126
93
-
```
127
+
```bash
94
128
$ faas-cli up -f ./issue-bot.yml
95
129
```
96
130
@@ -100,15 +134,15 @@ Log back into GitHub and navigate to your repository *bot-tester*
100
134
101
135
Click *Settings* -> *Webhooks* -> *Add Webhook*
102
136
103
-

137
+

104
138
105
-
Now enter the URL you were given from `ngrok` adding `/function/issue-bot` to the end, for example:
139
+
Now enter the URL you were given from inlets or your custom domain adding `/function/issue-bot` to the end, for example:
106
140
107
141
```
108
-
http://fuh83fhfj.ngrok.io/function/issue-bot
142
+
https://openfaas.example.com
109
143
```
110
144
111
-

145
+

112
146
113
147
For *Content-type* select: *application/json*
114
148
@@ -118,7 +152,7 @@ And select "Let me select individual events"
118
152
119
153
For events select **Issues** and **Issue comment**
120
154
121
-

155
+

122
156
123
157
## Check it worked
124
158
@@ -138,7 +172,7 @@ You can see the payload sent via GitHub by typing in `docker service logs -f iss
138
172
139
173
The GitHub Webhooks page will also show every message sent under "Recent Deliveries", you can replay a message here and see the response returned by your function.
140
174
141
-

175
+

142
176
143
177
### Deploy SentimentAnalysis function
144
178
@@ -214,7 +248,7 @@ Use the CLI to build and deploy the function:
214
248
$ faas-cli up -f issue-bot.yml
215
249
```
216
250
217
-
Now create a new issue in the `bot-tester` repository. GitHub will respond by sending a JSON payload to your function via the Ngrok tunnel we set up at the start.
251
+
Now create a new issue in the `bot-tester` repository. GitHub will respond by sending a JSON payload to your function via the Inlets tunnel we configured earlier.
218
252
219
253
You can view the request/response directly on GitHub - navigate to *Settings* -> *Webhook* as below:
0 commit comments