<commit_before>#!/bin/bash
# ------------------------------------------------------------------------
#
# Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

# ------------------------------------------------------------------------
set -e

kubernetes_artifact_version=1.0.0
node_scp_address=core@172.17.8.102
default_profile=default
source environment.bash
source ~/.bash_profile

# build common image
prgdir=`dirname "$0"`
current_path=`cd "$prgdir"; pwd`
root_dir=${current_path}/..
common_dir=${current_path}/../common
base_image_dir=`cd "${common_dir}/docker/base-image"; pwd`

user=`whoami`
echo "user executing the script $user" 


# navigate to base image dir
pushd $base_image_dir
# build
#  sudo bash build.sh ${kubernetes_artifact_version} 
# go back to previous directory location
popd

function build_docker_image_and_scp {
    # switch to IS 5 docker directory and build
    pushd ${root_dir}/$1/docker
    echo pwd=`pwd`
    sudo --preserve-env bash build.sh $2 ${kubernetes_artifact_version} $3
    # save the image as a tar file
    sudo bash save.sh $2 ${kubernetes_artifact_version} $3
    sudo chown $user:$user -R ~/docker/ 
    bash scp.sh ${node_scp_address} $2 ${kubernetes_artifact_version} $3
    popd
}

function deploy_kubernetes_artifacts {
    # switch to IS 5 kubernetes directory deploy kubernetes artifacts
    pushd ${root_dir}/$1/kubernetes
    bash deploy.sh    
    popd
}

function undeploy_kubernetes_artifacts {
    # switch to IS 5 kubernetes directory deploy kubernetes artifacts
    pushd ${root_dir}/$1/kubernetes
    bash undeploy.sh
    popd
}


# build and deploy
build_docker_image_and_scp 'wso2is' '5.0.0' "${default_profile}"
deploy_kubernetes_artifacts 'wso2is'
<commit_msg>adding a loop for product + version tuples<commit_after>#!/bin/bash
# ------------------------------------------------------------------------
#
# Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

# ------------------------------------------------------------------------

########################### Simple Test Script ############################
# 
#   This script will build the default version of specified docker images, 
#   scp them to the Kubernetes nodes and deploy the Kubernetes artifacts.
#
#   Tested with the Kubernetes setup at:
#   https://github.com/pires/kubernetes-vagrant-coreos-cluster
#
#   Usage: 
#   1. set PUPPET_HOME in environment.bash
#   2. add the products and version that need to be tested to the array 
#      'products' as comma separated tuples.
#       ex.: products=(wso2am,1.9.1 wso2is,5.0.0)
#   3. run the script
#
#
###########################################################################

set -e

kubernetes_artifact_version=1.0.0
node_scp_address=core@172.17.8.102
default_profile=default
source environment.bash
source ~/.bash_profile

# build common image
prgdir=`dirname "$0"`
current_path=`cd "$prgdir"; pwd`
root_dir=${current_path}/..
common_dir=${current_path}/../common
base_image_dir=`cd "${common_dir}/docker/base-image"; pwd`

user=`whoami`
echo "user executing the script $user"

function build_base_image {
    # navigate to base image dir
    pushd $base_image_dir
    # build
    # sudo bash build.sh ${kubernetes_artifact_version}
    # go back to previous directory location
    popd
}

function build_docker_image_and_scp {
    # switch to IS 5 docker directory and build
    pushd ${root_dir}/$1/docker
    echo pwd=`pwd`
    sudo --preserve-env bash build.sh $2 ${kubernetes_artifact_version} $3
    # save the image as a tar file
    sudo bash save.sh $2 ${kubernetes_artifact_version} $3
    sudo chown $user:$user -R ~/docker/ 
    bash scp.sh ${node_scp_address} $2 ${kubernetes_artifact_version} $3
    popd
}

function deploy_kubernetes_artifacts {
    # switch to IS 5 kubernetes directory deploy kubernetes artifacts
    pushd ${root_dir}/$1/kubernetes
    bash deploy.sh    
    popd
}

function undeploy_kubernetes_artifacts {
    # switch to IS 5 kubernetes directory deploy kubernetes artifacts
    pushd ${root_dir}/$1/kubernetes
    bash undeploy.sh
    popd
}

# build the base images
build_base_image
# build and deploy the products
products=(wso2am,1.9.1 wso2is,5.1.0)

for product in ${products[@]}; do
    IFS=","
    set $product
    echo "############################### testing $1 v.$2 ###############################"
    echo 'building docker image for='$1 ' version='$2
    build_docker_image_and_scp "$1" "$2" "${default_profile}"
    echo 'deploying kubernetes artifacts for='$1 ' version='$2
    deploy_kubernetes_artifacts "$1"
    sleep 10s
    echo 'undeploying kubernetes artifacts for='$1 ' version='$2
    undeploy_kubernetes_artifacts "$1"
    echo "########################## completed testing $1 v.$2 ##########################"
    unset IFS
done


{'fraction_non_alphanumeric': 0.1786994367639529, 'fraction_numerical': 0.020139955623826592, 'mean_word_length': 3.3088235294117645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3042835', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1680, 'n_words': 561}