Created
July 9, 2020 12:57
-
-
Save jgruberf5/7c8f6556f135cdf7dc0ee8fd706419e0 to your computer and use it in GitHub Desktop.
Workflow to Build IBM VPC Custom Images from F5 TMOS VE Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export TMOS_IMAGE_DIR='/data/F5Download/BIGIP-TEST' | |
export ICONTROLLX_RPMS_DIR='/data/iControlLXLatestBuild' | |
# create some object naming | |
export COS_RESOURCE_NAME='custom-tmos-images' | |
export UUID=$(uuid | tr -d '-' | fold -w 8 | head -n 1) | |
export COS_BUCKET_PREFIX="c$UUID" | |
export COS_IMAGE_LOCATION='us-south' | |
export TMOS_IMAGE_CATALOG_URL="https://$COS_BUCKET_PREFIX-$COS_IMAGE_LOCATION.s3.$COS_IMAGE_LOCATION.cloud-object-storage.appdomain.cloud/f5-image-catalog.json" | |
# set docker image creation caching options | |
# CACHE_OPTION='--rm --no-cache' | |
CACHE_OPTION='' | |
# Step 1. Clone tmos-cloudinit locally | |
git clone https://github.com/f5devcentral/tmos-cloudinit | |
cd tmos-cloudinit | |
# Step 2. Patch F5 TMOS Images to include tmos-cloudinit modules and IBM configuration | |
docker build $CACHE_OPTION -t tmos_image_patcher:latest tmos_image_patcher | |
docker run --rm -it -v $TMOS_IMAGE_DIR:/TMOSImages -v $ICONTROLLX_RPM_DIR:/iControlLXPackages -e TMOS_CLOUDINIT_CONFIG_TEMPLATE=/tmos-cloudinit/image_patch_files/cloudinit_configs/ibmcloud_vpc_gen2/cloud-init.tmpl tmos_image_patcher:latest | |
# All the F5 specific work is done. | |
# Step 3. Create IBM COS resources using the ibmcloud CLI client | |
ibmcloud resource group-create $COS_RESOURCE_NAME | |
export COS_RESOURCE_CRN=$(ibmcloud resource service-instance-create $COS_RESOURCE_NAME cloud-object-storage standard global -g $COS_RESOURCE_NAME | grep "^ID:" | tr -s ' ' | cut -d' ' -f2) | |
export COS_API_KEY=$(ibmcloud resource service-key-create $COS_RESOURCE_NAME Manager --instance-id $COS_RESOURCE_CRN -g $COS_RESOURCE_NAME| grep apikey | tr -s ' ' | grep '^ apikey' | cut -d' ' -f3) | |
# Step 4. Upload patched TMOS Images into IBM COS resources via docker client utility from tmos-cloudinit | |
docker build $CACHE_OPTION -t ibmcloud_image_uploader:latest ibmcloud_image_uploader | |
docker run --rm -it -v $TMOS_IMAGE_DIR:/TMOSImages -e COS_API_KEY="$COS_API_KEY" -e COS_RESOURCE_CRN="$COS_RESOURCE_CRN" -e COS_IMAGE_LOCATION="$COS_IMAGE_LOCATION" -e COS_BUCKET_PREFIX="$COS_BUCKET_PREFIX" ibmcloud_image_uploader:latest | |
# Step 5. Import COS Images into VPC custom images | |
# Generate an API key for authorization to create the VPC custom image using the ibmcloud CLI client | |
export API_KEY=$(ibmcloud iam api-key-create $COS_BUCKET_PREFIX-key|grep "^API Key"| tr -s ' ' | cut -d' ' -f3) | |
# Import the VPC custom images using the docker client utility from tmos-cloudinit | |
docker build $CACHE_OPTION -t ibmcloud_vpc_image_importer:latest ibmcloud_vpc_image_importer | |
docker run --rm -it -e API_KEY="$API_KEY" -e TMOS_IMAGE_CATALOG_URL="$TMOS_IMAGE_CATALOG_URL" ibmcloud_vpc_image_importer:latest | |
# Step 6 - Clean up build resources | |
# get rid of the API key used to create the VPC Custom Image | |
ibmcloud iam api-key-delete $COS_BUCKET_PREFIX-key --force | |
# get rid of the IBM COS resources used to store the TMOS image for import | |
ibmcloud resource service-key-delete $COS_RESOURCE_NAME --force | |
ibmcloud resource service-instance-delete $COS_RESOURCE_NAME --force | |
ibmcloud resource group-delete $COS_RESOURCE_NAME --force | |
# git rid of the tmos-cloudinit code | |
cd .. | |
rm -rf ./tmos-cloudinit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment