Skip to content

Commit 2301fd5

Browse files
committed
[HSEARCH] hsearch-elasticsearch-wikipedia: use docker-compose to set up the environment
1 parent 7e69352 commit 2301fd5

File tree

3 files changed

+85
-44
lines changed

3 files changed

+85
-44
lines changed

hibernate-search/hsearch-elasticsearch-wikipedia/README.md

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
# Setting up the environment
22

3-
## Database
3+
## Services
44

5-
Install postgresql and configure it.
5+
Install docker and docker-compose, then run this from the root of the project:
66

7-
* One-liner with docker:
8-
```
9-
sudo docker run --name postgresql-hibernate_demo -e POSTGRES_PASSWORD=hibernate_demo -e POSTGRES_USER=hibernate_demo -e POSTGRES_DB=hsearch_es_wikipedia -p 5432:5432 -d postgres:11.1
10-
```
11-
* Otherwise, for Fedora, [see here](https://fedoraproject.org/wiki/PostgreSQL)).
12-
You will need to enable the `md5` authentication scheme for the local network connection,
13-
and to create a `hibernate_demo` user with the password `hibernate_demo`.
14-
15-
## Data
7+
```
8+
sudo docker-compose -f environment-stack.yml -p hsearch-elasticsearch-wikipedia up
9+
```
1610

17-
You can try a fully automated initialization using this command:
11+
You can later remove the created services and volumes with this command:
1812

1913
```
20-
./src/init/init -d postgresql-hibernate_demo
14+
sudo docker-compose -f environment-stack.yml -p hsearch-elasticsearch-wikipedia down -v
2115
```
2216

23-
Or, if not using docker:
17+
## Data
18+
19+
You can try a fully automated initialization using this command:
2420

2521
```
2622
./src/init/init
@@ -44,22 +40,9 @@ bunzip2 <the dump>
4440
Initialize the database using the provided script:
4541

4642
```
47-
./src/init/init <the uncompressed dump>
43+
./src/init/init -f <path to the uncompressed dump>
4844
```
4945

50-
The script will ask for a password: just use `hibernate_demo`.
51-
52-
## Elasticsearch
53-
54-
Ensure you have an Elasticsearch 5 instance running and accessible from <http://localhost:9200/>:
55-
56-
* One-liner using temporary storage with docker (ES6, but it should work for this demo):
57-
```
58-
sudo docker run --ulimit memlock=-1:-1 -ti --tmpfs /run --tmpfs=/opt/elasticsearch/volatile/data:uid=1000 --tmpfs=/opt/elasticsearch/volatile/logs:uid=1000 -p 9200:9200 -p 9300:9300 --name es-it sanne/elasticsearch-light-testing
59-
```
60-
* Otherwise, you can download Elasticsearch from here: <https://www.elastic.co/downloads/elasticsearch>.
61-
Unzip the downloaded file, and just run `bin/elasticsearch` to start an instance on <http://localhost:9200>.
62-
6346
# Running the project
6447

6548
You must have [Maven (`mvn`)](https://maven.apache.org/) in your path, version 3.2 or later.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version: '3.1'
2+
services:
3+
db:
4+
image: postgres:11.1
5+
environment:
6+
- POSTGRES_USER=hibernate_demo
7+
- POSTGRES_PASSWORD=hibernate_demo
8+
- POSTGRES_DB=hsearch_es_wikipedia
9+
volumes:
10+
- postgresdata1:/var/lib/postgresql/data
11+
ports:
12+
- 5432:5432
13+
networks:
14+
- postgresnet
15+
elasticsearch1:
16+
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
17+
environment:
18+
- cluster.name=docker-cluster
19+
- bootstrap.memory_lock=true
20+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
21+
ulimits:
22+
memlock:
23+
soft: -1
24+
hard: -1
25+
volumes:
26+
- esdata1:/usr/share/elasticsearch/data
27+
ports:
28+
- 9200:9200
29+
networks:
30+
- esnet
31+
elasticsearch2:
32+
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
33+
environment:
34+
- cluster.name=docker-cluster
35+
- bootstrap.memory_lock=true
36+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
37+
- "discovery.zen.ping.unicast.hosts=elasticsearch1"
38+
ulimits:
39+
memlock:
40+
soft: -1
41+
hard: -1
42+
volumes:
43+
- esdata2:/usr/share/elasticsearch/data
44+
networks:
45+
- esnet
46+
47+
volumes:
48+
postgresdata1:
49+
driver: local
50+
esdata1:
51+
driver: local
52+
esdata2:
53+
driver: local
54+
55+
networks:
56+
esnet:
57+
postgresnet:

hibernate-search/hsearch-elasticsearch-wikipedia/src/init/init

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,44 @@ function guess_remote_dump_url() {
2020
}
2121

2222
function do_psql() {
23-
if [ -n "$DOCKER_CONTAINER_NAME" ]
23+
local options="--link "$DOCKER_CONTAINER_NAME":postgres -e PGPASSWORD=hibernate_demo"
24+
if [ -n "$DOCKER_NETWORK_NAME" ]
2425
then
25-
sudo -p "Sudo password (to execute docker): " docker run -i --rm --link "$DOCKER_CONTAINER_NAME":postgres -e PGPASSWORD=hibernate_demo postgres:11.1 psql -h postgres -U hibernate_demo hsearch_es_wikipedia
26-
else
27-
PGPASSWORD=hibernate_demo psql -U hibernate_demo -h localhost -W hsearch_es_wikipedia
26+
options+=" --net $DOCKER_NETWORK_NAME"
2827
fi
28+
sudo -p "Sudo password (to execute docker): " docker run -i --rm $options postgres:11.1 psql -h postgres -U hibernate_demo hsearch_es_wikipedia
2929
}
3030

3131

3232
which xsltproc 1>/dev/null 2>&1 || abort "Command 'xsltproc' isn't in the \$PATH; please install the command or add it to the \$PATH."
3333

34-
while getopts 'd:' opt
34+
DOCKER_CONTAINER_NAME="hsearch-elasticsearch-wikipedia_db_1"
35+
DOCKER_NETWORK_NAME="hsearch-elasticsearch-wikipedia_postgresnet"
36+
LOCAL_DUMP_FILE=
37+
while getopts 'c:n:f:' opt
3538
do
3639
case "$opt" in
37-
d)
40+
c)
3841
DOCKER_CONTAINER_NAME="$OPTARG"
39-
log "Will attempt to connect to docker container with name '$DOCKER_CONTAINER_NAME'"
4042
;;
43+
n)
44+
DOCKER_NETWORK_NAME="$OPTARG"
45+
;;
46+
f)
47+
LOCAL_DUMP_FILE="$OPTARG"
48+
;;
4149
\?)
4250
exit 1
4351
;;
4452
esac
4553
done
46-
4754
shift $(( OPTIND - 1 ))
4855

49-
if [ -z "$DOCKER_CONTAINER_NAME" ]
50-
then
51-
log "No docker container name given (-d option missing). Will attempt to use a local 'psql' command."
52-
which "psql" 1>/dev/null 2>&1 || abort "Command 'psql' isn't in the \$PATH; please install the command or add it to the \$PATH."
53-
fi
54-
55-
LOCAL_DUMP_FILE=$1
56+
log "Will attempt to connect to docker container with name '$DOCKER_CONTAINER_NAME' within network '$DOCKER_NETWORK_NAME'"
5657

5758
if [ -z "$LOCAL_DUMP_FILE" ]
5859
then
59-
log "No argument given; will try to retrieve the dump file automatically."
60+
log "No dump file path given; will try to retrieve the dump file automatically."
6061
LOCAL_DUMP_DIR="/tmp/hsearch_es_wikipedia"
6162
LOCAL_DUMP_FILE="$LOCAL_DUMP_DIR/enwiki-latest-pages-meta-current1.xml"
6263

0 commit comments

Comments
 (0)