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 +++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 29 deletions(-) (limited to 'build') 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 -- cgit 1.2.3-korg