diff --git a/Dockerfile b/Dockerfile index 890b4db..a65c882 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM python:3.6 COPY requirements.txt ./requirements.txt RUN pip install -r requirements.txt -COPY . /usr/var/ -WORKDIR /usr/var/ +COPY . /usr/var/MapBot +WORKDIR /usr/var/MapBot -CMD ["python", "./init.py"] +ENTRYPOINT ["/bin/sh","./docker-entrypoint.sh"] diff --git a/ENV/.env b/ENV/.env new file mode 100644 index 0000000..c623119 --- /dev/null +++ b/ENV/.env @@ -0,0 +1,9 @@ +DB_USER=root +DB_PASSWORD= +DB_HOST=localhost +DATABASE=mapbot +DB_PORT=3306 +GCLOUD_API_KEY= +JAVAHOME= +STANFORD_PATH_TO_JAR= +STANFORD_PATH_TO_MODELS_JAR= diff --git a/ENV/docker.env b/ENV/docker.env new file mode 100644 index 0000000..246c639 --- /dev/null +++ b/ENV/docker.env @@ -0,0 +1,9 @@ +DB_USER=root +DB_PASSWORD=root +DB_HOST=db +DATABASE=mapbot +DB_PORT=3306 +GCLOUD_API_KEY= +JAVAHOME=/usr/local/openjdk-11/bin/java +STANFORD_PATH_TO_JAR=./stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2.jar +STANFORD_PATH_TO_MODELS_JAR=./stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2-models.jar diff --git a/README.md b/README.md index 8fbefec..2ac22c9 100644 --- a/README.md +++ b/README.md @@ -48,19 +48,9 @@ Check out all related information [here](GSSoC.md) - Enter root password when prompted - `create database mapbot;` - Verify creation of the database `show databases;` -- Unzip the StanfordCoreNLP package in the repository and keep the file names `stanford-corenlp-x.x.x.jar` and `stanford-corenlp-x.x.x-models.jar` handy. -- Run `git rm --cached config.py` -- Create a file `.env` in the base directory of the repository -- Copy the content of `template.txt` into `.env` -- Edit the `.env` file with the corresponding values - - mapbotuser = "root" - - mapbotpassword = - - mapbothost = "localhost" - - mapbotdatabase = "mapbot" - - mapbotkey = - - stanford_path_to_jar = - - stanford_path_to_models_jar = - - javahome = +- Unzip the StanfordCoreNLP package in the repository and keep the file paths `stanford-corenlp-x.x.x.jar` and `stanford-corenlp-x.x.x-models.jar` handy. +- Run `git update-index --assume-unchanged ENV/*` +- Fill the existing template in `ENV/.env` with the corresponding values following the `KEY=VALUE` format - Install dependencies from `requirements.txt` file. Run `pip install -r requirements.txt` - You're all set up, run the `init.py` file. `python init.py` - It is recommended that you set this project up in a virtual environment to keep the dependencies separated and for easier debugging. Here's how you can do that - @@ -71,22 +61,15 @@ Check out all related information [here](GSSoC.md) #### What are some pre-requisites? (with Docker) -- StanfordCoreNLP - - StanfordCoreNLP has a dependency on Java 8. `java -version` should complete successfully with version 1.8 or higher. - - Windows- Download as a .zip file from [here](https://stanfordnlp.github.io/CoreNLP/download.html). - - Linux and MacOS- Follow the instructions to download the file from [here](https://stanfordnlp.github.io/CoreNLP/download.html). - Docker - Take a look at [this](https://docs.docker.com/install/) for detailed installation instructions for Docker on Windows, Linux and Mac systems. - Verify the installations by `docker --version` and `docker-compose --version` -- You won't need to download MySQL locally to make Docker work, but it's recommended as a pre-requisite to be able to debug programs outside Docker. #### How to set me up Docker style? - Clone the repository -- Unzip the StanfordCoreNLP package in the repository. Make sure the StanfordCoreNLP folder you downloaded in the prerequisite steps are in the cloned repository folder. -- Add config.py file to .gitignore to avoid pushing changes made to config -- Run `git rm --cached config.py` -- Modify *only* the following fields in `config.py` file with the corresponding values: - - key = +- Run `git update-index --assume-unchanged ENV/*` +- Modify *only* the following fields in `ENV/docker.env` with the corresponding values: + - `GCLOUD_API_KEY=` - You're all set up, kick off with `start.sh` file by running `bash start.sh`. ------ diff --git a/config.py b/config.py index 7c0edc3..c4b6629 100644 --- a/config.py +++ b/config.py @@ -1,28 +1,25 @@ import os -import dotenv +from dotenv import load_dotenv -dotenv.load_dotenv() +if os.getenv("DOCKER") == 'Y': + load_dotenv('ENV/docker.env') +else: + load_dotenv('ENV/.env') -user = os.getenv('mapbotuser') -password = os.getenv('mapbotpassword') -host = os.getenv('mapbothost') -database = os.getenv('mapbotdatabase') -port = os.getenv('mapbotport') -key = os.getenv('mapbotkey') +### MAKE SURE you have filled environment variables in `.env` files in `./ENV/` folder -stanford_path_to_jar = os.getenv('stanford_path_to_jar') +user = os.getenv("DB_USER") +password = os.getenv("DB_PASSWORD") +host = os.getenv("DB_HOST") +database = os.getenv("DATABASE") +port = os.getenv("DB_PORT") +key = os.getenv("GCLOUD_API_KEY") # Will be provided by mentors -stanford_path_to_models_jar = os.getenv('stanford_path_to_models_jar') +# your_path_to_stanford-corenlp-x.x.x.jar +stanford_path_to_jar = os.getenv("STANFORD_PATH_TO_JAR") -javahome = os.getenv('javahome') +# your_path_to_stanford-corenlp-x.x.x-models.jar +stanford_path_to_models_jar = os.getenv("STANFORD_PATH_TO_MODELS_JAR") - -# DONOT CHANGE THE VALUES BELOW DURING INITIAL CONFIGURATION SET UP - -docker = os.getenv("DOCKER") -if(docker=="Y"): - # print("Inside Docker") - user = os.getenv('dockeruser') - password = os.getenv('dockerpassword') - host = os.getenv('dockerhost') - javahome = os.getenv('dockerjavahome') +# for eg. 'C:\\Program\ Files\\Java\\jdk1.8.0_201\\bin\\java.exe' or '/usr/local/openjdk-11/bin/java' +javahome = os.getenv("JAVAHOME") diff --git a/docker-compose.yml b/docker-compose.yml index 3425cc0..7b863b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: image: python:3.6 container_name: mapbot_bot environment: - - DOCKER=true + - DOCKER=Y build: context: . dockerfile: Dockerfile @@ -29,7 +29,7 @@ services: - java volumes: - java_storage:/usr/local/openjdk-11/:ro - - .:/usr/var + - .:/usr/var/MapBot stdin_open: true tty: true diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..f1675fc --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,12 @@ +set -ex + +if [ ! -d ./stanford-corenlp-full-2018-10-05 ]; then + wget http://nlp.stanford.edu/software/stanford-corenlp-full-2018-10-05.zip -nc -c +fi + +if [ -f stanford-corenlp-full-2018-10-05.zip ]; then + unzip -n stanford-corenlp-full-2018-10-05.zip + rm stanford-corenlp-full-2018-10-05.zip +fi + +python init.py diff --git a/template.txt b/template.txt deleted file mode 100644 index ed7911c..0000000 --- a/template.txt +++ /dev/null @@ -1,22 +0,0 @@ -mapbotuser = "root" -mapbotpassword = "root" -mapbothost = "localhost" -mapbotdatabase = "mapbot" -mapbotport = "3306" -mapbotkey = "*Google_Cloud_API_key*" # Will be provided by mentors - -# your_path_to_stanford-corenlp-x.x.x.jar -stanford_path_to_jar = "./stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2.jar" - -# your_path_to_stanford-corenlp-x.x.x-models.jar -stanford_path_to_models_jar = "./stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2-models.jar" - -# for eg. 'C:\\Program\ Files\\Java\\jdk1.8.0_201\\bin\\java.exe' or '/usr/local/openjdk-11/bin/java' -javahome = '*your_path_to_jdk_bin_java.exe*' - -#DOCKER variables - DOCKER = "N" - dockeruser = "root" - dockerpassword = "root" - dockerhost = "db" - dockerjavahome = '/usr/local/openjdk-11/bin/java'