Commit adde6239 authored by sim's avatar sim

Correctly handle dev and prod environment

parent cd41fddb
......@@ -5,7 +5,7 @@
You need `pipenv` and an up-to-date version of `pip`. To setup development
environment and run test server:
$ make dev
$ make
$ pipenv run ./manage runserver
......@@ -46,10 +46,19 @@ If you use `pipenv shell`, don't forget to leave the virtualenv (`exit` or
To bootstrap Gargantext environment just cd into your local Gargantext repo and
do:
$ make dev
$ make
Or for production (without dev dependencies and without DEBUG mode):
$ make TARGET=prod
To specify a path for configuration file (by default gargantext.ini in current
directory), use GARGANTEXT_CONF environment variable. For example:
$ GARGANTEXT_CONF=/etc/gargantext/gargantext.ini make TARGET=prod
If everything is going well, you now have a clean virtualenv with every
packages you need to run Gargantext.
packages you need to run Gargantext, and a fresh configuration file.
You can now run any command by prefixing it with `pipenv run` or by first
entering the virtualenv with `pipenv shell`. To run Gargantext django backend
......
.PHONY: dev prod env conf
.PHONY: gargantext env conf
dev: conf env
@echo "• Installing dependencies..."
pipenv install --dev
@echo
ifeq ($(TARGET), "prod")
TARG=prod
PIPENV_ARGS=
else
TARG=dev
PIPENV_ARGS=--dev
endif
prod: conf env
gargantext: conf env
@echo "• Installing dependencies..."
pipenv install
pipenv install $(PIPENV_ARGS)
@echo
env:
@echo "• Setup django settings module..."
@echo "• Setup django settings module and configuration path..."
./tools/mkenv.sh
@echo
conf:
@echo "• Setup gargantext configuration..."
./tools/mkconf.sh
./tools/mkconf.sh $(TARG)
@echo
#!/usr/bin/env bash
# Handle arguments
while getopts f option; do
case "${option}"
in
f) FORCE=1;;
while :; do
case $1 in
-h|--help) echo "Usage: $0 [-h|--help] [-f|--force] [dev|prod]"; exit;;
-f|--force) FORCE=1;;
--) shift; break;;
*) break
esac
shift
done
# Gargantext configuration file
# Target can be dev or prod
TARGET="${1:-dev}"
# Gargantext configuration file path
[ -z "$GARGANTEXT_CONF" ] && GARGANTEXT_CONF=gargantext.ini
# Configuration template
# Configuration template path
TEMPLATE=tools/gargantext.template.ini
# Check for configuration file existence
if [ -f "$GARGANTEXT_CONF" -a -z "$FORCE" ]; then
echo "Configuration file $GARGANTEXT_CONF already exists. To generate a" \
"new configuration anyway you can do: ./tools/mkconf.sh -f"
echo -e "Configuration file $GARGANTEXT_CONF already exists, you may" \
"need to edit it.\nTo generate a new configuration anyway you" \
"can do: ./tools/mkconf.sh -f $TARGET"
exit
fi
# Check permissions for configuration file
D=$(dirname $GARGANTEXT_CONF)
if ! (mkdir -p $D && touch $GARGANTEXT_CONF 2>/dev/null); then
echo "Can't create $GARGANTEXT_CONF, please check permissions."
exit 1
fi
# Setup DEBUG mode for dev target
[ "$TARGET" = "prod" ] && DEBUG=False || DEBUG=True
echo "Generate secret key for Django..."
SECRET_KEY=$(python ./tools/gensecret.py)
echo "PostgreSQL configuration..."
DB_NAME_DEFAULT=gargandb
DB_USER_DEFAULT=gargantua
DB_NAME_DEFAULT=gargandb
DB_USER_DEFAULT=gargantua
read -p "Database name [$DB_NAME_DEFAULT]: " DB_NAME
DB_NAME=${DB_NAME:-$DB_NAME_DEFAULT}
read -p "Database name [$DB_NAME_DEFAULT]: " DB_NAME
DB_NAME=${DB_NAME:-$DB_NAME_DEFAULT}
read -p "Database user [$DB_USER_DEFAULT]: " DB_USER
DB_USER=${DB_USER:-$DB_USER_DEFAULT}
read -p "Database user [$DB_USER_DEFAULT]: " DB_USER
DB_USER=${DB_USER:-$DB_USER_DEFAULT}
read -s -p "Please provide the password for $DB_USER: " DB_PASS && echo
read -s -p "Please provide the password for $DB_USER: " DB_PASS && echo
# Escape variables
SECRET_KEY=$(echo -n "$SECRET_KEY" | sed -e 's/[/&\]/\\&/g')
......@@ -49,13 +61,14 @@ DB_USER=$(echo -n "$DB_USER" | sed -e 's/[/&\]/\\&/g')
DB_PASS=$(echo -n "$DB_PASS" | sed -e 's/[/&\]/\\&/g')
echo "Generate configuration file from $TEMPLATE..."
sed -E -e 's/[{]DEBUG[}]/True/g' \
sed -E -e "s/[{]DEBUG[}]/$DEBUG/g" \
-e "s/[{]SECRET_KEY[}]/$SECRET_KEY/g" \
-e "s/[{]DB_NAME[}]/$DB_NAME/g" \
-e "s/[{]DB_USER[}]/$DB_USER/g" \
-e "s/[{]DB_PASS[}]/$DB_PASS/g" \
"$TEMPLATE" > "$GARGANTEXT_CONF" \
&& echo "Configuration written successfully in $GARGANTEXT_CONF."
&& echo "Configuration for $TARGET environment written successfully in" \
"$GARGANTEXT_CONF."
[ -z "$DB_PASS" ] && echo "You didn't provide any database password, please" \
"edit $GARGANTEXT_CONF before running Gargantext."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment