Modify Agent to use Repo Image
[aaf/authz.git] / auth / docker / agent.sh
1 #!/bin/bash
2
3 CADI_VERSION=2.1.2-SNAPSHOT
4
5 # Fill out "aaf.props" if not filled out already
6 if [ ! -e aaf.props ]; then
7   > ./aaf.props
8 fi
9  
10 . ./aaf.props
11
12
13 for V in VERSION DOCKER_REPOSITORY AAF_FQDN AAF_FQDN_IP DEPLOY_FQI APP_FQDN APP_FQI VOLUME DRIVER LATITUDE LONGITUDE; do
14    if [ "$(grep $V ./aaf.props)" = "" ]; then
15       unset DEF
16       case $V in
17          DOCKER_REPOSITORY) 
18                 PROMPT="Docker Repo"
19                 DEF=nexus3.onap.org:10003
20                 ;;
21          AAF_FQDN)   PROMPT="AAF's FQDN";;
22          DEPLOY_FQI) PROMPT="Deployer's FQI";;
23          AAF_FQDN_IP)
24                 # Need AAF_FQDN's IP, because not might not be available in mini-container
25                 PROMPT="AAF FQDN IP"
26                 DEF=$(host $AAF_FQDN | grep "has address" | tail -1 | cut -f 4 -d ' ')
27                 ;;
28          APP_FQI)    PROMPT="App's FQI";; 
29          APP_FQDN)   PROMPT="App's Root FQDN";; 
30          VOLUME)     PROMPT="APP's AAF Configuration Volume";;
31          DRIVER)     PROMPT=$V;DEF=local;;
32          VERSION)    PROMPT="CADI Version";DEF=$CADI_VERSION;;
33          LATITUDE|LONGITUDE) PROMPT="$V of Node";;
34          *)          PROMPT=$V;;
35       esac
36       if [ "$DEF" = "" ]; then
37            PROMPT="$PROMPT: "
38       else 
39            PROMPT="$PROMPT ($DEF): "
40       fi
41       read -p "$PROMPT" VAR 
42       if [ "$VAR" = "" ]; then
43          if [ "$DEF" = "" ]; then
44             echo "agent.sh needs each value queried.  Please start again."
45             exit
46          else
47             VAR=$DEF
48          fi
49       fi
50       echo "$V=$VAR" >> ./aaf.props
51    fi
52 done
53 . ./aaf.props
54
55 # Make sure Container Volume exists
56 if [ "$(docker volume ls | grep ${VOLUME})" = "" ]; then
57   echo -n "Creating Volume: " 
58   docker volume create -d ${DRIVER} ${VOLUME}
59 fi
60
61 docker run \
62     -it \
63     --rm \
64     --mount 'type=volume,src='${VOLUME}',dst=/opt/app/osaaf,volume-driver='${DRIVER} \
65     --add-host="$AAF_FQDN:$AAF_FQDN_IP" \
66     --env AAF_FQDN=${AAF_FQDN} \
67     --env DEPLOY_FQI=${DEPLOY_FQI} \
68     --env DEPLOY_PASSWORD=${DEPLOY_PASSWORD} \
69     --env APP_FQI=${APP_FQI} \
70     --env APP_FQDN=${APP_FQDN} \
71     --env LATITUDE=${LATITUDE} \
72     --env LONGITUDE=${LONGITUDE} \
73     --name aaf_agent_$USER \
74     $DOCKER_REPOSITORY/onap/aaf/aaf_agent:$VERSION \
75     /bin/bash "$@"