diff options
author | 2018-01-29 14:28:04 -0800 | |
---|---|---|
committer | 2018-01-29 14:28:04 -0800 | |
commit | 1ff6c15c3bc7d724597867e54204095a832df08e (patch) | |
tree | 2525f2719d8c64b5646cbf9d0d91454e021df2c6 | |
parent | 05bc6725c5d09adc25495c56e54af7a7ee155e49 (diff) |
Refactor clearwater build and deploy scripts
JIRA: MODELS-2
Change-Id: I2554187ce61112b4757bc8d5865755ccae5acdd3
Signed-off-by: Bryan Sullivan <bryan.sullivan@att.com>
-rw-r--r-- | build/clearwater-docker.sh | 88 | ||||
-rw-r--r-- | tools/cloudify/k8s-cloudify-clearwater.sh | 102 |
2 files changed, 147 insertions, 43 deletions
diff --git a/build/clearwater-docker.sh b/build/clearwater-docker.sh index a8228ca..9fa4bde 100644 --- a/build/clearwater-docker.sh +++ b/build/clearwater-docker.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2017 AT&T Intellectual Property, Inc +# Copyright 2018 AT&T Intellectual Property, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,44 +18,74 @@ #. #. Prerequisites: #. Docker hub user logged on so images can be pushed to docker hub, i.e. via -#. $ docker login -u <hub-user> +#. $ docker login -u <hub_user> #. #. Usage: -#. bash clearwater-docker.sh <hub-user> -#. hub-user: username for dockerhub +#. bash clearwater-docker.sh <hub_user> <tag> [--no-cache] +#. hub_user: username for dockerhub +#. tag: tag to apply to the built images +#. --no-cache: build clean #. #. Status: this is a work in progress, under test. +trap 'fail' ERR + +fail() { + log "Build Failed!" + exit 1 +} + +function log() { + f=$(caller 0 | awk '{print $2}') + l=$(caller 0 | awk '{print $1}') + echo "" + echo "$f:$l ($(date)) $1" +} + +function build() { + log "Starting clearwater-docker build process" + if [[ -d /tmp/clearwater-docker ]]; then rm -rf /tmp/clearwater-docker; fi + + log "Cloning clearwater-docker repo to /tmp/clearwater-docker" + git clone https://github.com/Metaswitch/clearwater-docker.git \ + /tmp/clearwater-docker + + log "Building the images" + cd /tmp/clearwater-docker + vnfc="base astaire cassandra chronos bono ellis homer homestead homestead-prov ralf sprout" + for i in $vnfc ; do + log "Building $i" + sudo docker build $cache -t clearwater/$i $i + done +} + +function push() { + log "push images to docker hub" + for i in $vnfc ; do + log "Tagging the image as $hub_user/clearwater-$i:$tag" + id=$(sudo docker images | grep clearwater/$i | awk '{print $3}') + id=$(echo $id | cut -d ' ' -f 1) + sudo docker tag $id $hub_user/clearwater-$i:$tag + + log "Pushing the image to dockerhub as $hub_user/clearwater-$i" + sudo docker push $hub_user/clearwater-$i + done +} + +hub_user=$1 +tag=$2 +cache="$3" dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'` +export WORK_DIR=$(pwd) -echo; echo "$0 $(date): Update package repos" +log "Update package repos" if [ "$dist" == "Ubuntu" ]; then sudo apt-get update else sudo yum update -y fi -echo; echo "$0 $(date): Starting VES agent build process" -if [[ -d /tmp/clearwater-docker ]]; then rm -rf /tmp/clearwater-docker; fi - -echo; echo "$0 $(date): Cloning clearwater-docker repo to /tmp/clearwater-docker" - git clone https://github.com/Metaswitch/clearwater-docker.git \ - /tmp/clearwater-docker - -echo; echo "$0 $(date): Building the images" -cd /tmp/clearwater-docker -vnfc="base astaire cassandra chronos bono ellis homer homestead homestead-prov ralf sprout" -for i in $vnfc ; do - sudo docker build -t clearwater/$i $i -done - -echo; echo "$0 $(date): push images to docker hub" -for i in $vnfc ; do - echo; echo "$0 $(date): Tagging the image as $1/clearwater-$i:latest" - id=$(sudo docker images | grep clearwater/$i | awk '{print $3}') - id=$(echo $id | cut -d ' ' -f 1) - sudo docker tag $id $1/clearwater-$i:latest - - echo; echo "$0 $(date): Pushing the image to dockerhub as $1/clearwater-$i" - sudo docker push $1/clearwater-$i -done +build +push + +cd $WORK_DIR diff --git a/tools/cloudify/k8s-cloudify-clearwater.sh b/tools/cloudify/k8s-cloudify-clearwater.sh index 430d31a..5ed19a3 100644 --- a/tools/cloudify/k8s-cloudify-clearwater.sh +++ b/tools/cloudify/k8s-cloudify-clearwater.sh @@ -28,7 +28,12 @@ #. From a server with access to the kubernetes master node: #. $ git clone https://gerrit.opnfv.org/gerrit/models ~/models #. $ cd ~/models/tools/cloudify/ -#. $ bash k8s-cloudify-clearwater.sh <start|stop> <hub-user> <manager> +#. $ bash k8s-cloudify-clearwater.sh start <k8s_master_hostname> <image_path> <image_tag> +#. k8s_master_hostname: hostname of the k8s master node +#. image_path: "image path" for images (e.g. user on docker hub) +#. image_tag: "image tag" for images e.g. latest, test, stable +#. $ bash k8s-cloudify-clearwater.sh stop> <k8s_master_hostname> +#. k8s_master_hostname: hostname of the k8s master node #. #. Status: this is a work in progress, under test. @@ -45,17 +50,18 @@ function log() { } function build_local() { - master=$1 log "deploy local docker registry on k8s master" # Per https://docs.docker.com/registry/deploying/ ssh -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ - ubuntu@$master sudo docker run -d -p 5000:5000 --restart=always --name \ + ubuntu@$k8s_master sudo docker run -d -p 5000:5000 --restart=always --name \ registry registry:2 # per https://github.com/Metaswitch/clearwater-docker log "clone clearwater-docker" cd ~ - git clone https://github.com/Metaswitch/clearwater-docker.git + if [[ ! -d ~/clearwater-docker ]]; then + git clone --recursive https://github.com/Metaswitch/clearwater-docker.git + fi log "build docker images" cd clearwater-docker @@ -67,16 +73,16 @@ function build_local() { # workaround for https://www.bountysource.com/issues/37326551-server-gave-http-response-to-https-client-error # May not need both... if [[ "$dist" == "ubuntu" ]]; then - check=$(grep -c $master /etc/default/docker) + check=$(grep -c $k8s_master /etc/default/docker) if [[ $check -eq 0 ]]; then - echo "DOCKER_OPTS=\"--insecure-registry $master:5000\"" | sudo tee -a /etc/default/docker + echo "DOCKER_OPTS=\"--insecure-registry $k8s_master:5000\"" | sudo tee -a /etc/default/docker sudo systemctl daemon-reload sudo service docker restart fi fi check=$(grep -c insecure-registry /lib/systemd/system/docker.service) if [[ $check -eq 0 ]]; then - sudo sed -i -- "s~ExecStart=/usr/bin/dockerd -H fd://~ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry $master:5000~" /lib/systemd/system/docker.service + sudo sed -i -- "s~ExecStart=/usr/bin/dockerd -H fd://~ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry $k8s_master:5000~" /lib/systemd/system/docker.service sudo systemctl daemon-reload sudo service docker restart fi @@ -87,27 +93,95 @@ function build_local() { log "push images to local docker repo on k8s master" for i in $vnfc ; do - docker tag clearwater/$i:latest $master:5000/clearwater/$i:latest - docker push $master:5000/clearwater/$i:latest + docker tag clearwater/$i:latest $k8s_master:5000/clearwater/$i:latest + docker push $k8s_master:5000/clearwater/$i:latest done } - function start() { - master=$1 + ssh -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ + $k8s_user@$k8s_master <<EOF +echo "create configmap" +kubectl create configmap env-vars --from-literal=ZONE=default.svc.cluster.local --from-literal=ADDITIONAL_SHARED_CONFIG=log_level=5 + +echo "clone clearwater-docker" +git clone --recursive https://github.com/Metaswitch/clearwater-docker.git +cd clearwater-docker/kubernetes + +echo "generate k8s config with --image_path=$1 --image_tag=$2" +./k8s-gencfg --image_path=$1 --image_tag=$2 + +echo "prefix clearwater- to image names" +sed -i -- "s~$1/~$1/clearwater-~" *.yaml + +echo "change ellis-svc to NodePort" +sed -i -- "s/clusterIP: None/type: NodePort/" ellis-svc.yaml +sed -i -- "/port: 80/a\ \ \ \ nodePort: 30880" ellis-svc.yaml + +echo "deploying" +kubectl apply -f ../kubernetes +EOF +} + +function run_test() { + ssh -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ + $k8s_user@$k8s_master <<EOG +cat <<EOF >~/callsip.yaml +apiVersion: v1 +kind: Pod +metadata: + name: callsip + namespace: default +spec: + containers: + - name: callsip + image: ubuntu + command: + - sleep + - "3600" + imagePullPolicy: IfNotPresent + restartPolicy: Always +EOF +kubectl create -f ~/callsip.yaml +kubectl exec -d --namespace default callsip <<EOF +apt-get update +apt-get install -y git netcat +apt-get install dnsutils -y +nslookup bono.default.svc.cluster.local +git clone https://github.com/rundekugel/callSip.sh.git +while true ; do + bash /callSip.sh/src/callSip.sh -v 4 -p 5060 -d 10 -s bono.default.svc.cluster.local -c bob@example.com alice@example.com +done +EOF +EOG } function stop() { - master=$1 + ssh -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ + $k8s_user@$k8s_master <<'EOF' +deps="astaire bono chronos ellis etcd homer homestead homestead-prov ralf sprout cassandra" +for dep in $deps ; do + echo "deleting deployment $dep" + kubectl delete deployment --namespace default $dep + kubectl delete service --namespace default $dep +done +kubectl delete configmap env-vars +rm -rf clearwater-docker +EOF } dist=$(grep --m 1 ID /etc/os-release | awk -F '=' '{print $2}') +source ~/k8s_env_$2.sh + case "$1" in "start") - start $2 + start $3 $4 + ;; + "test") + run_test ;; "stop") - stop $2 + stop ;; *) grep '#. ' $0 |