UI initial implementation.
[validation.git] / docker / postgresql / 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 export DROOT=/var/lib
18 CONTAINER_NAME="validation_postgresql"
19 POSTGRES_HOST_PORT=6432
20 REGISTRY=akraino
21 NAME=validation
22 TAG_PRE=`echo "${PWD##*/}"`
23 TAG_VER=latest
24 POSTGRES_PASSWORD=""
25 HOST_ARCH=amd64
26
27 # get the architecture of the host
28 if [ "`uname -m`" = "aarch64" ]; then
29     HOST_ARCH=arm64
30 fi
31
32 for ARGUMENT in "$@"
33 do
34     KEY=$(echo $ARGUMENT | cut -f1 -d=)
35     VALUE=$(echo $ARGUMENT | cut -f2 -d=)
36     case "$KEY" in
37             REGISTRY)              REGISTRY=${VALUE} ;;
38             NAME)    NAME=${VALUE} ;;
39             TAG_VER)    TAG_VER=${VALUE} ;;
40             POSTGRES_PASSWORD)    POSTGRES_PASSWORD=${VALUE} ;;
41             *)
42     esac
43 done
44
45 if [ -z "$POSTGRES_PASSWORD" ]
46   then
47     echo "ERROR: You must specify at least the postgreSQL database password"
48     exit 1
49 fi
50
51 IMAGE="$REGISTRY"/"$NAME":"$TAG_PRE"-"$HOST_ARCH"-"$TAG_VER"
52 docker run --detach --name $CONTAINER_NAME --restart=always --publish $POSTGRES_HOST_PORT:5432 --volume $DROOT/postgres:/var/lib/postgresql/data --env POSTGRES_USER=admin --env POSTGRES_PASSWORD="$POSTGRES_PASSWORD" $IMAGE
53 sleep 10
54 docker exec $CONTAINER_NAME /bin/bash -c "psql -h localhost -p 5432 -U admin -f /akraino-blueprint_validation_db.sql"