Skip to content

Commit 3b73686

Browse files
committed
stripped fleet init and removed jumpbox creation
1 parent e7a8f1c commit 3b73686

File tree

2 files changed

+91
-105
lines changed

2 files changed

+91
-105
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
# ==============================
4+
# COMMON FUNCTIONS
5+
# ==============================
6+
7+
RED="\033[31m"
8+
BLUE="\033[94m"
9+
GREEN="\033[32m"
10+
ENDCOLOR="\033[0m"
11+
12+
function print_error {
13+
echo -e "${RED}\n==========================================${ENDCOLOR}"
14+
echo -e "${RED} FAILED${ENDCOLOR}"
15+
echo -e "${RED}==========================================\n${ENDCOLOR}"
16+
echo -e "${RED}$1${ENDCOLOR}"
17+
echo -e ""
18+
}
19+
function print_msg {
20+
echo -e "${BLUE}$1${ENDCOLOR}"
21+
}
22+
function print_success {
23+
echo -e "${GREEN}$1${ENDCOLOR}"
24+
}
25+
26+
# Helper function to check whether prerequisites are installed
27+
function check_prerequisites {
28+
# Ensure that jq tool is installed
29+
if ! command -v jq &>/dev/null; then
30+
print_error "'jq' tool is not installed"
31+
exit 1
32+
fi
33+
}
34+
35+
# ==============================
36+
# COMMON IBMCLOUD HELPERS
37+
# ==============================
38+
39+
# helper function to check whether IBM Cloud CLI plugins should get updated, or not
40+
function ensure_plugin_is_up_to_date() {
41+
echo "Checking $1 ..."
42+
# check whether plugin is installed
43+
if ! ibmcloud plugin show $1 -q >/dev/null; then
44+
# install it
45+
ibmcloud plugin install $1 -f --quiet
46+
else
47+
# check whether there is an update available
48+
ibmcloud plugin update $1 -f --quiet
49+
fi
50+
}
51+
52+
function target_region {
53+
print_msg "\nTargetting IBM Cloud region '$1' ..."
54+
current_region=$(ibmcloud target --output JSON |jq -r '.region|.name')
55+
if [[ "$current_region" != "$1" ]]; then
56+
ibmcloud target -r $1 --quiet
57+
fi
58+
}
59+
60+
function target_resource_group {
61+
print_msg "\nTargetting resource group '$resource_group_name' ..."
62+
current_resource_group=$(ibmcloud target --output JSON |jq -r '.resource_group|.name')
63+
if [[ "$current_resource_group" != "$1" ]]; then
64+
ibmcloud target -g $1 --quiet
65+
fi
66+
}

experimental/serverless-fleets/init-fleet-sandbox

Lines changed: 25 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ CLEANUP_ON_ERROR=${CLEANUP_ON_ERROR:=false}
55
CLEANUP_ON_SUCCESS=${CLEANUP_ON_SUCCESS:=false}
66
REGION="${REGION:=eu-de}"
77
NAME_PREFIX="${NAME_PREFIX:=ce-fleet-sandbox}"
8-
DEBUG_MODE="${DEBUG_MODE:=false}"
9-
REGISTRY=${REGISTRY:-icr.io/codeengine}
108
SETUP_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
6337
function clean() {
@@ -140,6 +114,8 @@ function abortScript() {
140114
exit 1
141115
}
142116

117+
118+
143119
if [[ "$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
169145
print_msg "\nInstalling required experiemental IBM Cloud CLI plugins ..."
170146
export 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

176152
print_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
185161
fi
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
308283
fi
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-
314285
print_msg "\nCreating required VPC Security group rules ..."
315286
ibmcloud 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
317287
ibmcloud is security-group-rule-add $vpc_name-group inbound all --remote $vpc_name-group --vpc $vpc_name >/dev/null
318288
echo "Done"
319289

@@ -356,54 +326,6 @@ if [[ "$SETUP_MONITORING" == "true" ]]; then
356326
fi
357327
fi
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
409331
print_msg "\nCreating COS instance '${cos_name}' ..."
@@ -461,15 +383,21 @@ if [ $? -ne 0 ]; then
461383
fi
462384
project_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+
464395
print_msg "\nCreating an API Key '${apikey_name}' for ICR credentials ..."
465396
apikey="$(ibmcloud iam api-key-create ${apikey_name} -q -o json|jq -r '.apikey')"
466397

467398
print_msg "\nCreating a Code Engine secret 'fleet-registry-secret' for ICR credentials ..."
468399
ibmcloud 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
474402
print_msg "\nCreating a Code Engine configmap 'fleet-vpc-config' to access the new VPC ..."
475403
ibmcloud ce configmap create --name fleet-vpc-config \
@@ -513,22 +441,14 @@ if [[ "$SETUP_MONITORING" == "true" ]]; then
513441
--from-literal MONITORING_INGESTION_REGION=${REGION}
514442
fi
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"
517446
ibmcloud 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"
532452
fi
533453

534454
print_success "\n=========================================="

0 commit comments

Comments
 (0)