Skip to content

Commit 4417996

Browse files
committed
fx deployment.
1 parent 4f39c34 commit 4417996

File tree

3 files changed

+77
-21
lines changed

3 files changed

+77
-21
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ ENV SERVER_PORT=8080
6565
EXPOSE 8080
6666

6767
# Modified command to fetch character file from GCS before starting
68-
CMD sh -c "gsutil cp gs://$BUCKET_NAME/$CHARACTER_FILE characters/character.json && pnpm start --non-interactive --characters=characters/character.json"
68+
CMD sh -c "gsutil cp gs://$AGENTS_BUCKET_NAME/$CHARACTER_FILE characters/$CHARACTER_FILE && pnpm start --non-interactive --characters=characters/$CHARACTER_FILE"

cloudbuild.yaml

+20-6
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,31 @@ steps:
1616
else
1717
full_name="${agent_name}"
1818
fi
19-
# Add timestamp for versioning
20-
timestamp=$(date +%Y%m%d-%H%M%S)
2119
echo "${agent_name}" > /workspace/agent_name
2220
echo "${full_name}" > /workspace/full_name
21+
# Add timestamp for versioning
22+
timestamp=$(date +%Y%m%d-%H%M%S)
2323
echo "${timestamp}" > /workspace/version
2424
echo "Agent name will be: ${full_name}"
2525
echo "Version will be: ${timestamp}"
2626
ls -la
2727
pwd
2828
29-
# Build the container image for Artifact Registry
29+
# Verify secrets access
30+
- name: 'gcr.io/cloud-builders/gcloud'
31+
entrypoint: 'bash'
32+
args:
33+
- '-c'
34+
- |
35+
echo "Verifying secrets access..."
36+
echo "Testing secret access..."
37+
if ! gcloud secrets versions access latest --secret="small-google-model"; then
38+
echo "Failed to access secrets"
39+
exit 1
40+
fi
41+
echo "Secret access verified"
42+
43+
# Build the container image
3044
- name: 'gcr.io/cloud-builders/docker'
3145
entrypoint: 'bash'
3246
args:
@@ -40,7 +54,7 @@ steps:
4054
docker build -t us-central1-docker.pkg.dev/$PROJECT_ID/qi-agents/${full_name}:${version} . || { echo "Docker build failed"; exit 1; }
4155
echo "Docker build completed"
4256
43-
# Push the container image to Artifact Registry
57+
# Push the container image
4458
- name: 'gcr.io/cloud-builders/docker'
4559
entrypoint: 'bash'
4660
args:
@@ -90,8 +104,8 @@ substitutions:
90104
_DISK_SIZE: 30GB
91105
_NETWORK: agents-vpc
92106
_SUBNET: agents-subnet
93-
_CHARACTER_FILE: default.character.json # Default value
94-
_SUFFIX: agent # Default value
107+
_CHARACTER_FILE: defalt.character.json
108+
_SUFFIX: agent
95109

96110
options:
97111
logging: CLOUD_LOGGING_ONLY

startup.sh

+56-14
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,72 @@
33
# Log startup for debugging
44
echo "Starting initialization script..."
55

6-
# Use /mnt/stateful_partition which is writable in GCE
7-
mkdir -p /mnt/stateful_partition/agent/data
8-
chmod 777 /mnt/stateful_partition/agent/data
6+
# Create parent directories first with error checking
7+
echo "Creating directory structure..."
8+
sudo mkdir -p /mnt/stateful_partition || {
9+
echo "Failed to create stateful_partition directory"
10+
exit 1
11+
}
912

10-
# Verify directory creation
13+
# Create qi-agents directory
14+
sudo mkdir -p /mnt/stateful_partition/qi-agents || {
15+
echo "Failed to create qi-agents directory"
16+
exit 1
17+
}
18+
19+
# Create data directory
20+
sudo mkdir -p /mnt/stateful_partition/qi-agents/data || {
21+
echo "Failed to create data directory"
22+
exit 1
23+
}
24+
25+
# Set permissions
26+
echo "Setting directory permissions..."
27+
sudo chmod -R 777 /mnt/stateful_partition/qi-agents || {
28+
echo "Failed to set permissions"
29+
exit 1
30+
}
31+
32+
# Verify directory structure
33+
echo "Verifying directory structure..."
1134
ls -la /mnt/stateful_partition/qi-agents/
1235

13-
# Pull latest image
36+
# Pull latest image with verification
1437
echo "Pulling latest image..."
15-
docker pull us-central1-docker.pkg.dev/${PROJECT_ID}/${FULL_NAME}:${version}
38+
if ! docker pull us-central1-docker.pkg.dev/${PROJECT_ID}/${FULL_NAME}:${version}; then
39+
echo "Failed to pull image"
40+
exit 1
41+
fi
42+
43+
# Get secrets from Secret Manager
44+
echo "Fetching secrets..."
45+
AGENTS_BUCKET_NAME=$(gcloud secrets versions access latest --secret="agents-bucket-name")
46+
SMALL_GOOGLE_MODEL=$(gcloud secrets versions access latest --secret="small-google-model")
47+
MEDIUM_GOOGLE_MODEL=$(gcloud secrets versions access latest --secret="medium-google-model")
48+
GOOGLE_GENERATIVE_AI_API_KEY=$(gcloud secrets versions access latest --secret="google-generative-ai-key")
1649

1750
# Run container with persistent storage and restart policy
1851
echo "Starting container..."
1952
docker run -d \
2053
--name ${FULL_NAME} \
2154
--restart=always \
22-
-v /mnt/stateful_partition/agent/data:/app/agent/data \
23-
-e AGENTS_BUCKET_NAME="gs://$AGENTS_BUCKET_NAME" \
24-
-e CHARACTER_FILE="$CHARACTER_FILE" \
25-
-e SMALL_GOOGLE_MODEL="$SMALL_GOOGLE_MODEL" \
26-
-e MEDIUM_GOOGLE_MODEL="$MEDIUM_GOOGLE_MODEL" \
27-
-e GOOGLE_GENERATIVE_AI_API_KEY="$GOOGLE_GENERATIVE_AI_API_KEY" \
55+
-v /mnt/stateful_partition/qi-agents/data:/app/agent/data \
56+
-e AGENTS_BUCKET_NAME="${AGENTS_BUCKET_NAME}" \
57+
-e CHARACTER_FILE="${CHARACTER_FILE}" \
58+
-e SMALL_GOOGLE_MODEL="${SMALL_GOOGLE_MODEL}" \
59+
-e MEDIUM_GOOGLE_MODEL="${MEDIUM_GOOGLE_MODEL}" \
60+
-e GOOGLE_GENERATIVE_AI_API_KEY="${GOOGLE_GENERATIVE_AI_API_KEY}" \
61+
-e PORT="8080" \
62+
-e SERVER_PORT="8080" \
2863
us-central1-docker.pkg.dev/${PROJECT_ID}/${FULL_NAME}:${version}
2964

30-
# Log container status
65+
# Verify container is running
3166
echo "Container started. Checking status..."
32-
docker ps | grep ${FULL_NAME}
67+
if ! docker ps | grep ${FULL_NAME}; then
68+
echo "Container failed to start. Checking logs:"
69+
docker logs ${FULL_NAME}
70+
exit 1
71+
fi
72+
73+
# Log success
74+
echo "Startup script completed successfully"

0 commit comments

Comments
 (0)