Commit e42c16e3 authored by sim's avatar sim

Correctly handle dev and prod environment

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