From a2b8267cd56abc4ac273798f581c037179f510a5 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Thu, 16 Nov 2017 19:19:19 -0500 Subject: [PATCH] Environmental variables, nginx templates --- .env | 3 +++ .gitignore | 1 + Dockerfile | 2 +- docker-compose.yml | 7 +++++-- nginx/.gitignore | 2 ++ nginx/{nginx.conf => nginx.conf.template} | 3 +-- start.sh | 14 +++++++++++++- webodm.sh | 11 +++++++++++ 8 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 .env create mode 100644 nginx/.gitignore rename nginx/{nginx.conf => nginx.conf.template} (96%) diff --git a/.env b/.env new file mode 100644 index 00000000..267b2443 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +HOST=webodm.localhost +PORT=8000 +APP_MEDIA_DIR=appmedia diff --git a/.gitignore b/.gitignore index 1ef28f69..cdbf6af3 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,4 @@ node_modules/ webpack-stats.json pip-selfcheck.json .idea/ +package-lock.json diff --git a/Dockerfile b/Dockerfile index c660d544..0b73a535 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ RUN printf "deb http://mirror.steadfast.net/debian/ stable main contrib n RUN printf "deb http://mirror.steadfast.net/debian/ testing main contrib non-free\ndeb-src http://mirror.steadfast.net/debian/ testing main contrib non-free" > /etc/apt/sources.list.d/testing.list # Install GDAL, nginx -RUN apt-get update && apt-get install -t testing -y binutils libproj-dev gdal-bin nginx +RUN apt-get update && apt-get install -t testing -y binutils libproj-dev gdal-bin nginx gettext-base WORKDIR /webodm/nodeodm/external/node-OpenDroneMap RUN npm install diff --git a/docker-compose.yml b/docker-compose.yml index 593a477a..8457bf48 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,9 +19,12 @@ services: container_name: webapp entrypoint: /bin/bash -c "chmod +x /webodm/*.sh && /bin/bash -c \"/webodm/wait-for-it.sh db:5432 -- /webodm/start.sh\"" volumes: - - appmedia:/webodm/app/media + - ${MEDIA_DIR}:/webodm/app/media ports: - - "8000:8000" + - "${PORT}:8000" depends_on: - db + environment: + - PORT + - HOST restart: on-failure:10 \ No newline at end of file diff --git a/nginx/.gitignore b/nginx/.gitignore new file mode 100644 index 00000000..077ba2b0 --- /dev/null +++ b/nginx/.gitignore @@ -0,0 +1,2 @@ +ssl/ +*.conf diff --git a/nginx/nginx.conf b/nginx/nginx.conf.template similarity index 96% rename from nginx/nginx.conf rename to nginx/nginx.conf.template index 18b39fbd..b107206b 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf.template @@ -31,8 +31,7 @@ http { listen 8000 deferred; client_max_body_size 0; - # set the correct host(s) for your site - server_name webodm.localhost; + server_name $HOST; keepalive_timeout 5; diff --git a/start.sh b/start.sh index 3abaac25..b467ce59 100755 --- a/start.sh +++ b/start.sh @@ -74,7 +74,19 @@ if [ "$1" = "--setup-devenv" ] || [ "$2" = "--setup-devenv" ] || [ "$1" = "--no- else if [ -e /webodm ] && [ ! -e /webodm/build/static ]; then echo -e "\033[91mWARN:\033[39m /webodm/build/static does not exist, CSS, JS and other files might not be available." - fi + fi + + # If this is invoked outside docker, we need to make sure + # envsubst returns a valid config file... + export HOST="${HOST:=webodm.localhost}" + + echo "Generating nginx configurations from templates..." + for templ in nginx/*.template + do + echo "- $templ" + envsubst '\$HOST \$OTHER_VAR' < $templ > ${templ%.*} + done + nginx -c $(pwd)/nginx/nginx.conf gunicorn webodm.wsgi --bind unix:/tmp/gunicorn.sock --timeout 360 --preload fi diff --git a/webodm.sh b/webodm.sh index a0910343..e3a20ae0 100755 --- a/webodm.sh +++ b/webodm.sh @@ -16,6 +16,11 @@ if [[ $platform = "Windows" ]]; then export COMPOSE_CONVERT_WINDOWS_PATHS=1 fi +# Set default ENV variables +export PORT="${WEBODM_PORT:=8000}" +export HOST="${WEBODM_HOST:=webodm.localhost}" +export MEDIA_DIR="${WEBODM_MEDIA_DIR:=appmedia}" + usage(){ echo "Usage: $0 [options]" echo @@ -121,6 +126,12 @@ resetpassword(){ if [[ $1 = "start" ]]; then environment_check echo "Starting WebODM..." + + + echo -e "Host: \033[92m\033[1m$PORT\033[0m\033[39m" + echo -e "Port: \033[92m\033[1m$HOST\033[0m\033[39m" + echo -e "Media dir: \033[92m\033[1m$HOST\033[0m\033[39m" + start elif [[ $1 = "stop" ]]; then environment_check