[UI] Handling users and passwords
[validation.git] / docker / ui / deploy.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2019 AT&T Intellectual Property.  All other rights reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -ex
18
19 # Container name
20 CONTAINER_NAME="akraino-validation-ui"
21 # Image data
22 REGISTRY=akraino
23 NAME=validation
24 TAG_PRE=ui
25 TAG_VER=latest
26 # Container input parameters
27 MYSQL_AKRAINO_PASSWORD=""
28 JENKINS_URL="https://jenkins.akraino.org/"
29 JENKINS_USERNAME="demo"
30 JENKINS_USER_PASSWORD="demo"
31 JENKINS_JOB_NAME="validation"
32 DB_IP_PORT=""
33 NEXUS_PROXY=""
34 JENKINS_PROXY=""
35 CERTDIR=$(pwd)
36 ENCRYPTION_KEY=""
37 UI_ADMIN_PASSWORD=""
38
39 for ARGUMENT in "$@"
40 do
41     KEY=$(echo $ARGUMENT | cut -f1 -d=)
42     VALUE=$(echo $ARGUMENT | cut -f2 -d=)
43     case "$KEY" in
44             REGISTRY)              REGISTRY=${VALUE} ;;
45             NAME)    NAME=${VALUE} ;;
46             TAG_PRE)    TAG_PRE=${VALUE} ;;
47             TAG_VER)    TAG_VER=${VALUE} ;;
48             MYSQL_AKRAINO_PASSWORD)    MYSQL_AKRAINO_PASSWORD=${VALUE} ;;
49             JENKINS_URL)    JENKINS_URL=${VALUE} ;;
50             JENKINS_USERNAME)    JENKINS_USERNAME=${VALUE} ;;
51             JENKINS_USER_PASSWORD)    JENKINS_USER_PASSWORD=${VALUE} ;;
52             JENKINS_JOB_NAME)    JENKINS_JOB_NAME=${VALUE} ;;
53             DB_IP_PORT)    DB_IP_PORT=${VALUE} ;;
54             CONTAINER_NAME)    CONTAINER_NAME=${VALUE} ;;
55             NEXUS_PROXY) NEXUS_PROXY=${VALUE} ;;
56             JENKINS_PROXY) JENKINS_PROXY=${VALUE} ;;
57             CERTDIR) CERTDIR=${VALUE} ;;
58             ENCRYPTION_KEY) ENCRYPTION_KEY=${VALUE} ;;
59             UI_ADMIN_PASSWORD) UI_ADMIN_PASSWORD=${VALUE} ;;
60             *)
61     esac
62 done
63
64 if [ -z "$DB_IP_PORT" ]
65   then
66     echo "ERROR: You must specify the database IP and port"
67     exit 1
68 fi
69
70 if [ -z "$MYSQL_AKRAINO_PASSWORD" ]
71   then
72     echo "ERROR: You must specify the mysql akraino user password"
73     exit 1
74 fi
75
76 if [ -z "$ENCRYPTION_KEY" ]
77   then
78     echo "ERROR: You must specify the encryption key"
79     exit 1
80 fi
81
82 if [ -z "$UI_ADMIN_PASSWORD" ]
83   then
84     echo "ERROR: You must specify the UI admin password"
85     exit 1
86 fi
87
88 echo "Note: If there is a password already stored in database, the supplied UI_ADMIN_PASSWORD will be ignored."
89
90 IMAGE="$REGISTRY"/"$NAME":"$TAG_PRE"-"$TAG_VER"
91 docker run --detach --name $CONTAINER_NAME --network="host" -v "$(pwd)/server.xml:/usr/local/tomcat/conf/server.xml" -v "$CERTDIR/bluval.key:/usr/local/tomcat/bluval.key" -v "$CERTDIR/bluval.crt:/usr/local/tomcat/bluval.crt" -v "$(pwd)/root_index.jsp:/usr/local/tomcat/webapps/ROOT/index.jsp" -e DB_IP_PORT="$DB_IP_PORT" -e MYSQL_AKRAINO_PASSWORD="$MYSQL_AKRAINO_PASSWORD" -e JENKINS_URL="$JENKINS_URL" -e JENKINS_USERNAME="$JENKINS_USERNAME" -e JENKINS_USER_PASSWORD="$JENKINS_USER_PASSWORD" -e JENKINS_JOB_NAME="$JENKINS_JOB_NAME" -e NEXUS_PROXY="$NEXUS_PROXY" -e JENKINS_PROXY="$JENKINS_PROXY" -e ENCRYPTION_KEY="$ENCRYPTION_KEY" -e UI_ADMIN_PASSWORD="$UI_ADMIN_PASSWORD" $IMAGE
92 sleep 10