Skip to content

Commit 1a89e30

Browse files
Merge pull request #220 from jeremiaswerner/init_for_walk
multiple changes to make script more flexible
2 parents dbb6816 + 58e6ccb commit 1a89e30

2 files changed

Lines changed: 57 additions & 32 deletions

File tree

experimental/serverless-fleets/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ If you don't have a fleet sandbox, choose one of the two methods to create one.
175175

176176
Run the following command, which will create all required cloud resources for you.
177177
```
178-
./init-fleet-sandbox
178+
NAME_PREFIX=ce-fleet-sandbox REGION=eu-de ./init-fleet-sandbox
179179
```
180180

181181
The following resources will be created in the resource group `ce-fleet-sandbox--rg` in `eu-de`.

experimental/serverless-fleets/init-fleet-sandbox

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
#!/bin/bash
22

3-
#### Global vars
4-
# vsi_images hashmap contains the list of valid vsi-images that can be used within fleets
5-
# The fleet sandbox can be setup on regions with a valid vsi-image, only.
6-
declare -A vsi_images
7-
vsi_images["eu-de"]=r010-e7b25759-7857-455a-aec0-904b65c3c4cb
8-
vsi_images["eu-gb"]=r018-31655c46-96e7-4d38-b61a-2ab1b66b9bbd
9-
vsi_images["us-east"]=r014-b7f47448-72db-4012-b018-bb120518b078
10-
113
# Env vars
124
CLEANUP_ON_ERROR=${CLEANUP_ON_ERROR:=false}
135
CLEANUP_ON_SUCCESS=${CLEANUP_ON_SUCCESS:=false}
@@ -33,6 +25,19 @@ icl_name="${NAME_PREFIX}--icl"
3325
sysdig_name="${NAME_PREFIX}--sysdig"
3426
sysdig_key_name="${NAME_PREFIX}--sysdig-key"
3527

