working out the worker/execution interface
This commit is contained in:
116
scripts/build-pack-binaries.sh
Executable file
116
scripts/build-pack-binaries.sh
Executable file
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build pack binaries using Docker and extract them to ./packs/
|
||||
#
|
||||
# This script builds native pack binaries (sensors, etc.) in a Docker container
|
||||
# with GLIBC compatibility and extracts them to the appropriate pack directories.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/build-pack-binaries.sh
|
||||
#
|
||||
# The script will:
|
||||
# 1. Build pack binaries in a Docker container with GLIBC 2.36 (Debian Bookworm)
|
||||
# 2. Extract binaries to ./packs/core/sensors/
|
||||
# 3. Make binaries executable
|
||||
# 4. Clean up temporary container
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Script directory
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
|
||||
# Configuration
|
||||
IMAGE_NAME="attune-pack-builder"
|
||||
CONTAINER_NAME="attune-pack-binaries-tmp"
|
||||
DOCKERFILE="docker/Dockerfile.pack-binaries"
|
||||
|
||||
echo -e "${GREEN}Building pack binaries...${NC}"
|
||||
echo "Project root: ${PROJECT_ROOT}"
|
||||
echo "Dockerfile: ${DOCKERFILE}"
|
||||
echo ""
|
||||
|
||||
# Navigate to project root
|
||||
cd "${PROJECT_ROOT}"
|
||||
|
||||
# Check if Dockerfile exists
|
||||
if [[ ! -f "${DOCKERFILE}" ]]; then
|
||||
echo -e "${RED}Error: ${DOCKERFILE} not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build the Docker image
|
||||
echo -e "${YELLOW}Step 1/4: Building Docker image...${NC}"
|
||||
if DOCKER_BUILDKIT=1 docker build \
|
||||
-f "${DOCKERFILE}" \
|
||||
-t "${IMAGE_NAME}" \
|
||||
. ; then
|
||||
echo -e "${GREEN}✓ Image built successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Failed to build image${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a temporary container from the image
|
||||
echo -e "${YELLOW}Step 2/4: Creating temporary container...${NC}"
|
||||
if docker create --name "${CONTAINER_NAME}" "${IMAGE_NAME}" ; then
|
||||
echo -e "${GREEN}✓ Container created${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Failed to create container${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract binaries from the container
|
||||
echo -e "${YELLOW}Step 3/4: Extracting pack binaries...${NC}"
|
||||
|
||||
# Create target directories
|
||||
mkdir -p packs/core/sensors
|
||||
|
||||
# Copy timer sensor binary
|
||||
if docker cp "${CONTAINER_NAME}:/pack-binaries/attune-core-timer-sensor" "packs/core/sensors/attune-core-timer-sensor" ; then
|
||||
echo -e "${GREEN}✓ Extracted attune-core-timer-sensor${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Failed to extract timer sensor binary${NC}"
|
||||
docker rm "${CONTAINER_NAME}" 2>/dev/null || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make binaries executable
|
||||
chmod +x packs/core/sensors/attune-core-timer-sensor
|
||||
|
||||
# Verify binaries
|
||||
echo ""
|
||||
echo -e "${YELLOW}Verifying binaries:${NC}"
|
||||
file packs/core/sensors/attune-core-timer-sensor
|
||||
ldd packs/core/sensors/attune-core-timer-sensor || echo "(ldd failed - binary may be static or require different environment)"
|
||||
ls -lh packs/core/sensors/attune-core-timer-sensor
|
||||
|
||||
# Clean up temporary container
|
||||
echo ""
|
||||
echo -e "${YELLOW}Step 4/4: Cleaning up...${NC}"
|
||||
if docker rm "${CONTAINER_NAME}" ; then
|
||||
echo -e "${GREEN}✓ Temporary container removed${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Failed to remove temporary container (may already be removed)${NC}"
|
||||
fi
|
||||
|
||||
# Summary
|
||||
echo ""
|
||||
echo -e "${GREEN}════════════════════════════════════════${NC}"
|
||||
echo -e "${GREEN}Pack binaries built successfully!${NC}"
|
||||
echo -e "${GREEN}════════════════════════════════════════${NC}"
|
||||
echo ""
|
||||
echo "Binaries location:"
|
||||
echo " • packs/core/sensors/attune-core-timer-sensor"
|
||||
echo ""
|
||||
echo "These binaries are now ready to be used by the init-packs service"
|
||||
echo "when starting docker-compose."
|
||||
echo ""
|
||||
echo "To use them:"
|
||||
echo " docker compose up -d"
|
||||
echo ""
|
||||
@@ -237,19 +237,40 @@ class CorePackLoader:
|
||||
param_schema = json.dumps(action_data.get("parameters", {}))
|
||||
out_schema = json.dumps(action_data.get("output", {}))
|
||||
|
||||
# Parameter delivery and format (defaults: stdin + json for security)
|
||||
parameter_delivery = action_data.get("parameter_delivery", "stdin").lower()
|
||||
parameter_format = action_data.get("parameter_format", "json").lower()
|
||||
|
||||
# Validate parameter delivery method (only stdin and file allowed)
|
||||
if parameter_delivery not in ["stdin", "file"]:
|
||||
print(
|
||||
f" ⚠ Invalid parameter_delivery '{parameter_delivery}' for '{ref}', defaulting to 'stdin'"
|
||||
)
|
||||
parameter_delivery = "stdin"
|
||||
|
||||
# Validate parameter format
|
||||
if parameter_format not in ["dotenv", "json", "yaml"]:
|
||||
print(
|
||||
f" ⚠ Invalid parameter_format '{parameter_format}' for '{ref}', defaulting to 'json'"
|
||||
)
|
||||
parameter_format = "json"
|
||||
|
||||
cursor.execute(
|
||||
"""
|
||||
INSERT INTO action (
|
||||
ref, pack, pack_ref, label, description,
|
||||
entrypoint, runtime, param_schema, out_schema, is_adhoc
|
||||
entrypoint, runtime, param_schema, out_schema, is_adhoc,
|
||||
parameter_delivery, parameter_format
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
ON CONFLICT (ref) DO UPDATE SET
|
||||
label = EXCLUDED.label,
|
||||
description = EXCLUDED.description,
|
||||
entrypoint = EXCLUDED.entrypoint,
|
||||
param_schema = EXCLUDED.param_schema,
|
||||
out_schema = EXCLUDED.out_schema,
|
||||
parameter_delivery = EXCLUDED.parameter_delivery,
|
||||
parameter_format = EXCLUDED.parameter_format,
|
||||
updated = NOW()
|
||||
RETURNING id
|
||||
""",
|
||||
@@ -264,6 +285,8 @@ class CorePackLoader:
|
||||
param_schema,
|
||||
out_schema,
|
||||
False, # Pack-installed actions are not ad-hoc
|
||||
parameter_delivery,
|
||||
parameter_format,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
160
scripts/setup-test-rules.sh
Executable file
160
scripts/setup-test-rules.sh
Executable file
@@ -0,0 +1,160 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Script to create test rules for Attune
|
||||
# 1. Echo every second
|
||||
# 2. Sleep for 3 seconds every 5 seconds
|
||||
# 3. HTTP POST to httpbin.org every 10 seconds
|
||||
|
||||
API_URL="${ATTUNE_API_URL:-http://localhost:8080}"
|
||||
LOGIN="${ATTUNE_LOGIN:-test@attune.local}"
|
||||
PASSWORD="${ATTUNE_PASSWORD:-TestPass123!}"
|
||||
|
||||
echo "=== Attune Test Rules Setup ==="
|
||||
echo "API URL: $API_URL"
|
||||
echo "Login: $LOGIN"
|
||||
echo ""
|
||||
|
||||
# Authenticate
|
||||
echo "Authenticating..."
|
||||
TOKEN=$(curl -s -X POST "$API_URL/auth/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"login\":\"$LOGIN\",\"password\":\"$PASSWORD\"}" | jq -r '.data.access_token')
|
||||
|
||||
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
|
||||
echo "ERROR: Failed to authenticate"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ Authenticated"
|
||||
echo ""
|
||||
|
||||
# Check if core pack exists
|
||||
echo "Checking core pack..."
|
||||
PACK_EXISTS=$(curl -s "$API_URL/api/v1/packs" \
|
||||
-H "Authorization: Bearer $TOKEN" | jq -r '.data[] | select(.ref == "core") | .ref')
|
||||
|
||||
if [ "$PACK_EXISTS" != "core" ]; then
|
||||
echo "ERROR: Core pack not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ Core pack found"
|
||||
echo ""
|
||||
|
||||
# Create Rule 1: Echo every second
|
||||
echo "Creating Rule 1: Echo every 1 second..."
|
||||
RULE1=$(curl -s -X POST "$API_URL/api/v1/rules" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"ref": "test.echo_every_second",
|
||||
"label": "Echo Every Second",
|
||||
"description": "Echoes a message every second using interval timer",
|
||||
"pack_ref": "core",
|
||||
"action_ref": "core.echo",
|
||||
"trigger_ref": "core.intervaltimer",
|
||||
"enabled": true,
|
||||
"trigger_params": {
|
||||
"unit": "seconds",
|
||||
"interval": 1
|
||||
},
|
||||
"action_params": {
|
||||
"message": "Hello from 1-second timer! Time: {{trigger.payload.executed_at}}"
|
||||
}
|
||||
}')
|
||||
|
||||
RULE1_ID=$(echo "$RULE1" | jq -r '.data.id // .id // empty')
|
||||
if [ -z "$RULE1_ID" ]; then
|
||||
echo "ERROR: Failed to create rule 1"
|
||||
echo "$RULE1" | jq .
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ Rule 1 created (ID: $RULE1_ID)"
|
||||
echo ""
|
||||
|
||||
# Create Rule 2: Sleep 3 seconds every 5 seconds
|
||||
echo "Creating Rule 2: Sleep 3 seconds every 5 seconds..."
|
||||
RULE2=$(curl -s -X POST "$API_URL/api/v1/rules" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"ref": "test.sleep_every_5s",
|
||||
"label": "Sleep Every 5 Seconds",
|
||||
"description": "Sleeps for 3 seconds every 5 seconds",
|
||||
"pack_ref": "core",
|
||||
"action_ref": "core.sleep",
|
||||
"trigger_ref": "core.intervaltimer",
|
||||
"enabled": true,
|
||||
"trigger_params": {
|
||||
"unit": "seconds",
|
||||
"interval": 5
|
||||
},
|
||||
"action_params": {
|
||||
"seconds": 3
|
||||
}
|
||||
}')
|
||||
|
||||
RULE2_ID=$(echo "$RULE2" | jq -r '.data.id // .id // empty')
|
||||
if [ -z "$RULE2_ID" ]; then
|
||||
echo "ERROR: Failed to create rule 2"
|
||||
echo "$RULE2" | jq .
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ Rule 2 created (ID: $RULE2_ID)"
|
||||
echo ""
|
||||
|
||||
# Create Rule 3: HTTP POST to httpbin.org every 10 seconds
|
||||
echo "Creating Rule 3: HTTP POST to httpbin.org every 10 seconds..."
|
||||
RULE3=$(curl -s -X POST "$API_URL/api/v1/rules" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"ref": "test.httpbin_post",
|
||||
"label": "HTTPBin POST Every 10 Seconds",
|
||||
"description": "Makes a POST request to httpbin.org every 10 seconds",
|
||||
"pack_ref": "core",
|
||||
"action_ref": "core.http_request",
|
||||
"trigger_ref": "core.intervaltimer",
|
||||
"enabled": true,
|
||||
"trigger_params": {
|
||||
"unit": "seconds",
|
||||
"interval": 10
|
||||
},
|
||||
"action_params": {
|
||||
"url": "https://httpbin.org/post",
|
||||
"method": "POST",
|
||||
"body": "{\"message\": \"Test from Attune\", \"timestamp\": \"{{trigger.payload.executed_at}}\", \"rule\": \"test.httpbin_post\"}",
|
||||
"headers": {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "Attune-Test/1.0"
|
||||
}
|
||||
}
|
||||
}')
|
||||
|
||||
RULE3_ID=$(echo "$RULE3" | jq -r '.data.id // .id // empty')
|
||||
if [ -z "$RULE3_ID" ]; then
|
||||
echo "ERROR: Failed to create rule 3"
|
||||
echo "$RULE3" | jq .
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ Rule 3 created (ID: $RULE3_ID)"
|
||||
echo ""
|
||||
|
||||
# List all rules
|
||||
echo "=== Created Rules ==="
|
||||
curl -s "$API_URL/api/v1/rules" \
|
||||
-H "Authorization: Bearer $TOKEN" | jq -r '.data[] | select(.ref | startswith("test.")) | " - \(.ref) (\(.label)) - Enabled: \(.enabled)"'
|
||||
|
||||
echo ""
|
||||
echo "=== Setup Complete ==="
|
||||
echo ""
|
||||
echo "Rules have been created and enabled."
|
||||
echo "Monitor executions with:"
|
||||
echo " curl -s $API_URL/api/v1/executions -H \"Authorization: Bearer \$TOKEN\" | jq '.data[] | {id, action_ref, status, created}'"
|
||||
echo ""
|
||||
echo "Or view in the web UI at http://localhost:3000"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user