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
124CLEANUP_ON_ERROR=${CLEANUP_ON_ERROR:= false}
135CLEANUP_ON_SUCCESS=${CLEANUP_ON_SUCCESS:= false}
@@ -33,6 +25,19 @@ icl_name="${NAME_PREFIX}--icl"
3325sysdig_name=" ${NAME_PREFIX} --sysdig"
3426sysdig_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
4449function 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
154157print_msg " \nChecking prerequisites ..."
155158check_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
166162print_msg " \nPulling latest IBM Cloud CLI release ..."
@@ -174,7 +170,6 @@ ensure_plugin_is_up_to_date vpc-infrastructure
174170ensure_plugin_is_up_to_date cloud-object-storage
175171ensure_plugin_is_up_to_date container-registry
176172
177- print_msg " \nTargetting IBM Cloud region '$REGION ' ..."
178173target_region $REGION
179174
180175#
@@ -363,13 +358,17 @@ ibmcloud cos config region --region $REGION
363358print_msg " \nCreating COS bucket '${cos_bucket_name} ' ..."
364359ibmcloud cos bucket-create --bucket ${cos_bucket_name} --ibm-service-instance-id $COS_ID
365360
366-
367361# Create COS credentials
368362print_msg " \nCreating COS service key '${cos_key_name} ' ..."
369363ibmcloud resource service-key-create ${cos_key_name} --parameters ' {"HMAC":true}' --instance-id $COS_ID
370364
371365print_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+
373372print_msg " \nCreating local rclone environment .rclone.conf to upload/download to the COS bucket..."
374373
375374cat > .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+
442442print_msg " \nCreating a Code Engine secret 'fleet-cos-config' to access the COS bucket ..."
443443ibmcloud 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+
454472print_msg " \nCreating a Code Engine secret 'fleet-observability-config' to enable logging and monitoring integrations ..."
455473ibmcloud ce secret create --name fleet-observability-config --format generic --from-literal LOGGING_ENABLED=${SETUP_LOGGING}
456474if [[ " $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
463488fi
464489if [[ " $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
469494fi
470495
471496print_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
475500print_msg " \nFollow the tutorial to launch your first Serverless Fleet with './run'"
476501
0 commit comments