diff options
author | Instrumental <jonathan.gathman@att.com> | 2018-12-12 17:16:30 -0600 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2018-12-12 17:16:52 -0600 |
commit | 218728980874ca82b07a10fceb26debd6045d2ea (patch) | |
tree | 16be83eb05dc48dcc5208ed6d2950991be5fade3 /auth/docker/agent.sh | |
parent | d499a5481bf34b6dfed090efb8c6d78822373e77 (diff) |
Further Batch Refactor
Issue-ID: AAF-670
Change-Id: Ie68280edb7e9d6c495d3905de61372be895dcf3d
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth/docker/agent.sh')
-rw-r--r-- | auth/docker/agent.sh | 184 |
1 files changed, 23 insertions, 161 deletions
diff --git a/auth/docker/agent.sh b/auth/docker/agent.sh index 33db109b..88b8497e 100644 --- a/auth/docker/agent.sh +++ b/auth/docker/agent.sh @@ -18,6 +18,8 @@ # limitations under the License. # ============LICENSE_END==================================================== # + + # Fill out "aaf.props" if not filled out already if [ ! -e aaf.props ]; then > ./aaf.props @@ -25,53 +27,29 @@ fi . ./aaf.props -if [ -z "$ADMIN" ]; then - echo -n "Is the target [K]ubernetes or [D]ocker (K):" - read R - case $R in - d|D) ADMIN=docker - echo "ADMIN=docker" >> aaf.props - ;; - *) ADMIN=kubectl - echo "ADMIN=kubectl" >> aaf.props - ;; - esac -fi - -if [ "$ADMIN" = "docker" ]; then - PROPS="VERSION DOCKER_REPOSITORY AAF_FQDN AAF_FQDN_IP DEPLOY_FQI APP_FQDN APP_FQI VOLUME DRIVER LATITUDE LONGITUDE" - DEF_AAF_FQDN=aaf-onap-test.osaaf.org -else - PROPS="VERSION DOCKER_REPOSITORY NAMESPACE DEPLOY_FQI DEPLOY_PASSWORD AAF_FQDN APP_FQDN APP_FQI VOLUME PVC DRIVER LATITUDE LONGITUDE" - DEF_AAF_FQDN=aaf-locate -fi +DOCKER=${DOCKER:=docker} +CADI_VERSION=${CADI_VERSION:=2.1.9-SNAPSHOT} -for V in $PROPS; do +for V in VERSION DOCKER_REPOSITORY AAF_FQDN AAF_FQDN_IP DEPLOY_FQI APP_FQDN APP_FQI VOLUME DRIVER LATITUDE LONGITUDE; do if [ "$(grep $V ./aaf.props)" = "" ]; then unset DEF case $V in DOCKER_REPOSITORY) - PROMPT="Docker Repo"; DEF="nexus3.onap.org:10003" ;; - AAF_FQDN) PROMPT="AAF's FQDN" - if [ -z "$NAMESPACE" ]; then - DEF=$DEF_AAF_FQDN - else - DEF=$DEF_AAF_FQDN.$NAMESPACE - fi - ;; - DEPLOY_FQI) PROMPT="Deployer's FQI"; DEF="deployer@people.osaaf.org" ;; + PROMPT="Docker Repo" + DEF="" + ;; + AAF_FQDN) PROMPT="AAF's FQDN";; + DEPLOY_FQI) PROMPT="Deployer's FQI";; AAF_FQDN_IP) - # Need AAF_FQDN's IP, because not might not be available in mini-container - PROMPT="AAF FQDN IP" - DEF=$(host $AAF_FQDN | grep "has address" | tail -1 | cut -f 4 -d ' ') - ;; + # Need AAF_FQDN's IP, because not might not be available in mini-container + PROMPT="AAF FQDN IP" + DEF=$(host $AAF_FQDN | grep "has address" | tail -1 | cut -f 4 -d ' ') + ;; APP_FQI) PROMPT="App's FQI";; APP_FQDN) PROMPT="App's Root FQDN";; - VOLUME) PROMPT="App's AAF Configuration Volume";DEF=${APP_FQDN/.*/}-config;; + VOLUME) PROMPT="APP's AAF Configuration Volume";; DRIVER) PROMPT=$V;DEF=local;; - VERSION) PROMPT="CADI Version";DEF=2.1.9-SNAPSHOT;; - NAMESPACE) PROMPT="Kubernetes Namespace";DEF=onap;; - PVC) PROMPT="Persistent Volume Claim";DEF=$VOLUME-pvc;; + VERSION) PROMPT="CADI Version";DEF=$CADI_VERSION;; LATITUDE|LONGITUDE) PROMPT="$V of Node";; *) PROMPT=$V;; esac @@ -87,7 +65,6 @@ for V in $PROPS; do exit else VAR=$DEF - declare $V="$VAR" fi fi echo "$V=$VAR" >> ./aaf.props @@ -95,20 +72,19 @@ for V in $PROPS; do done . ./aaf.props +# Make sure Container Volume exists +if [ "$($DOCKER volume ls | grep ${VOLUME})" = "" ]; then + echo -n "Creating Volume: " + $DOCKER volume create -d ${DRIVER} ${VOLUME} +fi + if [ -n "$DOCKER_REPOSITORY" ]; then PREFIX="$DOCKER_REPOSITORY/" else PREFIX="" fi -if [[ "$ADMIN" =~ docker ]]; then - # Make sure Container Volume exists - if [ "$($ADMIN volume ls | grep ${VOLUME})" = "" ]; then - echo -n "Creating Volume: $VOLUME" - $ADMIN volume create -d ${DRIVER} ${VOLUME} - fi - - $ADMIN run \ +$DOCKER run \ -it \ --rm \ -v "${VOLUME}:/opt/app/osaaf" \ @@ -123,117 +99,3 @@ if [[ "$ADMIN" =~ docker ]]; then --name aaf_agent_$USER \ "$PREFIX"onap/aaf/aaf_agent:$VERSION \ /bin/bash "$@" -else - NAMESPACE=${NAMESPACE:=onap} - YAML=${VOLUME}.yaml - # Make sure Container Volume exists - if [ -z "$($ADMIN -n $NAMESPACE get pv | grep ${VOLUME})" ]; then - if [ ! -r $YAML ]; then - SIZE=30M - echo "---" >> $YAML - echo "kind: PersistentVolume" >> $YAML - echo "apiVersion: v1" >> $YAML - echo "metadata:" >> $YAML - echo " name: $VOLUME-pv" >> $YAML - echo " namespace: $NAMESPACE" >> $YAML - echo " labels:" >> $YAML - echo " app: $VOLUME" >> $YAML - echo " type: local" >> $YAML - echo "spec:" >> $YAML - echo " capacity:" >> $YAML - echo " storage: $SIZE" >> $YAML - echo " accessModes:" >> $YAML - echo " - ReadWriteOnce" >> $YAML - echo " hostPath:" >> $YAML - echo " path: \"/data/$VOLUME\"" >> $YAML - echo " storageClassName: \"manual\"" >> $YAML - echo "---" >> $YAML - echo "kind: PersistentVolumeClaim" >> $YAML - echo "apiVersion: v1" >> $YAML - echo "metadata:" >> $YAML - echo " name: $VOLUME-pvc" >> $YAML - echo " namespace: $NAMESPACE" >> $YAML - echo " labels:" >> $YAML - echo " app: $VOLUME" >> $YAML - echo " type: local" >> $YAML - echo "spec:" >> $YAML - echo " selector:" >> $YAML - echo " matchLabels:" >> $YAML - echo " app: $VOLUME" >> $YAML - echo " accessModes:" >> $YAML - echo " - ReadWriteOnce" >> $YAML - echo " resources:" >> $YAML - echo " requests:" >> $YAML - echo " storage: $SIZE" >> $YAML - echo " storageClassName: "manual"" >> $YAML - fi - $ADMIN -n $NAMESPACE create -f $YAML - fi - POD=aaf-agent-$USER - $ADMIN run -n $NAMESPACE $POD \ - -i --rm \ - --restart=Never \ - --image="$PREFIX"onap/aaf/aaf_agent:$VERSION \ - --overrides=' -{ - "apiVersion": "v1", - "kind": "Pod", - "metadata": { - "name": "'$POD'" - }, - "spec": { - "volumes": [{ - "name": "'$VOLUME'", - "persistentVolumeClaim": { - "claimName": "'$VOLUME'-pvc" - } - }], - "containers": [ - { - "name": "aaf-agent-'$USER'", - "imagePullPolicy": "IfNotPresent", - "image": "'$PREFIX'onap/aaf/aaf_agent:'$VERSION'", - "args": [ - "/bin/bash", - "'$@'" - ], - "stdin": true, - "stdinOnce": true, - "tty": true, - "volumeMounts": [ - { - "mountPath": "/opt/app/osaaf", - "name": "'$VOLUME'" - } - ], - "env": [ - { - "name": "AAF_FQDN", - "value": "'$AAF_FQDN'" - },{ - "name": "DEPLOY_FQI", - "value": "'$DEPLOY_FQI'" - },{ - "name": "DEPLOY_PASSWORD", - "value": "'$DEPLOY_PASSWORD'" - },{ - "name": "APP_FQI", - "value": "'$APP_FQI'" - },{ - "name": "APP_FQDN", - "value": "'$APP_FQDN'" - },{ - "name": "LATITUDE", - "value": "'$LATITUDE'" - },{ - "name": "LONGITUDE", - "value": "'$LONGITUDE'" - } - ] - } - ] - } -}' - - -fi |