Skip to content

Commit

Permalink
techdebt: fix Makefile deploy (#250)
Browse files Browse the repository at this point in the history
* remove unused templates

* move and edit run_template.sh

* move run_template.sh to deploy.sh

* add comments

* pass in parameters to deploy.sh

* use appropriate template dir

* add ${TAG} to deploy target

* stop ignoring templates/broker-deployment

* delete clusterrolebinding

* remove OPENSHIFT USER and PASS variables

* change PROJECT to ORG, also pass to deploy script
  • Loading branch information
jmrodri authored and Erik Nelson committed Jun 30, 2017
1 parent 60dc12c commit f05b5d7
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 216 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ gosrc
etc/dev.config.yaml
etc/prod.config.yaml
etc/mock.config.yaml
templates/broker-deployment.yaml

#Compiled binaries
broker
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
REGISTRY ?= docker.io
PROJECT ?= ansibleplaybookbundle
ORG ?= ansibleplaybookbundle
TAG ?= latest
BROKER_IMAGE ?= $(REGISTRY)/$(PROJECT)/ansible-service-broker
BROKER_IMAGE ?= $(REGISTRY)/$(ORG)/ansible-service-broker
BUILD_DIR = "${GOPATH}/src/github.com/openshift/ansible-service-broker/build"
PREFIX ?= /usr/local
BROKER_CONFIG ?= $(PWD)/etc/generated_local_development.yaml
Expand Down Expand Up @@ -52,7 +52,7 @@ clean:
@rm -f build/broker

deploy:
@${GOPATH}/src/github.com/openshift/ansible-service-broker/scripts/deploy.sh
@${GOPATH}/src/github.com/openshift/ansible-service-broker/scripts/deploy.sh ${BROKER_IMAGE}:${TAG} ${REGISTRY} ${ORG}

test:
go test ./pkg/...
Expand Down
2 changes: 0 additions & 2 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ DOCKERHUB_ORG | ansibleplaybookbundle | Dockerhub organization
DOCKERHUB_USER | changeme | Dockerhub user Name
DOCKERHUB_PASS | changeme | Dockerhub user Password
OPENSHIFT_TARGET | https://kubernetes.default | OpenShift Target URL
OPENSHIFT_USER | admin | OpenShift User Name
OPENSHIFT_PASS | admin | OpenShift User Password
REGISTRY_TYPE | dockerhub | Registry Type
REGISTRY_URL | docker.io | Registry URL
DEV_BROKER | true | Include Broker Development Endpoint (true/false)
Expand Down
104 changes: 63 additions & 41 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,70 @@
#!/bin/bash
PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/..
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT=${SCRIPT_DIR}/..
TEMPLATE_DIR="${PROJECT_ROOT}/templates"

set -e

# Based on https://gist.github.com/pkuczynski/8665367
function parse_yaml() {
local prefix=$2
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_]*'
fs="$(echo @|tr @ '\034')"
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
awk -F"$fs" '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, $3);
}
}' | sed 's/_=/+=/g'
}
# from makefile
BROKER_IMAGE=$1
REGISTRY=$2
DOCKERHUB_ORG=$3

function oc_create {
oc create -f $TEMPLATE_DIR/$@
}
# override with from my_local_dev_vars
PROJECT="ansible-service-broker"
OPENSHIFT_TARGET="https://kubernetes.default"
REGISTRY_TYPE="dockerhub"
DEV_BROKER="true"
LAUNCH_APB_ON_BIND="false"
OUTPUT_REQUEST="true"
RECOVERY="true"
#DOCKERHUB_USERNAME="CHANGEME"
#DOCKERHUB_PASSWORD="CHANGEME"
#DOCKERHUB_ORG="ansibleplaybookbundle"

# process myvars
MY_VARS="${SCRIPT_DIR}/my_local_dev_vars"
if [ ! -f $MY_VARS ]; then
echo "Please create $MY_VARS"
echo "cp $MY_VARS.example $MY_VARS"
echo "then edit as needed"
exit 1
fi

parse_yaml $PROJECT_ROOT/etc/dev.config.yaml > /tmp/dev-config
sed -i "s/=(\"--\")//" /tmp/dev-config

for tpl in services.yaml route.yaml etcd-deployment.yaml broker-deployment.yaml; do
if [ "${tpl}" == "broker-deployment.yaml" ]; then
cp $TEMPLATE_DIR/broker-deployment_template.yaml $TEMPLATE_DIR/$tpl
sed -i "s/{{dockerhub_pass}}/${registry_pass}/" $TEMPLATE_DIR/$tpl
sed -i "s/{{dockerhub_user}}/${registry_user}/" $TEMPLATE_DIR/$tpl
sed -i "s/{{dockerhub_org}}/${registry_org}/" $TEMPLATE_DIR/$tpl
sed -i "s/{{openshift_pass}}/${openshift_pass}/" $TEMPLATE_DIR/$tpl
sed -i "s/{{openshift_target}}/${openshift_target}/" $TEMPLATE_DIR/$tpl
sed -i "s/{{openshift_user}}/${openshift_user}/" $TEMPLATE_DIR/$tpl
source ${MY_VARS}
if [ "$?" -ne "0" ]; then
echo "Error reading in ${MY_VARS}"
exit 1
fi

function validate_var {
if [ -z ${2+x} ]
then
echo "${1} is unset"
exit 1
fi
source /tmp/dev-config
oc_create $tpl
}

# check the variables that do not have defaults
validate_var "BROKER_IMAGE" $BROKER_IMAGE
validate_var "REGISTRY" $REGISTRY
validate_var "DOCKERHUB_USERNAME" $DOCKERHUB_USERNAME
validate_var "DOCKERHUB_PASSWORD" $DOCKERHUB_PASSWORD
validate_var "DOCKERHUB_ORG" $DOCKERHUB_ORG

# configure variables to pass to template
VARS="-p BROKER_IMAGE=${BROKER_IMAGE} -p OPENSHIFT_TARGET=${OPENSHIFT_TARGET} -p DOCKERHUB_ORG=${DOCKERHUB_ORG} -p DOCKERHUB_PASS=${DOCKERHUB_PASS} -p DOCKERHUB_USER=${DOCKERHUB_USER} -p REGISTRY_TYPE=${REGISTRY_TYPE} -p REGISTRY_URL=${REGISTRY} -p DEV_BROKER=${DEV_BROKER} -p LAUNCH_APB_ON_BIND=${LAUNCH_APB_ON_BIND} -p OUTPUT_REQUEST=${OUTPUT_REQUEST} -p RECOVERY=${RECOVERY}"

# cleanup old deployment
oc delete project --ignore-not-found=true ${PROJECT}
oc projects | grep ${PROJECT}
while [ $? -eq 0 ]
do
echo "Waiting for ${PROJECT} to be deleted"
sleep 5;
oc projects | grep ${PROJECT}
done
# delete the clusterrolebinding to avoid template error
oc delete clusterrolebindings --ignore-not-found=true asb

# deploy
oc new-project ${PROJECT}
oc process -f ${TEMPLATE_DIR}/deploy-ansible-service-broker.template.yaml -n ${PROJECT} ${VARS} | oc create -f -
33 changes: 0 additions & 33 deletions templates/broker-deployment_template.yaml

This file was deleted.

56 changes: 0 additions & 56 deletions templates/etcd-deployment.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions templates/route.yaml

This file was deleted.

30 changes: 0 additions & 30 deletions templates/run_template.sh

This file was deleted.

36 changes: 0 additions & 36 deletions templates/services.yaml

This file was deleted.

0 comments on commit f05b5d7

Please sign in to comment.