Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made taxbrain install script more usable #817

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install:
- export PATH="$HOME/miniconda/bin:$PATH"
- python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
- pushd deploy
- ./install_taxbrain_server.sh
- ./install_taxbrain_server.sh --all
- popd
- source activate aei_dropq

Expand Down
130 changes: 97 additions & 33 deletions deploy/install_taxbrain_server.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,99 @@
#!/bin/bash
install_env(){
export has_env=1;
conda env remove --name aei_dropq &> /dev/null;
conda env create --file fab/dropq_environment.yml || return 0;
return 0;
# Interactive installation script.
# For a fresh install, simply run:
# ./install_taxbrain_server.sh --all
# Optionally, pipe all output to /dev/null:
# ./install_taxbrain_server.sh --all > /dev/null
# For slow connections, it is helpful to increase the timeout for package downloads.
# To do so, add the following to your ~/.condarc file:
# remote_read_timeout_secs: 1000.0

set -e

# Gets the path to the current script's directory.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Paths to the requirements files that are installed.
REQS_FILES=(
${SCRIPT_DIR}/../requirements.txt
${SCRIPT_DIR}/../requirements_dev.txt
${SCRIPT_DIR}/requirements.txt
)

# Path to the log directory.
LOGDIR=${SCRIPT_DIR}/taxbrain_server/logs

# Name of the environment (in the DROPQ_YML_PATH file).
AEI_ENV_NAME='aei_dropq'

# The path to the dropq_environment.yml definition.
DROPQ_YML_PATH=${SCRIPT_DIR}/fab/dropq_environment.yml

# Setting to run everything automatically.
RUN_ALL=0
if [[ $# -eq 1 && $1 == "--all" ]]; then
RUN_ALL=1
fi

# Defines a finction that prompts the user for a particular action.
prompt_user() {
if [[ $RUN_ALL -eq 1 ]]; then
echo "$1 :: YES"
return 0
fi
printf "$1 [y/N] "
read -p "" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
return 0
else
return 1
fi
}
install_conda_reqs(){
echo ---------------------------------------Installing conda requirements;
channel="-c ospc/label/dev -c ospc "
for pkg in $(cat ../conda-requirements.txt);do
echo $pkg | grep -Eoi "(btax)|(ogusa)|(taxcalc)" &> /dev/null || echo install $channel $pkg && conda install $channel $pkg -y || return 1;
done
echo install $channel ogusa -y
conda install $channel ogusa -y
}
install_reqs(){
install_conda_reqs || return 1;
echo Install webapp-public requirements.txt
pip install -r ../requirements.txt || return 1;
echo Install webapp-public requirements_dev.txt
pip install -r ../requirements_dev.txt || return 1;
echo Install requirements.txt of the deploy folder;
pip install -r requirements.txt || return 1;
pip uninstall -y taxbrain_server &> /dev/null;
pip install -e . || return 1;
rm -rf taxbrain_server/logs
mkdir taxbrain_server/logs || return 1;
return 0;
}
msg(){
echo Local server installation complete!
return 0;
}
install_env && source activate aei_dropq && install_reqs && msg || echo FAILED

# Creates a new environment, or resets the current environment.
if prompt_user "Create / reset environment?"; then
if [[ $(conda env list) =~ $AEI_ENV_NAME ]]; then
if prompt_user "Remove existing environment?"; then
conda env remove --name $AEI_ENV_NAME
conda env create --file $DROPQ_YML_PATH
else
conda env update --file $DROPQ_YML_PATH
fi
else
conda env create --file $DROPQ_YML_PATH
fi
fi

# Everything from here down is done in the environment.
echo "source activate $AEI_ENV_NAME"
source activate $AEI_ENV_NAME

if prompt_user "Install conda requirements?"; then
conda install \
--yes \
-c ospc/label/dev \
-c ospc \
--file ${SCRIPT_DIR}/../conda-requirements.txt
fi

# Installs package requirements (including the current package).
if prompt_user "Install package requirements?"; then
REQUIREMENTS=()
for reqs in "${REQS_FILES[@]}"; do
REQUIREMENTS+=("-r $reqs")
done
echo "pip install ${REQUIREMENTS[@]}"
pip install ${REQUIREMENTS[@]}
# Installs project in development mode.
pip install -e .
fi

# Reinitializes the log directory.
if prompt_user "Re-initialize logs directory?"; then
rm -rf ${SCRIPT_DIR}/taxbrain_server/logs/*
fi

echo "Finished creating environment; to start, run:"
echo " source webapp_env.sh"

2 changes: 2 additions & 0 deletions webapp_env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source activate aei_dropq

export NUM_BUDGET_YEARS=10
export DEV_DEBUG=True
export HTML_MINIFY=True
Expand Down