Skip to content

Commit 32ab443

Browse files
committed
[HSEARCH] Allow to use docker for the hsearch-elasticsearch-wikipedia demo
1 parent 4b50dce commit 32ab443

File tree

2 files changed

+68
-28
lines changed
  • hibernate-search/hsearch-elasticsearch-wikipedia

2 files changed

+68
-28
lines changed

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

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,30 @@
22

33
## Database
44

5-
Install postgresql and configure it ([see here for Fedora](https://fedoraproject.org/wiki/PostgreSQL)).
5+
Install postgresql and configure it.
66

7-
Create a database and user:
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`.
814

9-
```
10-
# From a shell
11-
sudo -i -u postgres
12-
createuser -U postgres -P hibernate_demo # When prompted, use "hibernate_demo" as a password
13-
createdb -U postgres -O hibernate_demo hsearch_es_wikipedia
14-
```
15-
16-
You need to enable the `md5` authentication scheme for the local network connection.
15+
## Data
1716

18-
So, if you just installed PostgreSQL, you should make your `/var/lib/pgsql/data/pg_hba.conf` file look like:
19-
```
20-
local all all peer
21-
host all all 127.0.0.1/32 md5
22-
host all all ::1/128 md5
23-
```
24-
(just change `ident` to `md5` in the existing lines)
17+
You can try a fully automated initialization using this command:
2518

26-
Don't forget to reload your PostgreSQL server after this change:
2719
```
28-
sudo systemctl reload postgresql
20+
./src/init/init -d postgresql-hibernate_demo
2921
```
3022

31-
## Data
32-
33-
You can try a fully automated initialization using this command:
23+
Or, if not using docker:
3424

3525
```
3626
./src/init/init
3727
```
3828

39-
The script will ask for a password: just use `hibernate_demo`.
40-
4129
If this succeeds, you're all set, you can go to the next step.
4230

4331
Otherwise, Wikipedia's dumps page structure probably changed, but you can proceed as explained below.
@@ -63,9 +51,13 @@ The script will ask for a password: just use `hibernate_demo`.
6351

6452
## Elasticsearch
6553

66-
Ensure you have an Elasticsearch 5 instance running and accessible from <http://localhost:9200/>.
54+
Ensure you have an Elasticsearch 5 instance running and accessible from <http://localhost:9200/>:
6755

68-
You can download Elasticsearch from here: <https://www.elastic.co/downloads/elasticsearch>.
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>.
6961
Unzip the downloaded file, and just run `bin/elasticsearch` to start an instance on <http://localhost:9200>.
7062

7163
# Running the project

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,58 @@ function guess_remote_dump_url() {
1919
|| abort "Could not guess the URL to get the remote dump from."
2020
}
2121

22-
LOCAL_DUMP_FILE=$1
22+
function do_psql() {
23+
if [ -n "$DOCKER_CONTAINER_NAME" ]
24+
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
28+
fi
29+
}
30+
2331

2432
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."
2533

34+
while getopts 'd:' opt
35+
do
36+
case "$opt" in
37+
d)
38+
DOCKER_CONTAINER_NAME="$OPTARG"
39+
log "Will attempt to connect to docker container with name '$DOCKER_CONTAINER_NAME'"
40+
;;
41+
h)
42+
FEATURE=git_history
43+
;;
44+
f)
45+
case "$OPTARG" in
46+
"api"|"spi"|"public"|"impl"|"test"|"main"|"all")
47+
FILTER="$OPTARG"
48+
;;
49+
*)
50+
echo 2>&1 "Unrecognized source filter: $OPTARG"
51+
exit 1
52+
;;
53+
esac
54+
;;
55+
i)
56+
INTERNAL_PACKAGE_MARKER="$OPTARG"
57+
;;
58+
\?)
59+
exit 1
60+
;;
61+
esac
62+
done
63+
64+
shift $(( OPTIND - 1 ))
65+
66+
if [ -z "$DOCKER_CONTAINER_NAME" ]
67+
then
68+
log "No docker container name given (-d option missing). Will attempt to use a local 'psql' command."
69+
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."
70+
fi
71+
72+
LOCAL_DUMP_FILE=$1
73+
2674
if [ -z "$LOCAL_DUMP_FILE" ]
2775
then
2876
log "No argument given; will try to retrieve the dump file automatically."
@@ -48,5 +96,5 @@ fi
4896

4997
DIR=$(readlink -f "$0" | xargs dirname)
5098

51-
xsltproc "$DIR/sql_populate.xslt" $LOCAL_DUMP_FILE | psql -U hibernate_demo -h localhost -W hsearch_es_wikipedia
99+
xsltproc "$DIR/sql_populate.xslt" $LOCAL_DUMP_FILE | do_psql
52100

0 commit comments

Comments
 (0)