A mechanism intended to run in k8s as a workload (e.g. cronjob) and consume Cast.AI API.
This sub-repo is provided as a blueprint - so one can clone and design their own functions/docker-image.
Please regard this project as a framework, additional functions may be added in the future.
First things first - Install cluster hibernate and configure it. https://github.com/castai/hibernate
- This project relies on an API key stored in one of the projects secrets.
- Secret can also be created manually (instructions on how to set key in hibernate project)
- Defined in both pod and cronjob as follows
valueFrom:
secretKeyRef:
name: castai-hibernate
key: API_KEY
Next there are several steps to achieve your end-goal of a custom CAST.AI API consuming bot.
- Design your function (see src/functions/example.py for an example)
- The function is built to digest a BotExecutionConfig (src/models/bot_execution_config.py) to make it easier to define inputs and env vars
- The config is passed via a config-map that needs to be deployed (see api-bot-helper-function-config-example_configmap.yaml for an example)
- The config can also be passed for testing purposed using src/function_config.json
- Build you image using helper_scripts/build-and_push.py
- Rename helper_scritps/secrets.env.template to helper_scritps/secrets.env for registry credentials
- Set your Image name/tag in helper_scritps/constants.py
- Run build-and-push.py to create your image that will be used in the k8s bot workload
- Set your image name/tag in either api-bot-helper_pod.yaml or api-bot-helper_cronjob.yaml
- you can also create your own type of k8s workload
- A configmap like api-bot-helper-function-config-example_configmap.yaml and the workload needs to be deployed in your cluster
- In order to test the functionality locally before deploying:
- Configure src/function_config.json with right settings
- Set the
TEST_RUN
in main.py to True
Green section below includes a more bare-boned approach - just create whatever script in any language you want. Reference the script as entrypoint in Dockerimage make sure to add the required variables as env_vars as in the example.
castai-api-bot-helper
βββ bare_bones
ββββββ src
βββββββββ script_example.py
ββββββ helper_scripts
βββββββββ build-and-push.py
βββββββββ build-and-push.sh
βββββββββ constants.py
βββββββββ requirements.txt
βββββββββ secrets.env
βββββββββ secrets.env.template
ββββββ api-bot-helper_cronjob.yaml
ββββββ api-bot-helper_pod.yaml
ββββββ Dockerfile
βββ helper_scripts
ββββββ build-and-push.py
ββββββ constants.py
ββββββ requirements.txt
ββββββ secrets.env
ββββββ secrets.env.template
βββ src
βββββ functions
ββββββββ example.py
βββββ models
βββββββββ bot.py
βββββββββ bot_execution_config.py
ββββββ services
βββββββββ api_requests_svc.py
βββββββββ request_handle_svc.py
ββββββ constants.py
ββββββ function_confi.json
ββββββ main.py
ββββββ requirements.txt
ββββββ test_config.env
ββββββ test_config.env.template
βββ .dockerignore
βββ .gitignore
βββ api-bot-helper-function-config-example_configmap.yaml
βββ api-bot-helper_cronjob.yaml
βββ api-bot-helper_pod.yaml
βββ Dockerfile
βββ LICENSE.txt
βββ README.md
Distributed under the MIT License. See LICENSE.txt
for more information.