forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdeploy_eliza.yml
124 lines (124 loc) · 4.74 KB
/
deploy_eliza.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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"