Skip to content

Commit

Permalink
#8: MongoDB initialization also works
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Apr 16, 2018
1 parent 5bf528b commit 8e32f47
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ RUN git clone -b 1.1 --single-branch --depth=1 https://github.com/huridocs/uwazi
&& yarn production-build

COPY --chown=node:node ./scripts/patch/uwazi/database/reindex_elastic.js /home/node/uwazi/database/reindex_elastic.js
RUN cat /home/node/uwazi/database/reindex_elastic.js

## TODO: move to the start of the Dockerfile (fititnt, 2018-04-16 00:27 BRT)
# Install mongo & mongorestore (this is used only for database initialization, not on runtime)
# So much space need, see 'After this operation, 184 MB of additional disk space will be used.'
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 \
&& echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.6 main" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list \
&& apt-get update \
&& apt-get install -y mongodb-org-shell mongodb-org-tools

WORKDIR /home/node/uwazi/
COPY --chown=node:node docker-entrypoint.sh /docker-entrypoint.sh
Expand Down
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,12 @@ See also [History of Uwazi](https://github.com/huridocs/uwazi/wiki/History-of-Uw
The [uwazi-docker](https://github.com/fititnt/uwazi-docker) requires
[docker-compose](https://docs.docker.com/compose/install/) installed.

> At this moment, the Dockerfile of the uwazi is not ready, only it's external
> dependencies (Elastic Search and MongoDB), so you will also need install
[NVM](https://github.com/creationix/nvm) and [Yarn](https://yarnpkg.com/).

Run these commands on your terminal:

```bash
git clone [email protected]:fititnt/uwazi-docker.git
cd uwazi-docker
docker-compose up -d elasticsearch mongo
git clone [email protected]:huridocs/uwazi.git
cd uwazi
git checkout 1.1
nvm install 6.13
npm install
yarn production-build
yarn blank-state
yarn reindex
yarn run-production
docker-compose run -e IS_FIRST_RUN=true uwazi
```

Open your browser at <http://localhost:3000/>. User: _admin_, password: _admin_.
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ services:
working_dir: /home/node/uwazi
ports:
- 3000:3000
#networks:
# - exposed
environment:
- DBHOST=mongo
- DATABASE_NAME=uwazi_development
- ELASTICSEARCH_URL=http://elasticsearch:9200
- IS_FIRST_RUN=false
- IS_FIRST_RUN=${IS_FIRST_RUN:-false}
depends_on:
- elasticsearch
- mongo
Expand Down
18 changes: 16 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/bin/sh

echo "IS_FIRST_RUN: $IS_FIRST_RUN"
DB_INITIALIZATION_PATH=/home/node/uwazi/blank_state/uwazi_development

if [ "$IS_FIRST_RUN" = "true" ] ; then
echo "Enviroment variable IS_FIRST_RUN is true. Assuming need to install database from blank state"
# echo "Sorry, this version of uwazi-docker is not ready to initialize using docker. You need to setup first time from your host before use this container"
echo "Sorry, this version of uwazi-docker is not fully ready to initialize using docker. You need to setup the MongoDB outside this container with yarn blank-state"
# echo "Sorry, this version of uwazi-docker is not fully ready to initialize using docker. You need to setup the MongoDB outside this container with yarn blank-state"

# mongo --version
# mongorestore --version
# yarn blank-state

echo "\n\nDeleting ${DBHOST:-mongo} ${DATABASE_NAME:-uwazi_development} MongoDB database"

mongo -host ${DBHOST:-mongo} ${DATABASE_NAME:-uwazi_development} --eval "db.dropDatabase()"

echo "\n\nImporting $DB_INITIALIZATION_PATH to ${DBHOST:-mongo} ${DATABASE_NAME:-uwazi_development} MongoDB database"

mongorestore -h ${DBHOST:-mongo} $DB_INITIALIZATION_PATH --db=${DATABASE_NAME:-uwazi_development}

echo "Applyng yarn reindex. This will use data from MongoDB to feed Elastic Search"
yarn reindex
else
echo "Data detected. No need to install. Running container."
echo "Enviroment variable IS_FIRST_RUN is not true. Assume MongoDB and Elastic Search provide already are intialized"
echo "If this is the first time and you want this container also initialize MongoDB and Elastic Search, run only ONE, and just ONE time, with variable IS_FIRST_RUN=true"
fi

yarn run-production

0 comments on commit 8e32f47

Please sign in to comment.