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.