|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# set the defaults for docker registry and tag |
| 5 | +DOCKER_REGISTRY=docker-registry.helion.space:443 |
| 6 | +TAG=$(date -u +"%Y%m%dT%H%M%SZ") |
| 7 | + |
| 8 | +while getopts ":r:t:" opt; do |
| 9 | + case $opt in |
| 10 | + r) |
| 11 | + DOCKER_REGISTRY="$OPTARG" |
| 12 | + ;; |
| 13 | + t) |
| 14 | + TAG="$OPTARG" |
| 15 | + ;; |
| 16 | + \?) |
| 17 | + echo "Invalid option: -$OPTARG" >&2 |
| 18 | + exit 1 |
| 19 | + ;; |
| 20 | + :) |
| 21 | + echo "Option -$OPTARG requires an argument." >&2 |
| 22 | + exit 1 |
| 23 | + ;; |
| 24 | + esac |
| 25 | +done |
| 26 | + |
| 27 | +echo "Registry: $DOCKER_REGISTRY" |
| 28 | +echo "Tag: $TAG" |
| 29 | + |
| 30 | +echo "Starting build" |
| 31 | + |
| 32 | +GROUP_NAME=helioncf |
| 33 | +BUILD_ARGS="" |
| 34 | +__DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 35 | + |
| 36 | +#BUILD_ARGS="--build-arg http_proxy=http://proxy.sdc.hp.com:8080" |
| 37 | +#BUILD_ARGS="$BUILD_ARGS --build-arg https_proxy=http://proxy.sdc.hp.com:8080" |
| 38 | + |
| 39 | +function buildAndPublishImage { |
| 40 | + # $1 is name |
| 41 | + # $2 is docker file name |
| 42 | + # $3 is folder name |
| 43 | + |
| 44 | + NAME=$1 |
| 45 | + DOCKER_FILE=$2 |
| 46 | + FOLDER=$3 |
| 47 | + |
| 48 | + if [ ! -d "${FOLDER}" ]; then |
| 49 | + echo "Project ${FOLDER} hasn't been checked out"; |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | + IMAGE_URL=${DOCKER_REGISTRY}/${GROUP_NAME}/${NAME}:${TAG} |
| 54 | + echo Building Docker Image for $NAME |
| 55 | + |
| 56 | + pushd ${FOLDER} |
| 57 | + pwd |
| 58 | + docker build ${BUILD_ARGS} -t $NAME -f $DOCKER_FILE . |
| 59 | + |
| 60 | + docker tag ${NAME} ${IMAGE_URL} |
| 61 | + |
| 62 | + echo Pushing Docker Image ${IMAGE_URL} |
| 63 | + docker push ${IMAGE_URL} |
| 64 | + popd |
| 65 | +} |
| 66 | + |
| 67 | +# Cleanup the SDL/instance defs |
| 68 | +rm -rf ${__DIRNAME}/output/* |
| 69 | + |
| 70 | +# Cleanup prior to generating the UI container |
| 71 | +rm -rf ${__DIRNAME}/../stratos-ui/dist |
| 72 | +rm -rf ${__DIRNAME}/../stratos-server/dist |
| 73 | + |
| 74 | +# Build and publish all of the images for Stratos Console UI |
| 75 | +buildAndPublishImage cnap-console-db Dockerfile.UCP ${__DIRNAME}/../stratos-identity-db |
| 76 | +buildAndPublishImage cnap-console-mock-api Dockerfile.mock_api.UCP ${__DIRNAME}/../stratos-node-server |
| 77 | +buildAndPublishImage cnap-console-mock-auth Dockerfile.mock_auth.UCP ${__DIRNAME}/../stratos-node-server |
| 78 | +buildAndPublishImage cnap-console-api Dockerfile.UCP ${__DIRNAME}/../stratos-node-server |
| 79 | + |
| 80 | +# Build Portal Proxy |
| 81 | +PORTAL_PROXY_PATH=$GOPATH/src/github.com/hpcloud/portal-proxy |
| 82 | +pushd ${PORTAL_PROXY_PATH} |
| 83 | +./tools/build_portal_proxy.sh |
| 84 | +popd |
| 85 | + |
| 86 | +# Build and publish the container image for the portal proxy |
| 87 | +buildAndPublishImage cnap-console-proxy server.Dockerfile ${PORTAL_PROXY_PATH} |
| 88 | + |
| 89 | +# Build the postgres configuration container |
| 90 | +buildAndPublishImage cnap-console-database-configuration database.Dockerfile.UCP ${PORTAL_PROXY_PATH} |
| 91 | + |
| 92 | +# Prepare the nginx server |
| 93 | +docker run --rm \ |
| 94 | + -v ${__DIRNAME}/../stratos-ui:/usr/src/app \ |
| 95 | + -v ${__DIRNAME}/../helion-ui-framework:/usr/src/helion-ui-framework \ |
| 96 | + -v ${__DIRNAME}/../helion-ui-theme:/usr/src/helion-ui-theme \ |
| 97 | + -w /usr/src/app \ |
| 98 | + node:4.2.3 \ |
| 99 | + /bin/bash ./provision.sh |
| 100 | + |
| 101 | +# Copy the artifacts from the above to the stratos-server |
| 102 | +cp -R ${__DIRNAME}/../stratos-ui/dist ${__DIRNAME}/../stratos-server/dist |
| 103 | + |
| 104 | +# Build and push an image based on stratos-server |
| 105 | +buildAndPublishImage cnap-console-server Dockerfile.UCP ${__DIRNAME}/../stratos-server |
| 106 | + |
| 107 | +echo "Creating service and instance definition" |
| 108 | + |
| 109 | +mkdir -p ${__DIRNAME}/output |
| 110 | +for FILE in ${__DIRNAME}/ucp_templates/*.json ; do |
| 111 | + ofile=${__DIRNAME}/output/$(basename $FILE) |
| 112 | + cat $FILE | sed s/{{TAG}}/$TAG/g | sed s/{{REGISTRY}}/$DOCKER_REGISTRY/g > $ofile |
| 113 | +done |
| 114 | + |
| 115 | +echo "Build complete. Tag is $TAG and UCP definitions are in ${__DIRNAME}/output/" |
| 116 | +echo "The definitions are using registry: $DOCKER_REGISTRY and tag: $TAG" |
0 commit comments