Skip to content

Commit

Permalink
#45: dependencies (Mongo and ElasticSearch) with minor edits to work …
Browse files Browse the repository at this point in the history
…with lastest; main Dockerfile still need more work to initialize the database
  • Loading branch information
fititnt committed Jul 10, 2023
1 parent 47b28b8 commit 6467dd9
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 62 deletions.
32 changes: 11 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,23 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
dh-autoreconf \
git \
libpng-dev \
libcurl3 \
openssl \
gnupg \
poppler-utils

RUN curl -fsSL https://pgp.mongodb.com/server-4.2.asc | \
gpg -o /usr/share/keyrings/mongodb-server-4.2.gpg \
--dearmor

RUN echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-4.2.gpg ] http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.2 main" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list
RUN apt-get update
# RUN apt-get install -y mongodb-org-shell mongodb-org-tools
RUN apt-get install -y mongodb-org-tools
RUN apt-get clean && rm -rf /var/lib/apt/lists/*


# 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 20691EEC35216C63CAF66CE1656408E390CFB1F5 \
# && echo "deb http://repo.mongodb.org/apt/debian bullseye/mongodb-org/4.2 main" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list \
# RUN echo "deb http://repo.mongodb.org/apt/debian bullseye/mongodb-org/4.2 main" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list \
# && apt-get update \
# && apt-get install -y mongodb-org-shell mongodb-org-tools \
# && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
--dearmor

RUN echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" \
| tee /etc/apt/sources.list.d/mongodb-org-6.0.list \
&& apt-get update \
&& apt-get install -y mongodb-mongosh mongodb-org-tools \
&& apt-get clean && \
rm -rf /var/lib/apt/lists/*

# ## Download Uwazi v1.4
# RUN git clone -b v1.4 --single-branch --depth=1 https://github.com/huridocs/uwazi.git /home/node/uwazi/ \
## Download Uwazi v1.4
RUN git clone -b production --single-branch --depth=1 https://github.com/huridocs/uwazi.git /home/node/uwazi/ \
&& chown node:node -R /home/node/uwazi/ \
&& cd /home/node/uwazi/ \
Expand Down
46 changes: 27 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ for building and sharing document collections.
See also [History of Uwazi](https://github.com/huridocs/uwazi/wiki/History-of-Uwazi).

## Usage
The uwazi-docker requires docker-compose installed. See
The uwazi-docker requires docker compose installed. See
[requirements](requirements.md). If you are a developer, can also check some
advanced information on [development-instructions.md](development-instructions.md)
and a draft of [production-instructions.md](production-instructions.md).
Expand All @@ -31,15 +31,15 @@ Run these commands on your terminal **only** the first time:
```bash
git clone https://github.com/fititnt/uwazi-docker.git
cd uwazi-docker
docker-compose run -e IS_FIRST_RUN=true --rm uwazi # Install/Re-install from empty data
docker compose run -e IS_FIRST_RUN=true --rm uwazi # Install/Re-install from empty data

```
<!-- docker-compose run --rm uwazi-installer -->
<!-- docker compose run --rm uwazi-installer -->

### Run

```bash
docker-compose up -d uwazi # Run uwazi on background (automatic restart on reboot unless stopped)
docker compose up -d uwazi # Run uwazi on background (automatic restart on reboot unless stopped)
```

Open your browser at <http://localhost:3000/>. Initial user: _admin_, password: _admin_.
Expand All @@ -48,13 +48,13 @@ Open your browser at <http://localhost:3000/>. Initial user: _admin_, password:

```bash
# Stop all containers from this uwazi-docker and do not restart again until you explicit ask for it
docker-compose stop
docker compose stop

# Using "-d" param to run uwazi and its dependencies on background
docker-compose up -d uwazi
docker compose up -d uwazi

# No "-d" param, start uwazi, MongoDB & Elastic Search and see what is happening inside the containers
docker-compose up uwazi
docker compose up uwazi

# See what containers are running now
docker ps
Expand All @@ -66,26 +66,26 @@ docker volume ls
docker volume ls | grep 'mongodb_data1\|uploaded_documents'

# Want some GUI to see what is happening on MongoDB? Use nosqlclient
docker-compose up -d mongo-gui-mongoclient
docker compose up -d mongo-gui-mongoclient

# Want some GUI to see what is happening on Elastic Search? Try Dejavu
docker-compose up -d elasticsearch-gui-dejavu
docker compose up -d elasticsearch-gui-dejavu
```

### Extra features

#### Want some GUI to see what is happening on MongoDB? Use nosqlclient

```bash
docker-compose up -d mongo-gui-mongoclient
docker compose up -d mongo-gui-mongoclient
```

By default, uses <http://localhost:51000/>.

#### Want some GUI to see what is happening on Elastic Search? Try Dejavu

```bash
docker-compose up -d elasticsearch-gui-dejavu
docker compose up -d elasticsearch-gui-dejavu
```

By default, uses <http://localhost:52000/>.
Expand All @@ -110,14 +110,14 @@ instead of Public Domain unlicense.
# Tests on Ubuntu 20.04 LTS
fititnt@bravo:/workspace/git/fititnt/uwazi-docker$ docker compose --file /workspace/git/fititnt/uwazi-docker/docker-compose.yml run -e IS_FIRST_RUN=true --rm uwazi
stat /workspace/git/fititnt/uwazi-docker/docker-compose.yml: no such file or directory
fititnt@bravo:/workspace/git/fititnt/uwazi-docker$ docker compose --file docker-compose.yml run -e IS_FIRST_RUN=true --rm uwazi
stat /var/lib/snapd/void/docker-compose.yml: no such file or directory
fititnt@bravo:/workspace/git/fititnt/uwazi-docker$ docker compose --file /workspace/git/fititnt/uwazi-docker/docker compose.yml run -e IS_FIRST_RUN=true --rm uwazi
stat /workspace/git/fititnt/uwazi-docker/docker compose.yml: no such file or directory
fititnt@bravo:/workspace/git/fititnt/uwazi-docker$ docker compose --file docker compose.yml run -e IS_FIRST_RUN=true --rm uwazi
stat /var/lib/snapd/void/docker compose.yml: no such file or directory
fititnt@bravo:~/Downloads/uwazi-docker$ sudo su
[sudo] password for fititnt:
root@bravo:/home/fititnt/Downloads/uwazi-docker# docker compose --file docker-compose.yml run -e IS_FIRST_RUN=true --rm uwazi
root@bravo:/home/fititnt/Downloads/uwazi-docker# docker compose --file docker compose.yml run -e IS_FIRST_RUN=true --rm uwazi
Logs
(...)
Expand All @@ -142,10 +142,18 @@ instead of Public Domain unlicense.
# Refrech
docker compose --file docker-compose.yml run -e IS_FIRST_RUN=true --rm uwazi
docker compose --file docker compose.yml run -e IS_FIRST_RUN=true --rm uwazi
# (...)
docker stop $(docker ps -a -q)
docker system prune --all
# debug containers
docker ps
docker logs --tail 50 --follow --timestamps uwazi-docker-mongo-1
docker logs --tail 50 --follow --timestamps uwazi-docker-elasticsearch-1
# ...
docker system prune --all
###
git clone -b production --single-branch --depth=1 https://github.com/huridocs/uwazi.git huridocs-uwazi-docker/
-->
16 changes: 8 additions & 8 deletions development-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ tabs.

```bash
# To run and see messages
docker-compose up elasticsearch mongo
docker compose up elasticsearch mongo

# To run on background use -d param
docker-compose up -d elasticsearch mongo
docker compose up -d elasticsearch mongo

# Stop all containers from uwazi-docker after they where not more need and
# avoid they stay running even after you reboot your operational system
docker-compose down
docker compose down
```

The following step is optional if you want to populate the databases not using
uwazi-docker.

```bash
docker-compose run -e IS_FIRST_RUN=true --rm uwazi
docker compose run -e IS_FIRST_RUN=true --rm uwazi
```

## Create your own repository
Expand Down Expand Up @@ -143,17 +143,17 @@ local development machine. **9300/tcp** means the same container have the port
```bash

# See log messages of Mongo and Elastic Search
docker-compose logs -f mongo elasticsearch
docker compose logs -f mongo elasticsearch

# Want some GUI to see what is happening on MongoDB? Use nosqlclient
docker-compose up -d mongo-gui-mongoclient
docker compose up -d mongo-gui-mongoclient

# Want some GUI to see what is happening on Elastic Search? Try Dejavu
docker-compose up -d elasticsearch-gui-dejavu
docker compose up -d elasticsearch-gui-dejavu
```
### Configure ports of Mongo and Elastic Search

At this point, you have to edit the file [docker-compose.yml](docker-compose.yml)
At this point, you have to edit the file [docker compose.yml](docker compose.yml)
and edit the hardcored values.

Protip: the most common error of using uwazi-docker with Uwazi a port is already
Expand Down
10 changes: 7 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- UPLOADS_FOLDER=/data/uploaded_documents
# - LOGS_DIR=/path/to/log
- IS_FIRST_RUN=${IS_FIRST_RUN:-false}
- UWAZI_RELEASE_TAG=${UWAZI_RELEASE_TAG:-production}
volumes:
- uploaded_documents:/data/uploaded_documents
depends_on:
Expand All @@ -28,7 +29,7 @@ services:
environment:
- cluster.name=docker-cluster
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- xpack.security.enabled=false
# - xpack.security.enabled=false
ulimits:
memlock:
soft: -1
Expand All @@ -55,12 +56,15 @@ services:
mongo:
# image: mongo:3.4
# Based on https://github.com/huridocs/uwazi/releases/tag/1.123.2 . Please update this part in future
image: mongo:4.2
# image: mongo:4.2
# Using mongo 6.0 (not 4.2 as suggested by Uwazi 1.123.2) because mongo-shell on 4.2 don't run on Debian bullseye
image: mongo:6.0
restart: unless-stopped
volumes:
# - ./data/mongo:/data/db
- mongodb_data1:/data/db
command: mongod --smallfiles
command: mongod
# command: mongod --smallfiles
# Don't publish unprotected mongod
# ports:
# - 27017:27017
Expand Down
20 changes: 14 additions & 6 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#!/bin/sh
#!/bin/bash

echo "uwazi-docker: IS_FIRST_RUN: $IS_FIRST_RUN"
DB_INITIALIZATION_PATH=/home/node/uwazi/blank_state/uwazi_development
# DB_INITIALIZATION_PATH=/home/node/uwazi/blank_state/uwazi_development
# DB_INITIALIZATION_PATH=/home/node/uwazi/dump/uwazi_development
DB_INITIALIZATION_PATH=/home/node/uwazi/database/blank_state/uwazi_development

set -x
ls -lha /home/node/uwazi/
# ls -lha /home/node/uwazi/dump


if [ "$IS_FIRST_RUN" = "true" ] ; then
echo "uwazi-docker: Enviroment variable IS_FIRST_RUN is true. Assuming need to install database from blank state"

echo "\n\nuwazi-docker: Deleting ${DBHOST:-mongo} ${DATABASE_NAME:-uwazi_development} MongoDB database"
mongo -host ${DBHOST:-mongo} ${DATABASE_NAME:-uwazi_development} --eval "db.dropDatabase()"
echo "uwazi-docker: Deleting ${DBHOST:-mongo} ${DATABASE_NAME:-uwazi_development} MongoDB database"
# mongo -host ${DBHOST:-mongo} ${DATABASE_NAME:-uwazi_development} --eval "db.dropDatabase()"
mongosh -host "${DBHOST:-mongo}" "${DATABASE_NAME:-uwazi_development}" --eval "db.dropDatabase()"

echo "\n\nuwazi-docker: Importing $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 "uwazi-docker: Importing $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 "uwazi-docker: Applyng yarn reindex. This will use data from MongoDB to feed Elastic Search"
yarn reindex
Expand Down
2 changes: 1 addition & 1 deletion requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ TODO: write about (fititnt, 2018-04-18 04:47 BRT)

### Docker
[See updated instructions about how to install Docker Engine on Windows, Mac and Linux](https://docs.docker.com/compose/install/).
Docker docker-compose is already installed.
Docker docker compose is already installed.
8 changes: 4 additions & 4 deletions uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ These commands explain how to uninstall uwazi-docker.

## Uninstall

Use [docker-compose down](https://docs.docker.com/compose/reference/down/) to
Use [docker compose down](https://docs.docker.com/compose/reference/down/) to
remove the containers and networks created by uwazi-docker. This will not
delete the data created.

`docker-compose down # clean only containers and networks`
`docker compose down # clean only containers and networks`

## Complete Uninstall

Expand All @@ -20,6 +20,6 @@ more the uwazi-docker or want a really full reinstall (e.g. is debugging).

```bash

# Remove containers, networks and volumes created by uwazi-docker docker-compose up
docker-compose down -v --rmi all --remove-orphans # WARNING: Purge everything, even data
# Remove containers, networks and volumes created by uwazi-docker docker compose up
docker compose down -v --rmi all --remove-orphans # WARNING: Purge everything, even data
```

0 comments on commit 6467dd9

Please sign in to comment.