Skip to content

Commit 8d4d05d

Browse files
authored
Create cloudbuild.yaml
1 parent 8a6bbd9 commit 8d4d05d

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

cloudbuild.yaml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
steps:
2+
# Verify deployment configuration
3+
- name: 'gcr.io/cloud-builders/gcloud'
4+
entrypoint: 'bash'
5+
args:
6+
- '-c'
7+
- |
8+
echo "Starting deployment verification..."
9+
echo "Deployment ID: ${_DEPLOYMENT_ID}"
10+
11+
mkdir -p characters
12+
gsutil cp gs://qi-agents-service/${_DEPLOYMENT_ID}/*.character.json characters/
13+
14+
# Build deployment-specific image using base
15+
- name: 'gcr.io/cloud-builders/docker'
16+
args: [
17+
'build',
18+
'--build-arg', 'DEPLOYMENT_ID=${_DEPLOYMENT_ID}',
19+
'--build-arg', 'CHARACTER_FILE=${_CHARACTER_FILE}',
20+
'-t', 'us-east1-docker.pkg.dev/${PROJECT_ID}/qi-agents/${_DEPLOYMENT_ID}:${_VERSION}',
21+
'-f', 'Dockerfile.deploy',
22+
'.'
23+
]
24+
25+
# Push the container image
26+
- name: 'gcr.io/cloud-builders/docker'
27+
args: [
28+
'push',
29+
'us-east1-docker.pkg.dev/${PROJECT_ID}/qi-agents/${_DEPLOYMENT_ID}:${_VERSION}'
30+
]
31+
32+
# Create or update instance with random zone selection
33+
- name: 'gcr.io/cloud-builders/gcloud'
34+
entrypoint: 'bash'
35+
args:
36+
- '-c'
37+
- |
38+
ZONES=("a" "b" "c" "d" "f")
39+
RANDOM_ZONE="${ZONES[$((RANDOM % ${#ZONES[@]}))]}"
40+
ZONE="us-east1-$RANDOM_ZONE"
41+
42+
if [[ $(gcloud compute instances list --filter="name=${_DEPLOYMENT_ID}" --format="get(name)") ]]; then
43+
echo "Updating existing instance ${_DEPLOYMENT_ID}"
44+
gcloud compute instances update-container ${_DEPLOYMENT_ID} \
45+
--container-image us-east1-docker.pkg.dev/${PROJECT_ID}/qi-agents/${_DEPLOYMENT_ID}:${_VERSION} \
46+
--container-env BUCKET_PATH=${_DEPLOYMENT_ID} \
47+
--zone $ZONE
48+
else
49+
echo "Creating new instance ${_DEPLOYMENT_ID}"
50+
gcloud compute instances create-with-container ${_DEPLOYMENT_ID} \
51+
--container-image us-east1-docker.pkg.dev/${PROJECT_ID}/qi-agents/${_DEPLOYMENT_ID}:${_VERSION} \
52+
--machine-type ${_MACHINE_TYPE} \
53+
--zone $ZONE \
54+
--network agents-vpc \
55+
--subnet agents-subnet-primary \
56+
--no-address \
57+
--boot-disk-size 30GB \
58+
--container-env BUCKET_PATH=${_DEPLOYMENT_ID} \
59+
--scopes=cloud-platform \
60+
--service-account=${_SERVICE_ACCOUNT} \
61+
--metadata-from-file startup-script=startup.sh \
62+
--tags=agent-vm
63+
fi
64+
65+
substitutions:
66+
_MACHINE_TYPE: e2-small
67+
_SERVICE_ACCOUNT: qi-agents-service@qi-agents-as-a-service.iam.gserviceaccount.com
68+
_DEPLOYMENT_ID: ""
69+
_VERSION: ""
70+
_CHARACTER_FILE: ""
71+
72+
options:
73+
logging: CLOUD_LOGGING_ONLY
74+
machineType: 'E2_HIGHCPU_8'

0 commit comments

Comments
 (0)