diff --git a/.travis.yml b/.travis.yml index 4c1bd2b..a42758e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: - DOCKERFILE_DIR=nginx - DOCKERFILE_DIR=redis - DOCKERFILE_DIR=httpd + - DOCKERFILE_DIR=elasticsearch - DOCKERFILE_DIR=cgit script: diff --git a/README.md b/README.md index 00c58bc..9eeae69 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ https://hub.docker.com/u/clearlinux/ Containers ---------- - clr-sdk +- elasticsearch - httpd - machine-learning - mixer-ci diff --git a/elasticsearch/Dockerfile b/elasticsearch/Dockerfile new file mode 100644 index 0000000..e552f32 --- /dev/null +++ b/elasticsearch/Dockerfile @@ -0,0 +1,27 @@ +FROM clearlinux:latest +MAINTAINER qi.zheng@intel.com + +ARG swupd_args + +RUN swupd update $swupd_args \ + && swupd bundle-add elasticsearch $swupd_args \ + && rm -rf /var/lib/swupd/* + +RUN set -ex \ + && for path in \ + /var/data/elasticsearch \ + /var/log/elasticsearch \ + /etc/elasticsearch \ + ; do \ + mkdir -p "$path"; \ + chown -R elasticsearch:elasticsearch "$path"; \ + done + +COPY config /etc/elasticsearch +COPY docker-entrypoint.sh / + +VOLUME /var/data/elasticsearch + +EXPOSE 9200 9300 +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["-Epath.conf=/etc/elasticsearch/"] diff --git a/elasticsearch/README.md b/elasticsearch/README.md new file mode 100644 index 0000000..1c6bc51 --- /dev/null +++ b/elasticsearch/README.md @@ -0,0 +1,58 @@ +Elasticsearch +========== +This provides a Clear Linux* Elasticsearch instance. + +Build +----- +``` +docker build -t clearlinux/elasticsearch . +``` + +Or just pull it from Dockerhub +--------------------------- +``` +docker pull clearlinux/elasticsearch +``` + +Start a elasticsearch instance +----------------------- +``` +docker run -d -p 9200:9200 -e "discovery.type=single-node" -v esdata:/var/data/elasticsearch clearlinux/elasticsearch +``` + +Set the configuration file to the path /etc/elasticsearch/ by default CMD "-Epath.conf=/etc/elasticsearch/". + +Check cluster health +--------------------- +``` +curl http://localhost:9200/_cluster/health?pretty +``` + +Create an index called customer +--------------------- +``` +curl -X PUT "localhost:9200/customer?pretty" +``` + +Add new document to that index +--------------------- +``` +curl -X PUT "localhost:9200/customer/doc/1?pretty" -H 'Content-Type: application/json' -d'{"name": "Tom John" }' +curl -X PUT "localhost:9200/customer/doc/2?pretty" -H 'Content-Type: application/json' -d'{"name": "Kelly Wong" }' +``` + +View documents in the index +--------------------- +``` +curl localhost:9200/customer/_search?pretty +``` + +Details of how-to +--------------------- +Please refer to [page](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docker.html). + +Extra Build ARGs +---------------- +- ``swupd_args`` Specifies [SWUPD](https://clearlinux.org/documentation/swupdate_how_to_run_the_updater.html) flags + +Default build args in Docker are on: https://docs.docker.com/engine/reference/builder/#arg diff --git a/elasticsearch/config/elasticsearch.yml b/elasticsearch/config/elasticsearch.yml new file mode 100644 index 0000000..b18e340 --- /dev/null +++ b/elasticsearch/config/elasticsearch.yml @@ -0,0 +1,9 @@ +http.host: 0.0.0.0 + +# Uncomment the following lines for a production cluster deployment +#transport.host: 0.0.0.0 +#discovery.zen.minimum_master_nodes: 1 + +path: + data: /var/data/elasticsearch + logs: /var/log/elasticsearch diff --git a/elasticsearch/config/log4j2.properties b/elasticsearch/config/log4j2.properties new file mode 100644 index 0000000..46877d0 --- /dev/null +++ b/elasticsearch/config/log4j2.properties @@ -0,0 +1,9 @@ +status = error + +appender.console.type = Console +appender.console.name = console +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n + +rootLogger.level = info +rootLogger.appenderRef.console.ref = console diff --git a/elasticsearch/docker-entrypoint.sh b/elasticsearch/docker-entrypoint.sh new file mode 100755 index 0000000..eb1a8bf --- /dev/null +++ b/elasticsearch/docker-entrypoint.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +export PATH=/usr/share/elasticsearch/bin/:$PATH + +# Add elasticsearch as command if needed +if [ "${1:0:1}" = '-' ]; then + set -- elasticsearch "$@" +fi + +# Drop root privileges if we are running elasticsearch +# allow the container to be started with `--user` +if [ "$1" = 'elasticsearch' -a "$(id -u)" = '0' ]; then + # Change the ownership of user-mutable directories to elasticsearch + for path in \ + /var/data/elasticsearch \ + /var/log/elasticsearch \ + ; do + chown -R elasticsearch:elasticsearch "$path" + done + + # use tmp file to avoid multiple parameters issue on su -c + echo "elasticsearch -s /bin/bash -c \"$0 $@\"" | xargs su +fi + +# As argument is not related to elasticsearch, +# then assume that user wants to run his own process, +# for example a `bash` shell to explore this image +exec "$@"