Skip to content

Commit

Permalink
add_data: Read variables from environment instead of command-line
Browse files Browse the repository at this point in the history
Instead of manually passing the needed variables as command-line arguments
to add_data.sh in python/Dockerfile, rely on these variables being already
in the environment, as defined either in .env file for Docker Compose,
or in the task definition of Amazon ECS.

Also add a quick environment variable check at the beginning of
add_data.sh to warn if any variable is empty.

This fixes "curl: (3) URL using bad/illegal format or missing URL" error
in "Creating PSRA Kibana Index Patterns" due to unquoted command-line
arguments in python/Dockerfile, causing KIBANA_ENDPOINT to be empty
when the optional ES_USER and ES_PASS are empty.
  • Loading branch information
anthonyfok committed Jun 3, 2021
1 parent 3bbe74a commit 40e10fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ RUN chmod +x add_data.sh && \
apt-get update && \
apt-get install -y eatmydata git git-lfs jq time
#ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]
CMD ./add_data.sh ${POSTGRES_USER} ${POSTGRES_PASS} ${POSTGRES_PORT} ${DB_NAME} ${POSTGRES_HOST} ${ES_ENDPOINT} ${ES_USER} ${ES_PASS} ${KIBANA_ENDPOINT}
CMD ./add_data.sh
33 changes: 23 additions & 10 deletions python/add_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
trap : TERM INT
set -e

POSTGRES_USER=$1
POSTGRES_PASS=$2
POSTGRES_PORT=$3
DB_NAME=$4
POSTGRES_HOST=$5

ES_ENDPOINT=$6
ES_USER=$7
ES_PASS=$8
KIBANA_ENDPOINT=$9
# Needed variables (defined in .env for Docker Compose, or in a Amazon ECS task definition)
ENV_VAR_LIST=(
POSTGRES_USER POSTGRES_PASS POSTGRES_PORT POSTGRES_HOST DB_NAME
POPULATE_DB \
KIBANA_ENDPOINT ES_ENDPOINT ES_USER ES_PASS \
loadDsraScenario loadPsraModels loadHazardThreat loadPhysicalExposure
loadRiskDynamics loadSocialFabric
)

DSRA_REPOSITORY=https://github.com/OpenDRR/scenario-catalogue/tree/master/FINISHED

Expand Down Expand Up @@ -314,6 +312,21 @@ merge_csv() {
####################### Begin main processes #######################
############################################################################################

LOG "# Begin main processes"

LOG "## Check needed environment variables"

for var in "${ENV_VAR_LIST[@]}"; do
INFO "$var = ${!var}"
if [[ -z ${!var} ]]; then
if [[ "$var" =~ ^(ES_USER|ES_PASS)$ ]]; then
INFO "$var is not set, but it is optional"
else
WARN "$var is mandatory but not set! Your build will likely fail!"
fi
fi
done

# Speed up file writes with eatmydata
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+"$LD_LIBRARY_PATH:"}/usr/lib/libeatmydata
LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}libeatmydata.so
Expand Down
3 changes: 3 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Sample .env file used by Docker Compose for python-opendrr service

POSTGRES_USER=postgres
POSTGRES_PASS=password
POSTGRES_PORT=5432
Expand All @@ -7,6 +9,7 @@ POPULATE_DB=0

KIBANA_ENDPOINT=http://kibana-opendrr:5601
ES_ENDPOINT=http://elasticsearch-opendrr:9200
# ES_USER and ES_PASS are optional (can be empty) for local builds
ES_USER=
ES_PASS=

Expand Down

0 comments on commit 40e10fb

Please sign in to comment.