From fce4f7609a41dd1e85be68f7ae3fbb339363953f Mon Sep 17 00:00:00 2001 From: jjrom Date: Sat, 8 Aug 2020 17:01:14 +0200 Subject: [PATCH] Remove DATABASE_IS_EXTERNAL config param --- README.md | 2 -- config.env | 35 +++++++++++++------------ deploy | 23 ++++++++-------- docker-compose-itagdb.dev.yml | 4 ++- docker-compose-itagdb.yml | 4 ++- scripts/installDatasources.sh | 6 ++--- scripts/installGPW.sh | 6 ++--- scripts/installLandcover.sh | 6 ++--- scripts/updateDatasourcesWithGeoname.sh | 7 +++-- undeploy | 8 +++--- 10 files changed, 52 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 832ff7a..569e1d8 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,6 @@ Note that each time you change the configuration file, you should undeploy then ### External Database By default, iTag will create a local postgres docker image. However, it can also uses an external PostgreSQL database (version 11+). -To use an external database, set the config.env `ITAG_DATABASE_IS_EXTERNAL` parameter to `yes`. - The following extensions must be installed on the target database: * postgis * postgis_topology diff --git a/config.env b/config.env index e842587..cc7bcf9 100644 --- a/config.env +++ b/config.env @@ -8,36 +8,37 @@ ITAG_ENDPOINT=http://localhost:1212 ### itag local exosed port ITAG_EXPOSED_PORT=1212 -# Database port for console access (e.g. psql -h localhost -p ${ITAG_DATABASE_EXPOSED_PORT}) +### Database port for console access (e.g. psql -h ${DATABASE_HOST} -p ${DATABASE_EXPOSED_PORT}) +### [IMPORTANT] +### - For external database, this value should be the same as DATABASE_PORT #ITAG_DATABASE_EXPOSED_PORT=5432 ITAG_DATABASE_EXPOSED_PORT=1213 -# Database configuration -# Is PG cluster already exists somewhere on the network: yes/no -# default is no: a docker for PG is provided and geodata are loaded into a database -# if set to yes, an external PG database, version 11, must be available -# (following PG extensions will be installed in the target database: -# pg_trgm, postgis, postgis_topology, unaccent) -ITAG_DATABASE_IS_EXTERNAL=no - -# you should only change ITAG_DATABASE_USER_PASSWORD if DATABASE_IS_EXTERNAL=no, -# provide postgresql host parameters here -# example for localdg + +### [IMPORTANT] +### - If you set DATABASE_HOST to "itagdb" then a local PostgreSQL container will be created (this is the default) +### - If you want to use an existing external (i.e. not on localhost !) PostgreSQL endpoint then provide a valid hostname +### - If you want to use and existing localhost PostgreSQL, then set the value to "host.docker.internal" +### +ITAG_DATABASE_HOST=itagdb +ITAG_DATABASE_PORT=5432 + +### [IMPORTANT] Usually you should only change the DATABASE_USER_PASSWORD value and leave the other values untouched ITAG_DATABASE_USER_NAME=itag ITAG_DATABASE_USER_PASSWORD=itag ITAG_DATABASE_NAME=itag -ITAG_DATABASE_HOST=itagdb -ITAG_DATABASE_PORT=5432 -# example for external db +# Example for external db #ITAG_DATABASE_USER_NAME=postgres #ITAG_DATABASE_USER_PASSWORD=secret #ITAG_DATABASE_NAME=itag #ITAG_DATABASE_HOST=pg11.toto.eu-west-1.rds.amazonaws.com #ITAG_DATABASE_PORT=5432 -# PostgreSQL PGDATA directory i.e. directory on host where the database files are stored -# If set to a string and not a path, then a volume is created within docker volumes storage +### PostgreSQL PGDATA directory i.e. directory on host where the database files are stored. +### [IMPORTANT] +### - This value should is only used if DATABASE_HOST is set to "restodb" (i.e. for local database container) +### - If set to a string and not a path, then a volume is created within docker volumes storage (this is the default) POSTGRES_DATA=database_data # Maximum area of input geometry for landCover computation (in square kilometers) diff --git a/deploy b/deploy index 22a600c..b37b34b 100755 --- a/deploy +++ b/deploy @@ -121,7 +121,6 @@ ITAG_DATABASE_USER_NAME=$(grep ^ITAG_DATABASE_USER_NAME= ${ENV_FILE} | awk -F= ' ITAG_DATABASE_NAME=$(grep ^ITAG_DATABASE_NAME= ${ENV_FILE} | awk -F= '{print $2}') ITAG_DATABASE_HOST=$(grep ^ITAG_DATABASE_HOST= ${ENV_FILE} | awk -F= '{print $2}') ITAG_DATABASE_PORT=$(grep ^ITAG_DATABASE_PORT= ${ENV_FILE} | awk -F= '{print $2}') -ITAG_DATABASE_IS_EXTERNAL=$(grep ^ITAG_DATABASE_IS_EXTERNAL= ${ENV_FILE} | awk -F= '{print $2}') GPW_DATASOURCE_URL=$(grep ^GPW_DATASOURCE_URL= ${ENV_FILE} | awk -F= '{print $2}') LANDCOVER_DATASOURCE_URL=$(grep ^LANDCOVER_DATASOURCE_URL= ${ENV_FILE} | awk -F= '{print $2}') @@ -143,26 +142,26 @@ echo -e "${YELLOW}[INFO] You're now running itag installation in **${TARGET}** m # echo -e "[INFO] Starting ${PROJECT_NAME} docker instance" if [[ "${TARGET}" == "dev" ]]; then - if [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "yes" ]]; then - COMPOSE_FILE=docker-compose.dev.yml + if [[ "${ITAG_DATABASE_HOST}" == "itagdb" ]]; then + COMPOSE_FILE=docker-compose-itagdb.dev.yml:docker-compose.dev.yml else - COMPOSE_FILE=docker-compose-itagdb.dev.yml:docker-compose.dev.yml + COMPOSE_FILE=docker-compose.dev.yml fi else - if [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "yes" ]]; then - COMPOSE_FILE=docker-compose.yml + if [[ "${ITAG_DATABASE_HOST}" == "itagdb" ]]; then + COMPOSE_FILE=docker-compose-itagdb.yml:docker-compose.yml else - COMPOSE_FILE=docker-compose-itagdb.yml:docker-compose.yml + COMPOSE_FILE=docker-compose.yml fi fi echo "[debug] using compose files: ${COMPOSE_FILE}" COMPOSE_FILE=${COMPOSE_FILE} ENV_FILE=${ENV_FILE} docker-compose --project-name ${PROJECT_NAME} up -d -if [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "yes" ]]; then - DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} -else +if [ "${ITAG_DATABASE_HOST}" == "itagdb" ] || [ "${ITAG_DATABASE_HOST}" == "host.docker.internal" ]; then DATABASE_HOST_SEEN_FROM_DOCKERHOST=localhost +else + DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} fi if [ "${FORCE_DATASOURCES_INSTALL}" == "1" ]; then @@ -227,9 +226,11 @@ echo "" # Display mount point for database # MacOS X is a bit tricky - https://stackoverflow.com/questions/41273514/access-docker-volume-mountpoint-with-docker-for-mac # -if [[ ! "$OSTYPE" == "darwin"* ]] && [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "no" ]]; then +if [[ ! "$OSTYPE" == "darwin"* ]]; then + if [[ "${DATABASE_HOST}" == "itagdb" ]]; then MOUNT_POINT=$(docker volume inspect $(basename `pwd`)"_database_data"| grep Mountpoint | awk -F\" '{print $4}') echo -e "[INFO] Database mount point is ${GREEN}${MOUNT_POINT}${NC}" + fi fi echo -e "[INFO] Application iTag up and running in ${GREEN}${TARGET}${NC} mode at ${GREEN}${ITAG_ENDPOINT}${NC}" diff --git a/docker-compose-itagdb.dev.yml b/docker-compose-itagdb.dev.yml index 5f44a5e..918d8f2 100644 --- a/docker-compose-itagdb.dev.yml +++ b/docker-compose-itagdb.dev.yml @@ -22,6 +22,8 @@ services: - POSTGRES_USER=${ITAG_DATABASE_USER_NAME:-itag} - POSTGRES_PASSWORD=${ITAG_DATABASE_USER_PASSWORD:-itag} - POSTGRES_DB=${ITAG_DATABASE_NAME:-itag} + - POSTGRES_HOST=${ITAG_DATABASE_HOST:-itagdb} + - POSTGRES_PORT=${ITAG_DATABASE_PORT:-5432} ### Server configuration (uncomment to change values) #- POSTGRES_MAX_CONNECTIONS=300 #- POSTGRES_DEFAULT_STATISTICS_TARGET=100 @@ -35,7 +37,7 @@ services: - POSTGRES_LOG_MIN_DURATION_STATEMENT=0 #- POSTGRES_AUTOVACUUM=on ports: - - ${ITAG_DATABASE_EXPOSED_PORT:-1213}:5432 + - ${ITAG_DATABASE_EXPOSED_PORT:-1213}:${ITAG_DATABASE_PORT:-5432} networks: - default healthcheck: diff --git a/docker-compose-itagdb.yml b/docker-compose-itagdb.yml index f93fcce..a5faba4 100644 --- a/docker-compose-itagdb.yml +++ b/docker-compose-itagdb.yml @@ -22,6 +22,8 @@ services: - POSTGRES_USER=${ITAG_DATABASE_USER_NAME:-itag} - POSTGRES_PASSWORD=${ITAG_DATABASE_USER_PASSWORD:-itag} - POSTGRES_DB=${ITAG_DATABASE_NAME:-itag} + - POSTGRES_HOST=${ITAG_DATABASE_HOST:-itagdb} + - POSTGRES_PORT=${ITAG_DATABASE_PORT:-5432} ### Server configuration (uncomment to change values) #- POSTGRES_MAX_CONNECTIONS=300 #- POSTGRES_DEFAULT_STATISTICS_TARGET=100 @@ -35,7 +37,7 @@ services: #- POSTGRES_LOG_MIN_DURATION_STATEMENT=300 #- POSTGRES_AUTOVACUUM=on ports: - - ${ITAG_DATABASE_EXPOSED_PORT:-1213}:5432 + - ${ITAG_DATABASE_EXPOSED_PORT:-1213}:${ITAG_DATABASE_PORT:-5432} networks: - default healthcheck: diff --git a/scripts/installDatasources.sh b/scripts/installDatasources.sh index b0ef2b8..1746a9a 100755 --- a/scripts/installDatasources.sh +++ b/scripts/installDatasources.sh @@ -79,10 +79,10 @@ fi # Source config file . ${ENV_FILE} -if [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "yes" ]]; then - DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} -else +if [ "${ITAG_DATABASE_HOST}" == "itagdb" ] || [ "${ITAG_DATABASE_HOST}" == "host.docker.internal" ]; then DATABASE_HOST_SEEN_FROM_DOCKERHOST=localhost +else + DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} fi # Prepare data directory diff --git a/scripts/installGPW.sh b/scripts/installGPW.sh index abec4de..aba0781 100755 --- a/scripts/installGPW.sh +++ b/scripts/installGPW.sh @@ -78,10 +78,10 @@ fi # Source config file . ${ENV_FILE} -if [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "yes" ]]; then - DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} -else +if [ "${ITAG_DATABASE_HOST}" == "itagdb" ] || [ "${ITAG_DATABASE_HOST}" == "host.docker.internal" ]; then DATABASE_HOST_SEEN_FROM_DOCKERHOST=localhost +else + DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} fi diff --git a/scripts/installLandcover.sh b/scripts/installLandcover.sh index 1561056..b1ce6c0 100755 --- a/scripts/installLandcover.sh +++ b/scripts/installLandcover.sh @@ -78,10 +78,10 @@ fi # Source config file . ${ENV_FILE} -if [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "yes" ]]; then - DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} -else +if [ "${ITAG_DATABASE_HOST}" == "itagdb" ] || [ "${ITAG_DATABASE_HOST}" == "host.docker.internal" ]; then DATABASE_HOST_SEEN_FROM_DOCKERHOST=localhost +else + DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} fi diff --git a/scripts/updateDatasourcesWithGeoname.sh b/scripts/updateDatasourcesWithGeoname.sh index 70f3a7c..6e6b4ed 100755 --- a/scripts/updateDatasourcesWithGeoname.sh +++ b/scripts/updateDatasourcesWithGeoname.sh @@ -78,13 +78,12 @@ fi # Source config file . ${ENV_FILE} -if [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "yes" ]]; then - DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} -else +if [ "${ITAG_DATABASE_HOST}" == "itagdb" ] || [ "${ITAG_DATABASE_HOST}" == "host.docker.internal" ]; then DATABASE_HOST_SEEN_FROM_DOCKERHOST=localhost +else + DATABASE_HOST_SEEN_FROM_DOCKERHOST=${ITAG_DATABASE_HOST} fi - echo -e "[INFO] Udpate datasources tables" PGPASSWORD=${ITAG_DATABASE_USER_PASSWORD} psql -U ${ITAG_DATABASE_USER_NAME} -d ${ITAG_DATABASE_NAME} -h ${DATABASE_HOST_SEEN_FROM_DOCKERHOST} -p ${ITAG_DATABASE_EXPOSED_PORT} > /dev/null 2>errors.log << EOF ALTER TABLE datasources.states ADD COLUMN geonameid INTEGER; diff --git a/undeploy b/undeploy index 3834709..1e04668 100755 --- a/undeploy +++ b/undeploy @@ -19,12 +19,12 @@ NC='\033[0m' ENV_FILE=./config.env PROJECT_NAME=itag -ITAG_DATABASE_IS_EXTERNAL=$(grep ^ITAG_DATABASE_IS_EXTERNAL= ${ENV_FILE} | awk -F= '{print $2}' | sed 's/^"//g' | sed 's/"$//g') +ITAG_DATABASE_HOST=$(grep ^ITAG_DATABASE_HOST= ${ENV_FILE} | awk -F= '{print $2}' | sed 's/^"//g' | sed 's/"$//g') -if [[ "${ITAG_DATABASE_IS_EXTERNAL}" == "yes" ]]; then - COMPOSE_FILE="docker-compose.yml" -else +if [ "${ITAG_DATABASE_HOST}" == "itagdb" ]; then COMPOSE_FILE="docker-compose-itagdb.yml:docker-compose.yml" +else + COMPOSE_FILE="docker-compose.yml" fi echo -e "[INFO] Stopping ${GREEN}${PROJECT_NAME}${NC} docker instance"