How to Write Custom Actions
Custom Kleinkram actions are implemented as Docker containers. Inside the container, you interact with the Kleinkram platform using the Kleinkram CLI. The Kleinkram CLI is a Python package installable via pip.
Download and List Files inside a Kleinkram Action
The following example shows how to create a simple action that downloads data from a mission and lists the files.
FROM python:latest
# Install Kleinkram CLI
RUN pip install kleinkram --force-reinstall
# Copy entrypoint script and make it executable
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]With the following entrypoint script:
#!/bin/bash
# Exit on error (non-zero exit codes mark action as failed)
set -e
echo "Get Started with Kleinkram Actions 🚀"
# Authenticate with the API key from environment variables
klein login --key "$KLEINKRAM_API_KEY"
echo "Download data from mission with UUID $KLEINKRAM_MISSION_UUID"
mkdir data
klein download -m "$KLEINKRAM_MISSION_UUID" --dest ./data
echo "List files of mission with UUID $KLEINKRAM_MISSION_UUID"
cd ./data || exit 1
ls -laEnvironment Variables
The following environment variables are available within the Docker container during action execution:
KLEINKRAM_API_KEY: API key for Kleinkram API authentication.KLEINKRAM_PROJECT_UUID: UUID of the project the action is running within.KLEINKRAM_MISSION_UUID: UUID of the mission the action is operating on.KLEINKRAM_ACTION_UUID: UUID of the currently running action.KLEINKRAM_API_ENDPOINT: Endpoint of the Kleinkram API.KLEINKRAM_S3_ENDPOINT: Endpoint of the Kleinkram S3 storage.
Deprecated Environment Variables
The following environment variables are deprecated and will be removed in the future:
APIKEY(UseKLEINKRAM_API_KEYinstead)PROJECT_UUID(UseKLEINKRAM_PROJECT_UUIDinstead)MISSION_UUID(UseKLEINKRAM_MISSION_UUIDinstead)ACTION_UUID(UseKLEINKRAM_ACTION_UUIDinstead)ENDPOINT(UseKLEINKRAM_API_ENDPOINTinstead)
Push Actions to Docker Hub
Kleinkram actions must be pushed to Docker Hub under a namespace defined by the VITE_DOCKER_HUB_NAMESPACE environment variable. If this is left empty, actions are allowed to be pushed on any namespace. To publish your action:
# login to docker hub
docker login
# build the image
docker build -t <namespace>/my-action .
# push the image
docker push <namespace>/my-action