Skip to content

Commit

Permalink
sync image
Browse files Browse the repository at this point in the history
  • Loading branch information
azep-ninja committed Jan 1, 2025
1 parent df53886 commit c4b86d5
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,62 +89,67 @@ RUN mkdir -p characters
# Add debugging to startup command
CMD sh -c '\
echo "Debug: Starting container initialization" && \
echo "Verifying jq installation..." && \
if ! command -v jq &> /dev/null; then \
echo "jq not found. Installing..." && \
apt-get update && \
apt-get install -y jq && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*; \
fi && \
last_update="" && \
while true; do \
# Check metadata for updates
current_update=$(curl -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/character-update-trigger") && \
if [ "$current_update" != "$last_update" ]; then \
echo "Update triggered at $(date)" && \
# Get list of active characters
active_characters=$(curl -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/active-characters") && \
echo "Active characters from metadata: $active_characters" && \
# Copy all character files (even inactive ones)
echo "Copying all character files..." && \
gsutil -m cp "gs://${AGENTS_BUCKET_NAME}/${DEPLOYMENT_ID}/*.character.json" /app/characters/ && \
echo "Character files in directory:" && \
ls -la /app/characters/ && \
echo "Character files found:" && \
for file in /app/characters/*.character.json; do \
echo "- $file" \
echo "- $file"; \
done && \
# Filter for only active characters
character_files=$(echo "$active_characters" | jq -r ".[]" | while read char; do \
found_file=$(find /app/characters -name "${char}.character.json") && \
if [ -n "$found_file" ]; then \
echo "Found active character file: $found_file" >&2; \
echo "$found_file"; \
if [ -n "$active_characters" ]; then \
character_files=$(echo "$active_characters" | jq -r ".[]" | while read char; do \
found_file=$(find /app/characters -name "${char}.character.json") && \
if [ -n "$found_file" ]; then \
echo "Found active character file: $found_file" >&2; \
echo "$found_file"; \
else \
echo "Warning: No file found for active character: $char" >&2; \
fi; \
done | paste -sd "," -) && \
if [ -n "$character_files" ]; then \
echo "Restarting with active character files: $character_files" && \
pkill -f "pnpm start" || true && \
pnpm start --non-interactive --characters="$character_files" & \
else \
echo "Warning: No file found for active character: $char" >&2; \
echo "Warning: No active character files found to start"; \
fi; \
done | paste -sd "," -) && \
if [ -n "$character_files" ]; then \
echo "Restarting with active character files: $character_files" && \
pkill -f "pnpm start" || true && \
pnpm start --non-interactive --characters="$character_files" & \
else \
echo "Warning: No active character files found to start" \
fi && \
last_update=$current_update; \
fi && \
sleep 30; \
done & \
\
# Initial startup using all available characters
# Initial startup
echo "Debug: Initial startup at $(date)" && \
echo "Debug: Environment variables:" && \
env | grep -E "AGENTS_BUCKET_NAME|DEPLOYMENT_ID" && \
echo "Debug: Copying initial character files..." && \
gsutil -m cp "gs://${AGENTS_BUCKET_NAME}/${DEPLOYMENT_ID}/*.character.json" /app/characters/ && \
echo "Debug: Initial character files in directory:" && \
ls -la /app/characters/ && \
echo "Debug: Initial character files found:" && \
echo "Character files found:" && \
for file in /app/characters/*.character.json; do \
echo "- $file" \
echo "- $file"; \
done && \
# Get initial active characters from metadata
active_characters=$(curl -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/active-characters") && \
if [ -n "$active_characters" ]; then \
echo "Debug: Found active characters in metadata: $active_characters" && \
character_files=$(echo "$active_characters" | jq -r ".[]" | while read char; do \
found_file=$(find /app/characters -name "${char}.character.json") && \
if [ -n "$found_file" ]; then \
Expand All @@ -156,17 +161,13 @@ CMD sh -c '\
done | paste -sd "," -) && \
if [ -n "$character_files" ]; then \
echo "Starting with active character files: $character_files" && \
pnpm start --non-interactive --characters="$character_files"; \
else \
echo "Warning: No active character files found to start" && \
exit 1; \
exec pnpm start --non-interactive --characters="$character_files"; \
fi; \
else \
# If no active characters specified, use all available ones
character_files=$(find /app/characters -name "*.character.json" | paste -sd "," -) && \
if [ -n "$character_files" ]; then \
echo "Starting with all available character files: $character_files" && \
pnpm start --non-interactive --characters="$character_files"; \
exec pnpm start --non-interactive --characters="$character_files"; \
else \
echo "ERROR: No character files found in /app/characters/" && \
exit 1; \
Expand Down

0 comments on commit c4b86d5

Please sign in to comment.