Skip to content

Commit

Permalink
Remove DATABASE_IS_EXTERNAL config param
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrom committed Aug 8, 2020
1 parent f8050e8 commit fce4f76
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 49 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 18 additions & 17 deletions config.env
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 12 additions & 11 deletions deploy
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand All @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
4 changes: 3 additions & 1 deletion docker-compose-itagdb.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion docker-compose-itagdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions scripts/installDatasources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions scripts/installGPW.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions scripts/installLandcover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 3 additions & 4 deletions scripts/updateDatasourcesWithGeoname.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions undeploy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fce4f76

Please sign in to comment.