Skip to content

Commit 01f3d7e

Browse files
authored
Update deploy_eliza.yml
1 parent 3ff0724 commit 01f3d7e

File tree

1 file changed

+101
-13
lines changed

1 file changed

+101
-13
lines changed

aws/ssm/documents/deploy_eliza.yml

+101-13
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,124 @@
11
---
22
schemaVersion: "2.2"
3-
description: "SSM document to update Docker container on EC2"
3+
description: "SSM document to update Agent Docker container on EC2 with character configuration from SSM"
44
parameters:
55
ImageParameterName:
66
description: "SSM parameter name for Docker image"
77
type: "String"
8-
ConfigParameterName:
9-
description: "SSM parameter name for app configuration"
8+
allowedPattern: "^[a-zA-Z0-9/_-]+$"
9+
CharacterParameterName:
10+
description: "SSM parameter name for character configuration"
1011
type: "String"
12+
allowedPattern: "^[a-zA-Z0-9/_-]+$"
13+
ContainerMemory:
14+
description: "Memory limit for container (in MB)"
15+
type: "String"
16+
default: "512"
17+
allowedPattern: "^[0-9]+$"
1118
mainSteps:
1219
- inputs:
1320
runCommand:
1421
- "#!/bin/bash"
1522
- "set -e"
23+
- ""
24+
- "# Validate AWS CLI is installed"
25+
- "if ! command -v aws &> /dev/null; then"
26+
- " echo \"AWS CLI is not installed\" >&2"
27+
- " exit 1"
28+
- "fi"
29+
- ""
30+
- "# Validate Docker is running"
31+
- "if ! docker info &> /dev/null; then"
32+
- " echo \"Docker daemon is not running\" >&2"
33+
- " exit 1"
34+
- "fi"
35+
- ""
36+
- "# Source environment variables"
37+
- "if [ ! -f /var/run/agent/secrets/env ]; then"
38+
- " echo \"Environment file not found\" >&2"
39+
- " exit 1"
40+
- "fi"
41+
- "source /var/run/agent/secrets/env"
42+
- ""
43+
- "# Create required directories"
44+
- "mkdir -p /opt/agent/characters"
45+
- ""
46+
- "# Get parameters from SSM"
47+
- "echo \"Fetching parameters from SSM...\""
1648
- "IMAGE_NAME=$(aws ssm get-parameter --name {{ ImageParameterName }} --query\
1749
\ \"Parameter.Value\" --output text)"
18-
- "CONFIG=$(aws ssm get-parameter --name {{ ConfigParameterName }} --with-decryption\
19-
\ --query \"Parameter.Value\" --output text)"
20-
- "echo \"$CONFIG\" > /tmp/app_config.json"
21-
- "docker pull $IMAGE_NAME"
22-
- "docker stop app_container || true"
23-
- "docker rm app_container || true"
24-
- "docker run -d --name app_container -v /tmp/app_config.json:/app/config.json\
25-
\ $IMAGE_NAME"
50+
- "if [ $? -ne 0 ]; then"
51+
- " echo \"Failed to fetch image parameter\" >&2"
52+
- " exit 1"
53+
- "fi"
54+
- ""
55+
- "CHARACTER_DATA=$(aws ssm get-parameter --name {{ CharacterParameterName }}\
56+
\ --with-decryption --query \"Parameter.Value\" --output text)"
57+
- "if [ $? -ne 0 ]; then"
58+
- " echo \"Failed to fetch character data\" >&2"
59+
- " exit 1"
60+
- "fi"
61+
- ""
62+
- "# Validate JSON data"
63+
- "echo \"$CHARACTER_DATA\" | jq empty"
64+
- "if [ $? -ne 0 ]; then"
65+
- " echo \"Invalid character JSON configuration\" >&2"
66+
- " exit 1"
67+
- "fi"
68+
- ""
69+
- "# Write character data to file"
70+
- "echo \"$CHARACTER_DATA\" > /opt/agent/characters/eliza.character.json"
71+
- "chmod 600 /opt/agent/characters/eliza.character.json"
72+
- ""
73+
- "# Create required volumes if they don't exist"
74+
- "docker volume create tokenizer || true"
75+
- ""
76+
- "# Stop and remove existing container"
77+
- "echo \"Stopping existing container...\""
78+
- "docker stop agent-docker.service 2>/dev/null || true"
79+
- "docker rm agent-docker.service 2>/dev/null || true"
80+
- ""
81+
- "# Start new container"
82+
- "echo \"Starting new container...\""
83+
- "docker run -d \\\n"
84+
- " -p 3000:3000 \\\n"
85+
- " -v tokenizer:/app/node_modules/@anush008/tokenizers/ \\\n"
86+
- " -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/\
87+
\ \\\n"
88+
- " --mount type=bind,source=/opt/agent,target=/opt/agent \\\n"
89+
- " --mount type=bind,source=/opt/agent/characters/,target=/app/agent/characters/\
90+
\ \\\n"
91+
- " --env-file /var/run/agent/secrets/env \\\n"
92+
- " --memory={{ ContainerMemory }}m \\\n"
93+
- " --memory-swap={{ ContainerMemory }}m \\\n"
94+
- " --health-cmd=\"curl -f http://localhost:3000/health || exit 1\" \\\n"
95+
- " --health-interval=30s \\\n"
96+
- " --health-timeout=10s \\\n"
97+
- " --health-retries=3 \\\n"
98+
- " --rm \\\n"
99+
- " --name \"agent-docker.service\" \\\n"
100+
- " --entrypoint /opt/agent/docker-entrypoint-strace2.sh \\\n"
101+
- " ${AGENT_IMAGE:-$IMAGE_NAME}"
102+
- ""
103+
- "# Wait for container to be healthy"
104+
- "echo \"Waiting for container to be healthy...\""
105+
- "timeout 60 bash -c 'until docker ps --filter \"name=agent-docker.service\"\
106+
\ --filter \"health=healthy\" | grep agent-docker.service; do sleep 2; done'"
107+
- ""
108+
- "echo \"Container update completed successfully\""
26109
name: "UpdateDockerContainer"
27110
action: "aws:runShellScript"
28111
- inputs:
29112
runCommand:
30113
- "#!/bin/bash"
31114
- "if [ $? -ne 0 ]; then"
32-
- " echo \"Error occurred during container update\" >> /var/log/container_update_errors.log"
33-
- " docker logs app_container >> /var/log/container_update_errors.log"
115+
- " echo \"Container update failed at $(date)\" | tee -a /var/log/container_update_errors.log"
116+
- " echo \"Container logs:\" | tee -a /var/log/container_update_errors.log"
117+
- " docker logs agent-docker.service 2>&1 | tee -a /var/log/container_update_errors.log"
118+
- " echo \"System information:\" | tee -a /var/log/container_update_errors.log"
119+
- " docker info | tee -a /var/log/container_update_errors.log"
120+
- " df -h | tee -a /var/log/container_update_errors.log"
121+
- " exit 1"
34122
- "fi"
35123
name: "CaptureErrors"
36124
action: "aws:runShellScript"

0 commit comments

Comments
 (0)