Skip to content
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

Create deploy_eliza.yml #19

Open
wants to merge 2 commits into
base: feature/skinny_eliza/feb10
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions aws/ssm/documents/deploy_eliza.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
schemaVersion: "2.2"
description: "SSM document to update Agent Docker container on EC2 with character configuration from SSM"
parameters:
ImageParameterName:
description: "SSM parameter name for Docker image"
type: "String"
allowedPattern: "^[a-zA-Z0-9/_-]+$"
CharacterParameterName:
description: "SSM parameter name for character configuration"
type: "String"
allowedPattern: "^[a-zA-Z0-9/_-]+$"
ContainerMemory:
description: "Memory limit for container (in MB)"
type: "String"
default: "512"
allowedPattern: "^[0-9]+$"
mainSteps:
- inputs:
runCommand:
- "#!/bin/bash"
- "set -e"
- ""
- "# Validate AWS CLI is installed"
- "if ! command -v aws &> /dev/null; then"
- " echo \"AWS CLI is not installed\" >&2"
- " exit 1"
- "fi"
- ""
- "# Validate Docker is running"
- "if ! docker info &> /dev/null; then"
- " echo \"Docker daemon is not running\" >&2"
- " exit 1"
- "fi"
- ""
- "# Source environment variables"
- "if [ ! -f /var/run/agent/secrets/env ]; then"
- " echo \"Environment file not found\" >&2"
- " exit 1"
- "fi"
- "source /var/run/agent/secrets/env"
- ""
- "# Create required directories"
- "mkdir -p /opt/agent/characters"
- ""
- "# Get parameters from SSM"
- "echo \"Fetching parameters from SSM...\""
- "IMAGE_NAME=$(aws ssm get-parameter --name {{ ImageParameterName }} --query\
\ \"Parameter.Value\" --output text)"
- "if [ $? -ne 0 ]; then"
- " echo \"Failed to fetch image parameter\" >&2"
- " exit 1"
- "fi"
- ""
- "CHARACTER_DATA=$(aws ssm get-parameter --name {{ CharacterParameterName }}\
\ --with-decryption --query \"Parameter.Value\" --output text)"
- "if [ $? -ne 0 ]; then"
- " echo \"Failed to fetch character data\" >&2"
- " exit 1"
- "fi"
- ""
- "# Validate JSON data"
- "echo \"$CHARACTER_DATA\" | jq empty"
- "if [ $? -ne 0 ]; then"
- " echo \"Invalid character JSON configuration\" >&2"
- " exit 1"
- "fi"
- ""
- "# Write character data to file"
- "echo \"$CHARACTER_DATA\" > /opt/agent/characters/eliza.character.json"
- "chmod 600 /opt/agent/characters/eliza.character.json"
- ""
- "# Create required volumes if they don't exist"
- "docker volume create tokenizer || true"
- ""
- "# Stop and remove existing container"
- "echo \"Stopping existing container...\""
- "docker stop agent-docker.service 2>/dev/null || true"
- "docker rm agent-docker.service 2>/dev/null || true"
- ""
- "# Start new container"
- "echo \"Starting new container...\""
- "docker run -d \\\n"
- " -p 3000:3000 \\\n"
- " -v tokenizer:/app/node_modules/@anush008/tokenizers/ \\\n"
- " -v tokenizer:/app/node_modules/fastembed/node_modules/.pnpm/@anush008+tokenizers@https+++codeload.github.com+meta-introspector+arm64-tokenizers+tar.gz+98_s2457qj3pe4ojcbckddasgzfvu/node_modules/@anush008/\
\ \\\n"
- " --mount type=bind,source=/opt/agent,target=/opt/agent \\\n"
- " --mount type=bind,source=/opt/agent/characters/,target=/app/agent/characters/\
\ \\\n"
- " --env-file /var/run/agent/secrets/env \\\n"
- " --memory={{ ContainerMemory }}m \\\n"
- " --memory-swap={{ ContainerMemory }}m \\\n"
- " --health-cmd=\"curl -f http://localhost:3000/health || exit 1\" \\\n"
- " --health-interval=30s \\\n"
- " --health-timeout=10s \\\n"
- " --health-retries=3 \\\n"
- " --rm \\\n"
- " --name \"agent-docker.service\" \\\n"
- " --entrypoint /opt/agent/docker-entrypoint-strace2.sh \\\n"
- " ${AGENT_IMAGE:-$IMAGE_NAME}"
- ""
- "# Wait for container to be healthy"
- "echo \"Waiting for container to be healthy...\""
- "timeout 60 bash -c 'until docker ps --filter \"name=agent-docker.service\"\
\ --filter \"health=healthy\" | grep agent-docker.service; do sleep 2; done'"
- ""
- "echo \"Container update completed successfully\""
name: "UpdateDockerContainer"
action: "aws:runShellScript"
- inputs:
runCommand:
- "#!/bin/bash"
- "if [ $? -ne 0 ]; then"
- " echo \"Container update failed at $(date)\" | tee -a /var/log/container_update_errors.log"
- " echo \"Container logs:\" | tee -a /var/log/container_update_errors.log"
- " docker logs agent-docker.service 2>&1 | tee -a /var/log/container_update_errors.log"
- " echo \"System information:\" | tee -a /var/log/container_update_errors.log"
- " docker info | tee -a /var/log/container_update_errors.log"
- " df -h | tee -a /var/log/container_update_errors.log"
- " exit 1"
- "fi"
name: "CaptureErrors"
action: "aws:runShellScript"