From 5d015ee4b345bf797e3664cf0ac56e427e0fdb82 Mon Sep 17 00:00:00 2001 From: boyamurthy <92081029+boyamurthy@users.noreply.github.com> Date: Thu, 18 Nov 2021 16:58:02 +0530 Subject: [PATCH] updating build server and ubim version (#34) --- .build.config | 26 +++ .build.config.user | 2 + build.sh | 367 ++++++++++++++++++++++++++++++++++ helm/csi-powermax/values.yaml | 9 +- 4 files changed, 400 insertions(+), 4 deletions(-) create mode 100644 .build.config create mode 100644 .build.config.user create mode 100644 build.sh diff --git a/.build.config b/.build.config new file mode 100644 index 00000000..9ce63a56 --- /dev/null +++ b/.build.config @@ -0,0 +1,26 @@ +BUILD: + TYPE: R + REPO: localhost:5000 + NAMESPACE: powermax + NUMBER: 0 +GO: + VERSION: 1.16.3 +CENTOS: + REPO: "" + NAMESPACE: centos + VERSION: centos8.2.2004 +RHEL: + REPO: registry.access.redhat.com + NAMESPACE: rhel7/rhel + VERSION: 7.7-529 +UBI: + REPO: registry.access.redhat.com + NAMESPACE: ubi8/ubi + VERSION: 8.3-227 +UBIM: + REPO: registry.access.redhat.com + NAMESPACE: ubi8/ubi-minimal + VERSION: 8.5-204 + SHA: e0814339ffc6c933652bed0c5f8b6416b9a3d40be2f49f95e6e4128387d2a24a +IMAGE: + NAME: csi-powermax diff --git a/.build.config.user b/.build.config.user new file mode 100644 index 00000000..786cfff0 --- /dev/null +++ b/.build.config.user @@ -0,0 +1,2 @@ +IMAGE: + NAME: csi-powermax diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..0ddcbc28 --- /dev/null +++ b/build.sh @@ -0,0 +1,367 @@ +#!/bin/bash +# This script will build an image for the PowerMax CSI Driver +# Before running this script, make sure that you have Docker engine (> v17) +# or podman installed on your system +# If you are going to push the image to an image repo, make sure that you are logged in + +# This script parses the config file(s) present in the same folder to use as an environment for the build + + +# Defaults +IMAGE_NAME="csi-powermax" +REVPROXY_IMAGE_NAME="csipowermax-reverseproxy" +NOPROMPT=false +PUSH_IMAGE=false +BUILD_REVPROXY=false +OVERWRITE_IMAGE=false +EXTRA_TAGS=false + +function print_usage { + echo + echo "`basename ${0}`" + echo " -p - Push the image to the repo specified via config" + echo " -y - Don't prompt the user" + echo " -o - Overwrite existing local/remote image" + echo " -e - Create additionals tags for latest, minor and major versions" + echo " -i - Set the image type. Accepted values are ubim, ubi, centos and rhel" + echo " -r - Build the CSI PowerMax ReverseProxy image along with driver image" + echo " -c - Delete the local image after a successful build" + echo + echo "Default values are specified via the .build.config file. They can be overridden by creating a .build.config.user file" +} + +function git_version { + local gitdesc=$(git describe --long) + local version="${gitdesc%%-*}" + MAJOR_VERSION=$(echo $version | cut -d. -f1) + MINOR_VERSION=$(echo $version | cut -d. -f2) + PATCH_NUMBER=$(echo $version | cut -d. -f3) + BUILD_NUMBER_FROM_GIT=$(sed -e 's#.*-\(\)#\1#' <<< "${gitdesc%-*}") + printf -v TEMP_BUILD_NUMBER "%03d" $BUILD_NUMBER_FROM_GIT +} + +function parse_config { + local prefix=$2 + local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') + sed -ne "s|^\($s\):|\1|" \ + -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | + awk -F$fs '{ + indent = length($1)/2; + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i /var/jenkins/workspace/patch1_info + if [ "$EXTRA_TAGS" = true ]; then + if [ -n "$BUILD_REPO" ]; then + IMAGE_LATEST_TAG="$IMAGE_TAG:latest" + IMAGE_VERSION_WITH_PATCH_TAG="$IMAGE_TAG:$MAJOR_VERSION.$MINOR_VERSION.$PATCH_NUMBER" + else + echo "BUILD_REPO not specified but EXTRA tags are enabled. Skipping creation of extra tags" + EXTRA_TAGS=false + fi + fi +} + +function build_image { + # Check if a local image exists with the same tag + echo "###################### BUILDING IMAGE ########################" + echo $BUILDCMD inspect --type=image $IMAGE_VERSION_TAG + $BUILDCMD image inspect $IMAGE_VERSION_TAG >/dev/null 2>&1 && image_exists=true || image_exists=false + if [[ $image_exists == "true" ]] && [[ $OVERWRITE_IMAGE == "false" ]] ; then + echo "A local image with the same tag exists. Enable the over-write option (-o) and run the script again" + exit 1 + fi + if [ "$EXTRA_TAGS" = true ]; then + echo $BUILDCMD build -t $IMAGE_VERSION_TAG\ + -t $IMAGE_LATEST_TAG\ + -t $IMAGE_VERSION_WITH_PATCH_TAG\ + -f csi-powermax/Dockerfile.build .\ + --build-arg BUILD_NUMBER=$BUILD_NUMBER\ + --build-arg BUILD_TYPE=$BUILD_TYPE\ + --build-arg GO_VERSION=$GO_VERSION\ + --build-arg SOURCE_IMAGE_TAG=$SOURCE_IMAGE_TAG\ + --build-arg SOURCE_REPO=$SOURCE_REPO\ + --build-arg IMAGE_TYPE=$IMAGE_TYPE\ + $DOCKEROPT + (cd .. && + $BUILDCMD build -t "$IMAGE_VERSION_TAG"\ + -t "$IMAGE_LATEST_TAG"\ + -t "$IMAGE_VERSION_WITH_PATCH_TAG"\ + -f csi-powermax/Dockerfile.build .\ + --build-arg BUILD_NUMBER="$BUILD_NUMBER"\ + --build-arg BUILD_TYPE="$BUILD_TYPE"\ + --build-arg GO_VERSION="$GO_VERSION"\ + --build-arg SOURCE_IMAGE_TAG="$SOURCE_IMAGE_TAG"\ + --build-arg SOURCE_REPO="$SOURCE_REPO"\ + --build-arg IMAGE_TYPE="$IMAGE_TYPE"\ + $DOCKEROPT) + if [ "$BUILD_REVPROXY" = true ]; then + echo $BUILDCMD build -t "$REVPROXY_IMAGE_VERSION_TAG" + (cd csireverseproxy && $BUILDCMD build -t "$REVPROXY_IMAGE_VERSION_TAG" . ) + fi + else + echo $BUILDCMD build -t $IMAGE_VERSION_TAG\ + -f csi-powermax/Dockerfile.build .\ + --build-arg BUILD_NUMBER=$BUILD_NUMBER\ + --build-arg BUILD_TYPE=$BUILD_TYPE\ + --build-arg GO_VERSION=$GO_VERSION\ + --build-arg SOURCE_IMAGE_TAG=$SOURCE_IMAGE_TAG\ + --build-arg SOURCE_REPO=$SOURCE_REPO\ + --build-arg IMAGE_TYPE="$IMAGE_TYPE"\ + $DOCKEROPT + (cd .. && + $BUILDCMD build -t "$IMAGE_VERSION_TAG"\ + -f csi-powermax/Dockerfile.build .\ + --build-arg BUILD_NUMBER="$BUILD_NUMBER"\ + --build-arg BUILD_TYPE="$BUILD_TYPE"\ + --build-arg GO_VERSION="$GO_VERSION"\ + --build-arg SOURCE_IMAGE_TAG="$SOURCE_IMAGE_TAG"\ + --build-arg SOURCE_REPO="$SOURCE_REPO"\ + --build-arg IMAGE_TYPE="$IMAGE_TYPE"\ + $DOCKEROPT) + if [ "$BUILD_REVPROXY" = true ]; then + echo $BUILDCMD build -t "$REVPROXY_IMAGE_VERSION_TAG" . + (cd csireverseproxy && $BUILDCMD build -t "$REVPROXY_IMAGE_VERSION_TAG" . ) + fi + fi +} + +function push_image { + echo $BUILDCMD push $IMAGE_TAG + $BUILDCMD push $IMAGE_VERSION_TAG + if [ "$BUILD_REVPROXY" = true ]; then + $BUILDCMD push $REVPROXY_IMAGE_VERSION_TAG + fi + if [ "$EXTRA_TAGS" = true ]; then + echo $BUILDCMD push $IMAGE_LATEST_TAG + $BUILDCMD push $IMAGE_LATEST_TAG + echo $BUILDCMD push $IMAGE_VERSION_WITH_PATCH_TAG + $BUILDCMD push $IMAGE_VERSION_WITH_PATCH_TAG + fi +} + +function set_image_type { + input_image_type=$1 + valid_image_type='false' + if [[ ( $input_image_type == "CENTOS" ) || ( $input_image_type == "centos" ) ]]; then + SOURCE_IMAGE_TYPE="centos" + valid_image_type='true' + elif [[ ( $input_image_type == "RHEL" ) || ( $input_image_type == "rhel" ) ]]; then + SOURCE_IMAGE_TYPE="rhel" + valid_image_type='true' + elif [[ ( $input_image_type == "UBI" ) || ( $input_image_type == "ubi" ) ]]; then + SOURCE_IMAGE_TYPE="ubi" + valid_image_type='true' + elif [[ ( $input_image_type == "UBIM" ) || ( $input_image_type == "ubim" ) ]]; then + SOURCE_IMAGE_TYPE="ubim" + valid_image_type='true' + fi + if [ "$valid_image_type" = false ] ; then + echo "Invalid image type specified" + exit 1 + fi +} +IMAGE_TYPE_SET=false +# Read options +while getopts 'cpyheori:' flag; do + case "${flag}" in + c) DELETE_IMAGE='true' ;; + p) PUSH_IMAGE='true' ;; + y) NOPROMPT='true' ;; + e) EXTRA_TAGS='true' ;; + o) OVERWRITE_IMAGE='true' ;; + r) BUILD_REVPROXY='true' ;; + i) IMAGE_TYPE_SET=true;set_image_type $OPTARG;; + h) print_usage + exit 0;; + *) print_usage + exit 1 ;; + esac +done + +if [ "$IMAGE_TYPE_SET" = false ]; then + echo "Missing argument: -i must be supplied to provide the image type" >&2 + exit 1 +fi + +BUILDCMD="docker" +DOCKEROPT="--format=docker" + +if [[ ( $SOURCE_IMAGE_TYPE == "ubi" ) || ( $SOURCE_IMAGE_TYPE == "ubim" ) || ( $SOURCE_IMAGE_TYPE == "rhel" ) ]]; then + command -v podman + if [ $? -eq 0 ]; then + echo "Using podman for building image" + BUILDCMD="podman" + else + echo "podman must be installed for building RHEL/UBI based image" + exit 1 + fi +else + command -v docker + if [ $? -eq 0 ]; then + echo "Using docker for building image" + BUILDCMD="docker" + DOCKEROPT="" + else + echo "Couldn't find docker. Looking for podman" + command -v podman + if [ $? -eq 0 ]; then + echo "Using podman for building image" + BUILDCMD="podman" + else + echo "Failed to find docker or podman. Exiting with failure" + exit 1 + fi + fi +fi + +# After finding the toolset, fail immediately after any error +set -e + +# Get the version from git tag +git_version + +# Read the config and the user config (if specified) +eval "$(parse_config .build.config)" +if [ -e .build.config.user ]; then + eval "$(parse_config .build.config.user)" +fi + +IMAGE_TYPE="others" + +if [ "$SOURCE_IMAGE_TYPE" = "centos" ]; then + SOURCE_IMAGE_TAG=$CENTOS_VERSION +elif [ "$SOURCE_IMAGE_TYPE" = "rhel" ]; then + SOURCE_IMAGE_TAG=$RHEL_VERSION + IMAGE_NAME="$IMAGE_NAME-$SOURCE_IMAGE_TYPE" +elif [ "$SOURCE_IMAGE_TYPE" = "ubi" ]; then + SOURCE_IMAGE_TAG=$UBI_VERSION +elif [ "$SOURCE_IMAGE_TYPE" = "ubim" ]; then + if [ -n "$UBIM_SHA" ]; then + # We need to use the SHA + SOURCE_IMAGE_TAG=$UBIM_SHA + else + SOURCE_IMAGE_TAG=$UBIM_VERSION + fi + IMAGE_TYPE="ubim" +fi + +build_source_image_repo_name + +if [ "$SOURCE_IMAGE_TYPE" = "ubim" ]; then + if [ -n "$UBIM_SHA" ]; then + SOURCE_REPO="$SOURCE_REPO@sha256" + fi +fi + +# Check if BUILD_NUMBER is set +if [ -n "$BUILD_NUMBER" ]; then + printf -v BUILD_NUMBER_FROM_ENV "%03d" $BUILD_NUMBER + echo "BUILD_NUMBER specified via environment and set to:" $BUILD_NUMBER_FROM_ENV + BUILD_NUMBER=$BUILD_NUMBER_FROM_ENV +else + BUILD_NUMBER=$TEMP_BUILD_NUMBER +fi +# Check if Build Type is set +if [ -n "$BUILD_TYPE" ]; then + echo "BUILD_TYPE specified via environment and set to:" $BUILD_TYPE +else + echo "BUILD_TYPE not specified. Defaulting to : 'X'" + BUILD_TYPE="X" +fi + +VERSION="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_NUMBER.$BUILD_NUMBER$BUILD_TYPE" + +# Build image tags +build_image_tags + +# Build the image +build_image + +if [ "$PUSH_IMAGE" = true ]; then + echo "###################### PUSH IMAGE ############################" + echo "IMAGE REPOSITORY is set to :" $BUILD_REPO + if [ -n "$BUILD_REPO" ]; then + [[ $NOPROMPT == "false" ]] && read -n 1 -p "Are you sure you want to push to the above image repository (y/n)? " YN && echo + [[ $YN == "y" || $YN == "Y" || $YN == "" ]] && push_image + else + echo "IMAGE REPOSITORY not set. Nothing to push to" + exit 1 + fi +fi + +if [ "$DELETE_IMAGE" = true ]; then + echo "####################### DELETING LOCAL IMAGE #####################" + IMAGE_ID=$($BUILDCMD images $IMAGE_VERSION_TAG --format "{{.ID}}") + echo "IMAGE ID: "$IMAGE_ID + $BUILDCMD images | grep $IMAGE_ID | awk '{print $1 ":" $2}' | xargs $BUILDCMD rmi +fi diff --git a/helm/csi-powermax/values.yaml b/helm/csi-powermax/values.yaml index 670bea53..a80d21ec 100644 --- a/helm/csi-powermax/values.yaml +++ b/helm/csi-powermax/values.yaml @@ -32,9 +32,6 @@ global: # Example: https://0.0.0.1:8443 managementServers: - endpoint: https://unisphere-address:8443 - # Current version of the driver - # Don't modify this value as this value will be used by the install script - version: "2.0.0" # If you are using the CSI PowerMax ReverseProxy then comment the section # 'without reverse proxy configuration' above and uncomment the following section # and fill out the required configuration @@ -71,6 +68,10 @@ global: # credentialsSecret: backup-2-secret # skipCertificateValidation: true +# Current version of the driver +# Don't modify this value as this value will be used by the install script +version: "2.0.0" + ## K8S/DRIVER ATTRIBUTES ######################## # customDriverName: If enabled, sets the driver name to the @@ -359,4 +360,4 @@ authorization: # "false" - TLS certificate will be verified # Default value: "true" skipCertificateValidation: true - \ No newline at end of file +