From 1ff6c15c3bc7d724597867e54204095a832df08e Mon Sep 17 00:00:00 2001 From: Bryan Sullivan Date: Mon, 29 Jan 2018 14:28:04 -0800 Subject: Refactor clearwater build and deploy scripts JIRA: MODELS-2 Change-Id: I2554187ce61112b4757bc8d5865755ccae5acdd3 Signed-off-by: Bryan Sullivan --- build/clearwater-docker.sh | 88 +++++++++++++++++--------- 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 +#. $ docker login -u #. #. Usage: -#. bash clearwater-docker.sh -#. hub-user: username for dockerhub +#. bash clearwater-docker.sh [--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 +#. $ bash k8s-cloudify-clearwater.sh start +#. 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: 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 <~/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 <