-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kubectl example #175
base: main
Are you sure you want to change the base?
Add kubectl example #175
Changes from 16 commits
28371b5
32c9f53
ac7408d
1e03b0e
2397e04
2c2b660
a3b9ccb
4865819
f19775d
012bc60
9e381d6
29b9f6d
db2e38f
c9ccbc5
a62221e
e130d06
d8537fc
cc5e188
83fa002
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
tools: sys.write, kubectl, helm, browser | ||
|
||
1. Create a Namespace named vote but do not fail if it already exists | ||
2. Deploy in the vote namespace the application which yaml specification is available at https://luc.run/vote.yaml | ||
3. Use a single command to wait for all the Pods in the vote namespace to be ready | ||
4. Install Traefik ingress controller in kube-system namespace with helm only if it is not already installed in this namespace | ||
5. Make sure the Traefik Pod is in running status | ||
6. Wait for the IP address of the traefik Service to be available and save it in the file ./lb-ip.txt | ||
7. Create the file ./ingress.yaml and make sure it contains the yaml specification of an Ingress resource which exposes the vote-ui Service on vote.LBIP.nip.io and the result-ui Service on result.LBIP.nip.io, first making sure to replace the LBIP placeholders with the content of the file ./lb-ip.txt | ||
8. Create the Ingress resource specified in ./ingress.yaml | ||
9. Open a browser on vote.LBIP.nip.io but make sur to replace the LBIP placeholder with the content of lb-ip.txt in this URL first | ||
tylerslaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
--- | ||
name: kubectl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't remember if we discussed this, but this is technically a "safer" way to implement:
Can you do it this way or was there a particular reason you didn't? I can't recall the details of the convos we had around this. |
||
description: use kubectl command to manage k8s resources | ||
args: arguments: the arguments for the kubectl command | ||
|
||
!#/bin/bash | ||
|
||
kubectl ${arguments} | ||
|
||
--- | ||
name: helm | ||
description: use helm command to manage k8s charts | ||
args: arguments: the arguments for the helm command | ||
|
||
!#/bin/bash | ||
|
||
helm ${arguments} | ||
|
||
--- | ||
name: browser | ||
tools: sys.exec | ||
args: url: the url to open | ||
description: open a browser window | ||
|
||
You are only in charge of opening a browser window on the requested url | ||
You can only use the sys.exec tool to open a browser window | ||
Comment on lines
+34
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you not use our browser tool for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, I need to open a window so show the application. Can the browser tool open a window ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! That's what it is designed to do. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||
This example shows how to use GPTScript to run regular tasks. It involves the creation of a VM and defines a crontab entry onto that one. | ||||||
|
||||||
This example checks if a specific URL is reachable and sends the status code to an external webhook. If you want to test this example, you need to follow the steps below: | ||||||
|
||||||
- Create a DigitalOcean PAT token and export it in the DIGITALOCEAN_ACCESS_TOKEN environment variable | ||||||
|
||||||
- Create a new ssh key on your local machin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
|
||||||
``` | ||||||
ssh-keygen -f /tmp/do_gptscript | ||||||
``` | ||||||
|
||||||
- Define a new ssh key in DigitalOcean using the public part of the ssh key created above and call it *gptscript* | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
|
||||||
- Get a token from [https://webhooks.app](https://webhooks.app) | ||||||
|
||||||
![webhooks](./picts/webhooks-1.png) | ||||||
|
||||||
Note: your token will be different | ||||||
|
||||||
- Run gptscript example using this token | ||||||
|
||||||
``` | ||||||
gptscript --cache=false ./regular-task.gpt --url https://fakely.app --token 1e105ea8bef80ca6aba7c8953c34d3 | ||||||
``` | ||||||
|
||||||
- Check the message coming every minute on the [Webhooks dashboard](https://webhooks.app/dashboard) | ||||||
|
||||||
![webhooks](./picts/webhooks-2.png) | ||||||
|
||||||
- Once you'r done do not forget to remove the DigitalOcean VM created in the process | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
tylerslaton marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
tools: create-regular-task | ||
args: url: URL of the website to check | ||
args: token: webhook token | ||
|
||
Create a task which verifies every minute if the website ${url} is reachable and sends the status code to the following HTTP POST request: | ||
- URL is https://webhooks.app/data | ||
- Authorization bearer is ${token} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is just an example, but it is bad practice to hand credentials to the LLM, so I think this should be changed a bit. Tokens should only be handled by pure code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're totally right. I'll change that to make sure the token is retrieved beforehand and is not provided to the LLM. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've modified the script to that the token is not sent to the LLM |
||
- A json payload must be returned, containing a "message" property with the value of the ${url} and the status code returned | ||
|
||
--- | ||
tools: create-vm, create-crontab-entry | ||
name: create-regular-task | ||
decription: Manage the creation of a crontab on a remove VM | ||
args: command: command to be run in a crontab without the schedule part | ||
args: schedule: schedule to be used in a crontab | ||
|
||
Perform the actions in the following order: | ||
|
||
1. Create a virtual machine on DigitalOcean, wait for its IP to be returned and save it in ./vm.ip | ||
2. Create a crontab entry for command ${command} and schedule ${schedule} in the VM which IP address is in file ./vm.ip | ||
|
||
--- | ||
tools: sys.exec, sys.write | ||
name: create-crontab-entry | ||
description: Create a crontab entry in a remote VM | ||
args: command: command to run in a crontab on the remote VM | ||
args: schedule: schedule for the crontab | ||
|
||
Perform the step in this exact order taking into account that if you need to call a ssh command you must use user root and the IP address which value is in ./vm.ip | ||
|
||
1. Create a bash file containing the ${command} to run without the schedule part, make it executable, and make sure the components are correctly escaped first. | ||
2. Send this file to the remote VM via ssh saving it to /tmp/cron.sh on the remove VM | ||
3. Create a crontab entry calling /tmp/cron.sh file for the schedule specified in the ${command} | ||
|
||
--- | ||
tools: sys.exec | ||
name: create-vm | ||
description: create a virtual machine on DigitalOcean | ||
|
||
You are an operator which can use the doctl command line tool to interact with DigitalOcean infrastructure | ||
|
||
Perform the actions in this exact order: | ||
|
||
1. Get the ID of the ssh-key named gptscript and save it in ./key.id | ||
2. Create a Virtual Machine in the new-york datacenter named cron making sure to provide the id from ./key.id as the ssh-key of the new droplet | ||
3. Wait for the VM to be up and running and save its IP address in ./vm.ip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: