@@ -5,10 +5,8 @@ CLEANUP_ON_ERROR=${CLEANUP_ON_ERROR:=false}
55CLEANUP_ON_SUCCESS=${CLEANUP_ON_SUCCESS:= false}
66REGION=" ${REGION:= eu-de} "
77NAME_PREFIX=" ${NAME_PREFIX:= ce-fleet-sandbox} "
8- DEBUG_MODE=" ${DEBUG_MODE:= false} "
9- REGISTRY=${REGISTRY:- icr.io/ codeengine}
108SETUP_LOGGING=" ${SETUP_LOGGING:- true} "
11- SETUP_MONITORING=" ${SETUP_MONITORING:- false } "
9+ SETUP_MONITORING=" ${SETUP_MONITORING:- true } "
1210
1311
1412# Generate a short uuid for some resources
@@ -31,33 +29,9 @@ sysdig_key_name="${NAME_PREFIX}--sysdig-key"
3129# ==============================
3230# COMMON FUNCTIONS
3331# ==============================
34- RED=" \033[31m"
35- BLUE=" \033[94m"
36- GREEN=" \033[32m"
37- ENDCOLOR=" \033[0m"
38-
39- function print_error {
40- echo -e " ${RED} \n==========================================${ENDCOLOR} "
41- echo -e " ${RED} FAILED${ENDCOLOR} "
42- echo -e " ${RED} ==========================================\n${ENDCOLOR} "
43- echo -e " ${RED} $1 ${ENDCOLOR} "
44- echo " "
45- }
46- function print_msg {
47- echo -e " ${BLUE} $1 ${ENDCOLOR} "
48- }
49- function print_success {
50- echo -e " ${GREEN} $1 ${ENDCOLOR} "
51- }
5232
53- # Helper function to check whether prerequisites are installed
54- function check_prerequisites {
55- # Ensure that jq tool is installed
56- if ! command -v jq & > /dev/null; then
57- print_error " 'jq' tool is not installed"
58- exit 1
59- fi
60- }
33+ SCRIPT_DIR=$( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd )
34+ source ${SCRIPT_DIR} /common.sh
6135
6236# Clean up previous run
6337function clean() {
@@ -140,6 +114,8 @@ function abortScript() {
140114 exit 1
141115}
142116
117+
118+
143119if [[ " $1 " == " clean" ]]; then
144120 print_msg " \nCleaning up the created IBM Cloud resources ..."
145121 clean
@@ -168,13 +144,13 @@ ibmcloud update --force
168144# Ensure that latest versions of used IBM Cloud CLI plugins are installed
169145print_msg " \nInstalling required experiemental IBM Cloud CLI plugins ..."
170146export CE_EXPERIMENTAL_FLEET=true
171- ibmcloud plugin install code-engine -f --quiet
172- ibmcloud plugin install vpc-infrastructure -f --quiet
173- ibmcloud plugin install cloud-object-storage -f --quiet
174- ibmcloud plugin install container-registry -f --quiet
147+ ensure_plugin_is_up_to_date code-engine
148+ ensure_plugin_is_up_to_date vpc-infrastructure
149+ ensure_plugin_is_up_to_date cloud-object-storage
150+ ensure_plugin_is_up_to_date container-registry
175151
176152print_msg " \nTargetting IBM Cloud region '$REGION ' ..."
177- ibmcloud target -r $REGION
153+ target_region $REGION
178154
179155#
180156# Create the resource group, if it does not exist
@@ -183,8 +159,7 @@ if [ $? != 0 ]; then
183159 print_msg " \nCreating resource group '$resource_group_name ' ..."
184160 ibmcloud resource group-create $resource_group_name
185161fi
186- print_msg " \nTargetting resource group '$resource_group_name ' ..."
187- ibmcloud target -g $resource_group_name
162+ target_resource_group $resource_group_name
188163
189164#
190165# Check whether Logging should be configured
@@ -307,13 +282,8 @@ if [ $? -ne 0 ]; then
307282 abortScript
308283fi
309284
310- # Allow access to the jumpbox via ssh only from your current IP
311- remote_ip=$( curl -s https://ipv4.icanhazip.com/)
312- print_msg " \nLimit access to the jumpbox via SSH to your current IP address '${remote_ip} ' ..."
313-
314285print_msg " \nCreating required VPC Security group rules ..."
315286ibmcloud is security-group-rule-add $vpc_name -group outbound all --remote 0.0.0.0/0 --vpc $vpc_name > /dev/null
316- ibmcloud is security-group-rule-add $vpc_name -group inbound tcp --remote ${remote_ip} --port-min 22 --port-max 22 --vpc $vpc_name > /dev/null
317287ibmcloud is security-group-rule-add $vpc_name -group inbound all --remote $vpc_name -group --vpc $vpc_name > /dev/null
318288echo " Done"
319289
@@ -356,54 +326,6 @@ if [[ "$SETUP_MONITORING" == "true" ]]; then
356326 fi
357327fi
358328
359- #
360- # Create the ssh key for jump box server VSI
361- print_msg " \nGenerating a ssh key-pair in './${sshkey_name} ' and './${sshkey_name} .pub' ..."
362- ssh-keygen -t rsa -b 4096 -f ${sshkey_name} -N ' '
363- ibmcloud is key-create ${sshkey_name} @./${sshkey_name} .pub
364-
365- #
366- # Create the jump box server VSI
367- print_msg " \nCreating the VPC VSI '$vsi_jumpbox_name ', which acts as the jumpbox server ..."
368- ibmcloud is instance-create $vsi_jumpbox_name $vpc_name $REGION -1 cx2-2x4 $vpc_name -subnet \
369- --image " ibm-ubuntu-24-04-6-minimal-amd64-1" \
370- --boot-volume ' {"name": "boot-vol-attachment-name", "volume": {"name": "my-agent-boot-vol", "capacity": 100, "profile": {"name": "general-purpose"}}, "delete_volume_on_instance_delete": true}' \
371- --resource-group-name $resource_group_name \
372- --host-failure-policy restart \
373- --primary-network-interface " {\" name\" : \" eth0\" , \" allow_ip_spoofing\" : false, \" auto_delete\" : true, \" subnet\" : {\" name\" :\" ${vpc_name} -subnet\" }, \" primary_ip\" : {\" auto_delete\" : true}, \" security_groups\" : [{\" name\" : \" ${vpc_name} -group\" }]}" \
374- --keys " ${sshkey_name} "
375- if [ $? -ne 0 ]; then
376- print_error " VPC VSI creation failed!"
377- abortScript
378- fi
379-
380- print_msg " \nWaiting for the VSI '$vsi_jumpbox_name ' to start ..."
381- COUNTER=0
382- while ! [[ $( ibmcloud is instance $vsi_jumpbox_name --output json | jq -r ' .status' ) == " running" ]]; do
383- sleep 2
384- COUNTER=$(( COUNTER + 1 ))
385- if (( COUNTER > 10 )) ; then
386- print_error " The VSI does not became ready as expected. Perform 'ibmcloud is instance $vsi_jumpbox_name ' for further details."
387- abortScript
388- fi
389- done
390- echo " VSI '$vsi_jumpbox_name ' is running, now!"
391-
392- #
393- # Assign the floating IP
394- print_msg " \nAssigning a VPC Floating IP to the primary network interface of VSI '$vsi_jumpbox_name ' ..."
395- ibmcloud is floating-ip-reserve $vsi_jumpbox_name -ip --nic eth0 --in $vsi_jumpbox_name
396- if [ $? -ne 0 ]; then
397- print_error " VPC Floating IP assignment failed!"
398- abortScript
399- fi
400- public_ip_address=$( ibmcloud is instance $vsi_jumpbox_name --output json | jq -r ' .primary_network_interface|.floating_ips|.[0]|.address' )
401- private_ip_address=$( ibmcloud is instance $vsi_jumpbox_name --output json | jq -r ' .primary_network_interface|.primary_ip|.address' )
402-
403- #
404- # Copying ssh private ssh-key over to the jumpbox
405- scp -i ${sshkey_name} -o UserKnownHostsFile=/dev/null -o StrictHostKeychecking=no ./${sshkey_name} root@${public_ip_address} :/root/.ssh/id_rsa
406-
407329#
408330# Creating COS instance and bucket
409331print_msg " \nCreating COS instance '${cos_name} ' ..."
@@ -461,15 +383,21 @@ if [ $? -ne 0 ]; then
461383fi
462384project_guid=$( ibmcloud ce project current --output json | jq -r ' .guid' )
463385
386+ #
387+ # Create the ssh key for jump box server VSI
388+ print_msg " \nGenerating a ssh key-pair in './${sshkey_name} ' and './${sshkey_name} .pub' ..."
389+ ssh-keygen -t rsa -b 4096 -f ${sshkey_name} -N ' '
390+ ibmcloud is key-create ${sshkey_name} @./${sshkey_name} .pub
391+
392+ print_msg " \nCreating a Code Engine secret 'fleet-ssh-secret' for public ssh key ..."
393+ ibmcloud ce secret create --name fleet-ssh-secret --format ssh --key-path ./${sshkey_name} .pub
394+
464395print_msg " \nCreating an API Key '${apikey_name} ' for ICR credentials ..."
465396apikey=" $( ibmcloud iam api-key-create ${apikey_name} -q -o json| jq -r ' .apikey' ) "
466397
467398print_msg " \nCreating a Code Engine secret 'fleet-registry-secret' for ICR credentials ..."
468399ibmcloud ce secret create --name fleet-registry-secret --format registry --server ' de.icr.io' --username iamapikey --password $apikey
469400
470- print_msg " \nCreating a Code Engine secret 'fleet-ssh-secret' for public ssh key ..."
471- ibmcloud ce secret create --name fleet-ssh-secret --format ssh --key-path ./${sshkey_name} .pub
472-
473401# using the common base VSI image "jwe-ubuntu24-gpu" enabled for GPU and including podman and s3fs
474402print_msg " \nCreating a Code Engine configmap 'fleet-vpc-config' to access the new VPC ..."
475403ibmcloud ce configmap create --name fleet-vpc-config \
@@ -513,22 +441,14 @@ if [[ "$SETUP_MONITORING" == "true" ]]; then
513441 --from-literal MONITORING_INGESTION_REGION=${REGION}
514442fi
515443
516- print_msg " \nBefore cleaning up, this end-to-end sample created the following set of IBM Cloud resources:"
444+ print_msg " \nThe Fleet demo sandbox has been configured. Please be aware that the created resources will occur costs in your account."
445+ echo " $ ibmcloud resource service-instances --type all -g $resource_group_name "
517446ibmcloud resource service-instances --type all -g $resource_group_name
518447
519- if [[ " ${CLEANUP_ON_SUCCESS} " == true ]]; then
520- print_msg " \nCleaning up the created IBM Cloud resources ..."
521- clean
522- else
523- print_msg " \nThe Fleet demo sandbox has been configured. Please be aware that the created resources will occur costs in your account."
524- echo " $ ibmcloud resource service-instances --type all -g $resource_group_name "
525- ibmcloud resource service-instances --type all -g $resource_group_name
448+ print_msg " \nFollow the tutorial to launch your first Serverless Fleet with './run'"
526449
527- print_msg " \nFollow the tutorial to launch your first Serverless Fleet with './run'"
528-
529- if [[ " $SETUP_LOGGING " == " true" ]]; then
530- print_msg " \nLogging is enabled and logs can be accessed using the IBM Cloud Logs instance '$icl_name ': $icl_dashboard_url "
531- fi
450+ if [[ " $SETUP_LOGGING " == " true" ]]; then
451+ print_msg " \nLogging is enabled and logs can be accessed using the IBM Cloud Logs instance '$icl_name ': $icl_dashboard_url "
532452fi
533453
534454print_success " \n=========================================="
0 commit comments