28+
# checking if a there is a valid vsi-image in the region available
29+
vsi_image_id=""
30+
if [[ "$REGION" == "eu-de" ]]; then
31+
vsi_image_id="r010-e7b25759-7857-455a-aec0-904b65c3c4cb"
32+
elif [[ "$REGION" == "eu-gb" ]]; then
33+
vsi_image_id="r018-31655c46-96e7-4d38-b61a-2ab1b66b9bbd"
34+
elif [[ "$REGION" == "us-east" ]]; then
35+
vsi_image_id="r014-b7f47448-72db-4012-b018-bb120518b078"
36+
else
37+
echo "Fleet sandbox setup is currently not supported in region ($region), exiting setup... "
38+
exit -1
39+
fi
40+
3641
# ==============================
3742
# COMMON FUNCTIONS
3843
# ==============================
@@ -43,24 +48,22 @@ source ${SCRIPT_DIR}/common.sh
4348
# Clean up previous run
4449
function clean() {
4550
(
51+
target_region $REGION
52+
target_resource_group $resource_group_name
53+
4654
rm -f ${sshkey_name}
4755
rm -f ${sshkey_name}.pub
4856

49-
50-
ibmcloud resource service-instance-delete $icl_name -f -q 2>/dev/null
51-
ibmcloud iam service-id-delete ${icl_name}-svc-id -f -q 2>/dev/null
52-
ibmcloud is endpoint-gateway-delete ${icl_name}-vpegw --force 2>/dev/null
53-
5457
if [[ "$SETUP_MONITORING" == "true" ]]; then
5558
ibmcloud resource service-key-delete ${sysdig_key_name} -f -q 2>/dev/null
56-
ibmcloud resource service-instance-delete ${sysdig_name} -f -q 2>/dev/null
59+
ibmcloud resource service-instance-delete ${sysdig_name} -g ${resource_group_name} -f -q 2>/dev/null
5760
ibmcloud is endpoint-gateway-delete ${sysdig_name}-vpegw --force 2>/dev/null
5861
fi
5962

6063
if [[ "$SETUP_LOGGING" == "true" ]]; then
61-
ibmcloud iam service-id-delete ${icl_name}-svc-id
64+
ibmcloud iam service-id-delete ${icl_name}-svc-id -f 2>/dev/null
6265
ibmcloud is endpoint-gateway-delete ${icl_name}-vpegw --force 2>/dev/null
63-
ibmcloud resource service-instance-delete $icl_name -f -q 2>/dev/null
66+
ibmcloud resource service-instance-delete $icl_name -g ${resource_group_name} -f -q 2>/dev/null
6467
fi
6568

6669
ibmcloud iam api-key-delete ${apikey_name} --force 2>/dev/null
@@ -89,12 +92,12 @@ function clean() {
8992
if [[ $? == 0 ]]; then
9093
COUNTER=0
9194
# some resources (e.g. boot volumes) are deleted with some delay. Hence, the script waits before exiting with an error
92-
while (( "$(ibmcloud resource service-instances --type all -g $resource_group_name --output json | jq -r '. | length')" > 0 )); do
95+
while (( "$(ibmcloud resource service-instances --type all -g $resource_group_name --location $REGION --output json | jq -r '. | length')" > 0 )); do
9396
sleep 5
9497
COUNTER=$((COUNTER + 1))
9598
if ((COUNTER > 3)); then
9699
print_error "Cleanup failed! Please make sure to delete remaining resources manually to avoid unwanted charges."
97-
ibmcloud resource service-instances --type all -g $resource_group_name
100+
ibmcloud resource service-instances --type all -g $resource_group_name --location $REGION
98101
exit 1
99102
fi
100103
done
@@ -109,8 +112,8 @@ function abortScript() {
109112
clean
110113
else
111114
print_msg "\nSkipping deletion of the created IBM Cloud resources. Please be aware that the created resources will occur costs in your account."
112-
echo "$ ibmcloud resource service-instances --type all -g $resource_group_name"
113-
ibmcloud resource service-instances --type all -g $resource_group_name
115+
echo "$ ibmcloud resource service-instances --type all -g $resource_group_name --location $REGION"
116+
ibmcloud resource service-instances --type all -g $resource_group_name --location $REGION
114117
fi
115118
exit 1
116119
}
@@ -154,13 +157,6 @@ echo "Please note: This script will install various IBM Cloud resources within t
154157
print_msg "\nChecking prerequisites ..."
155158
check_prerequisites
156159

157-
# checking if a there is a valid vsi-image in the region available
158-
vsi_image_id=${vsi_images[${REGION}]}
159-
160-
if [[ $vsi_image_id == "" || $vsi_image_id == null ]]; then
161-
echo " Fleet sandbox setup is currently not supported in region ($region), exiting setup... "
162-
exit -1
163-
fi
164160

165161
# Ensure that latest versions of used IBM Cloud ClI is installed
166162
print_msg "\nPulling latest IBM Cloud CLI release ..."
@@ -174,7 +170,6 @@ ensure_plugin_is_up_to_date vpc-infrastructure
174170
ensure_plugin_is_up_to_date cloud-object-storage
175171
ensure_plugin_is_up_to_date container-registry
176172

177-
print_msg "\nTargetting IBM Cloud region '$REGION' ..."
178173
target_region $REGION
179174

180175
#
@@ -363,13 +358,17 @@ ibmcloud cos config region --region $REGION
363358
print_msg "\nCreating COS bucket '${cos_bucket_name}' ..."
364359
ibmcloud cos bucket-create --bucket ${cos_bucket_name} --ibm-service-instance-id $COS_ID
365360

366-
367361
# Create COS credentials
368362
print_msg "\nCreating COS service key '${cos_key_name}' ..."
369363
ibmcloud resource service-key-create ${cos_key_name} --parameters '{"HMAC":true}' --instance-id $COS_ID
370364

371365
print_msg "\nCOS instance '${COS_ID}' and bucket '${cos_bucket_name}' created ..."
372366

367+
ibmcloud cos config crn --force --crn $(ibmcloud resource service-instance $cos_name --crn | grep "crn")
368+
369+
print_msg "\ncreateing bucket lifecycle configuration for objects in the result folder with 1 day retention ..."
370+
ibmcloud cos bucket-lifecycle-configuration-put --bucket ${cos_bucket_name} --region ${REGION} --lifecycle-configuration '{ "Rules": [ {"Expiration": {"Days": 1},"Filter": {"Prefix": "result/ticker"},"ID": "ticker results","Status": "Enabled"}, {"Expiration": {"Days": 1},"Filter": {"Prefix": "result/inferencing"},"ID": "inferencing results","Status": "Enabled"}, {"Expiration": {"Days": 1},"Filter": {"Prefix": "result/docling"},"ID": "docling results","Status": "Enabled"}, {"Expiration": {"Days": 1},"Filter": {"Prefix": "result/wordcount"},"ID": "wordcount results","Status": "Enabled"} ] }'
371+
373372
print_msg "\nCreating local rclone environment .rclone.conf to upload/download to the COS bucket..."
374373

375374
cat > .rclone.conf << EOF
@@ -439,6 +438,7 @@ ibmcloud ce configmap create --name fleet-vpc-config \
439438
# alternative to fetch the latest stock image:
440439
# --from-literal VSI_IMAGE_ID="$(ibmcloud is image ibm-ubuntu-24-04-6-minimal-amd64-1 --output json | jq -r '.id')"
441440

441+
## crawl+
442442
print_msg "\nCreating a Code Engine secret 'fleet-cos-config' to access the COS bucket ..."
443443
ibmcloud ce secret create --name fleet-cos-config \
444444
--from-literal access_key_id=$(ibmcloud resource service-key ${cos_key_name} --output JSON | jq -r '.[0] | .credentials | .cos_hmac_keys | .access_key_id') \
@@ -451,15 +451,40 @@ ibmcloud ce secret create --name fleet-cos-config \
451451
--from-literal prefix="" \
452452
--from-literal resource_instance_id=$COS_ID
453453

454+
## walk
455+
print_msg "\nCreating a Code Engine Persistant Data Store 'fleet-task-store' to access the COS bucket as the task state store ..."
456+
ibmcloud ce secret create --name fleet-task-store-secret \
457+
--format hmac \
458+
--secret-access-key $(ibmcloud resource service-key ${cos_key_name} --output JSON | jq -r '.[0] | .credentials | .cos_hmac_keys | .secret_access_key') \
459+
--access-key-id $(ibmcloud resource service-key ${cos_key_name} --output JSON | jq -r '.[0] | .credentials | .cos_hmac_keys | .access_key_id')
460+
## walk
461+
ibmcloud ce pds create --name fleet-task-store \
462+
--cos-bucket-name ${cos_bucket_name} \
463+
--cos-bucket-location ${REGION} \
464+
--cos-access-secret fleet-task-store-secret
465+
466+
## walk
467+
print_msg "\nCreating the Code Engine default secret 'codeengine-fleet-defaults' with observability and VPC subnet configurations ..."
468+
ibmcloud ce secret create -n codeengine-fleet-defaults \
469+
--from-literal pool_subnet_crn_1="$(ibmcloud is subnet ${vpc_name}-subnet --output json | jq -r '.crn')" \
470+
--from-literal pool_security_group_crns_1="$(ibmcloud is security-group ${vpc_name}-group --output json | jq -r '.crn')"
471+
454472
print_msg "\nCreating a Code Engine secret 'fleet-observability-config' to enable logging and monitoring integrations ..."
455473
ibmcloud ce secret create --name fleet-observability-config --format generic --from-literal LOGGING_ENABLED=${SETUP_LOGGING}
456474
if [[ "$SETUP_LOGGING" == "true" ]]; then
457475
print_msg "\nMake sure logs are sent to '${icl_ingestion_host}' ..."
476+
## crawl+
458477
ibmcloud ce secret update --name fleet-observability-config \
459478
--from-literal LOGGING_INGESTION_HOST=${icl_ingestion_host} \
460479
--from-literal LOGGING_INGESTION_APIKEY=${icl_ingestion_apikey} \
461480
--from-literal LOGGING_LEVEL_AGENT=info \
462481
--from-literal LOGGING_LEVEL_WORKER=info
482+
## walk
483+
ibmcloud ce secret update -n codeengine-fleet-defaults \
484+
--from-literal LOGGING_INGRESS_ENDPOINT="${icl_ingestion_host}" \
485+
--from-literal LOGGING_SENDER_API_KEY="${icl_ingestion_apikey}" \
486+
--from-literal LOGGING_LEVEL_AGENT=info \
487+
--from-literal LOGGING_LEVEL_WORKER=info
463488
fi
464489
if [[ "$SETUP_MONITORING" == "true" ]]; then
465490
print_msg "\nMake sure monitoring is enabled to '${sysdig_collector_host}' ..."
@@ -469,8 +494,8 @@ if [[ "$SETUP_MONITORING" == "true" ]]; then
469494
fi
470495

471496
print_msg "\nThe Fleet demo sandbox has been configured. Please be aware that the created resources will occur costs in your account."
472-
echo "$ ibmcloud resource service-instances --type all -g $resource_group_name"
473-
ibmcloud resource service-instances --type all -g $resource_group_name
497+
echo "$ ibmcloud resource service-instances --type all -g $resource_group_name --location $REGION"
498+
ibmcloud resource service-instances --type all -g $resource_group_name --location $REGION
474499

475500
print_msg "\nFollow the tutorial to launch your first Serverless Fleet with './run'"
476501

0 commit comments

Comments
 (0)