Skip to content

Commit

Permalink
Add travis docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Royer committed Sep 24, 2018
1 parent b5ccde2 commit 0796553
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 2 deletions.
16 changes: 14 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
dist: trusty
sudo: false
language: java
sudo: required
language:
- java
- bash

services:
- docker

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down Expand Up @@ -31,6 +36,7 @@ before_deploy:
- export ZIPBALL=$(ls distribution/zip/build/distributions/elassandra-*.zip)
- export DEBPKG=$(ls distribution/deb/build/distributions/elassandra-*.deb)
- export RPMPKG=$(ls distribution/rpm/build/distributions/elassandra-*.rpm)
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

deploy:
- provider: releases
Expand Down Expand Up @@ -62,3 +68,9 @@ deploy:
on:
tags: true
repo: strapdata/elassandra-rc

- provider: script
skip_cleanup: true
script: bash docker/build.sh
on:
tags: true
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tar.gz
85 changes: 85 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# vim:set ft=dockerfile:
FROM debian:jessie-backports

# explicitly set user/group IDs
RUN groupadd -r cassandra --gid=999 && useradd -r -g cassandra --uid=999 cassandra


# grab gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates jq wget curl && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& gosu nobody true \
&& apt-get purge -y --auto-remove ca-certificates

# solves warning: "jemalloc shared library could not be preloaded to speed up memory allocations"
RUN apt-get update && apt-get install -y --no-install-recommends libjna-java libjemalloc1 && rm -rf /var/lib/apt/lists/*

# https://github.com/docker-library/cassandra/pull/98#issuecomment-280761137
RUN { \
echo 'Package: openjdk-* ca-certificates-java'; \
echo 'Pin: release n=*-backports'; \
echo 'Pin-Priority: 990'; \
} > /etc/apt/preferences.d/java-backports

RUN apt-get update && apt-get install -y --no-install-recommends openjdk-8-jre-headless python python-pip && \
rm -rf /var/lib/apt/lists/* && \
pip install cassandra-driver yq

LABEL maintainer="[email protected]"
LABEL description="Elassandra docker image"

ARG elassandra_version
ARG elassandra_url

ENV ELASSANDRA_VERSION=${elassandra_version:-5.5.0.22-rc3}
ENV ELASSANDRA_URL=${elassandra_url:-https://github.com/strapdata/elassandra-rc/releases/download/v${ELASSANDRA_VERSION}/elassandra-${ELASSANDRA_VERSION}.tar.gz}

ENV ELASSANDRA_VERSION ${ELASSANDRA_VERSION}
ENV CASSANDRA_HOME /opt/elassandra-${ELASSANDRA_VERSION}
ENV CASSANDRA_CONF /opt/elassandra-${ELASSANDRA_VERSION}/conf
ENV CASSANDRA_PIDFILE /opt/elassandra-${ELASSANDRA_VERSION}/cassandra.pid
ENV PATH $PATH:/opt/elassandra-${ELASSANDRA_VERSION}/bin

# Copy or download elassandra tarball
RUN /bin/bash -c "if [[ $ELASSANDRA_URL == http* ]]; then wget -q -O /elassandra-$ELASSANDRA_VERSION.tar.gz $ELASSANDRA_URL; fi"
COPY --chown=cassandra:cassandra ready-probe.sh elassandra-${ELASSANDRA_VERSION}.tar.gz* /

RUN cd /opt \
&& tar -xzf "/elassandra-${ELASSANDRA_VERSION}.tar.gz" \
&& rm -v "/elassandra-${ELASSANDRA_VERSION}.tar.gz" \
&& chown -R cassandra:cassandra "$CASSANDRA_HOME" \
&& chmod -R o-rwx "$CASSANDRA_HOME"

# Add custom logback.xml including variables.
COPY --chown=cassandra:cassandra logback.xml "$CASSANDRA_HOME"/conf/

RUN mkdir -p /var/lib/cassandra /var/log/cassandra \
&& rm -r "$CASSANDRA_HOME"/data "$CASSANDRA_HOME"/logs \
&& ln -s /var/lib/cassandra "$CASSANDRA_HOME"/data \
&& ln -s /var/log/cassandra "$CASSANDRA_HOME"/logs \
&& chown -R cassandra:cassandra /var/lib/cassandra /var/log/cassandra "$CASSANDRA_HOME"/data "$CASSANDRA_HOME"/logs \
&& chmod 750 /var/lib/cassandra /var/log/cassandra \
&& chmod a+rx /ready-probe.sh

COPY docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

VOLUME /var/lib/cassandra

# 7000: intra-node communication
# 7001: TLS intra-node communication
# 7199: JMX
# 9042: CQL
# 9160: thrift service
# 9200: elassandra HTTP
# 9300: elasticsearch transport
EXPOSE 7000 7001 7199 9042 9160 9200 9300
CMD ["bin/cassandra"]
61 changes: 61 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## Elassandra docker image

[Elassandra](https://github.com/strapdata/elassandra) is a fork of [Elasticsearch](https://github.com/elastic/elasticsearch) modified to run on top of [Apache Cassandra](http://cassandra.apache.org/) in a scalable and resilient peer-to-peer architecture. Elasticsearch code is embedded in Cassanda nodes providing advanced search features on Cassandra tables and Cassandra serve as an Elasticsearch data and configuration store.

Check-out the [elassandra documentation](http://doc.elassandra.io/en/latest) for detailed instructions.

Commercial support is available from [Strapdata](https://www.strapdata.com).

## Usage

This Elassandra image is available on [docker hub](https://hub.docker.com/r/strapdata/elassandra/)

```bash
docker pull strapdata/elassandra
```

#### Start a single-node cluster

```bash
docker run --name el strapdata/elassandra
```

#### Connect with cqlsh

```bash
docker run -it --link el --rm strapdata/elassandra cqlsh some-elassandra
```

#### Connect to Elasticsearch API with curl

```bash
docker run -it --link el --rm strapdata/elassandra curl some-elassandra:9200
```

#### Exposed ports

* 7000: Intra-node communication
* 7001: TLS intra-node communication
* 7199: JMX
* 9042: CQL
* 9160: thrift service
* 9200: ElasticSearch HTTP
* 9300: ElasticSearch transport

#### Volumes

* /var/lib/cassandra

## More information

This docker image is based on [strapdata/elassandra](https://hub.docker.com/r/strapdata/elassandra/) inspired from [docker-library/cassandra](https://github.com/docker-library/cassandra). For more complicated setups, please refer to the [documentation](https://github.com/docker-library/docs/tree/master/cassandra).


* A **logback.xml** with environment variables allows to manage debug levels from your docker env section.
* For kubernetes usage, a **ready_probe.sh** script can be use for readiness probe as follow:

readinessProbe:
exec:
command: [ "/bin/bash", "-c", "/ready-probe.sh" ]
initialDelaySeconds: 15
timeoutSeconds: 5
59 changes: 59 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -ex

# work in the project dir.
cd $(dirname "$0")/..

# If set, the images will be published to docker hub
DOCKER_PUBLISH=${DOCKER_PUBLISH:-true}

# Unless specified with a trailing slash, publish in the public strapdata docker hub
DOCKER_REGISTRY=${DOCKER_REGISTRY:-""}

# If set, the images will be tagged latest
LATEST=${LATEST:-false}

REPO=${TRAVIS_REPO_SLUG:="strapdata/elassandra"}

# Options to add to docker build command
DOCKER_BUILD_OPTS=${DOCKER_BUILD_OPTS:-"--rm"}

# the target names of the images
DOCKER_IMAGE=${DOCKER_REGISTRY}${REPO}

cp ${TRAVIS_BUILD_DIR:-"."}/distribution/tar/build/distributions/elassandra-*.tar.gz docker/
elassandra_tarball=$(ls docker/elassandra-*.tar.gz)
elassandra_version=$(echo $elassandra_tarball | sed 's/.*elassandra\-\(.*\).tar.gz/\1/')

echo "Building docker image for elassandra_tarball=$elassandra_tarball"
docker build --build-arg elassandra_version=$elassandra_version \
--build-arg elassandra_url=elassandra-${elassandra_version}.tar.gz \
$DOCKER_BUILD_OPTS -f docker/Dockerfile -t "$DOCKER_IMAGE:$elassandra_version" docker

# push to docker hub if DOCKER_PUBLISH variable is true (replace remote_repository if you want to use this feature)
if [ "$DOCKER_PUBLISH" = "true" ]; then
docker push $DOCKER_IMAGE:$elassandra_version

if [ "$LATEST" = "true" ] || [ "$TRAVIS_BRANCH" = "master" ]; then
echo "Publishing the latest = $elassandra_version"
docker tag $DOCKER_IMAGE:$elassandra_version $DOCKER_IMAGE:latest
docker push $DOCKER_IMAGE:latest
fi
fi

116 changes: 116 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/bin/bash

# Set memlock limit to unlimited (before set -e)
ulimit -l unlimited

set -e

# first arg is `-f` or `--some-option`
if [ "${1:0:1}" = '-' ]; then
set -- bin/cassandra
fi

# allow the container to be started with `--user`
if [ "$1" = 'bin/cassandra' -a "$(id -u)" = '0' ]; then
chown -R cassandra /var/lib/cassandra /var/log/cassandra "$CASSANDRA_CONF"
exec gosu cassandra "$BASH_SOURCE" "$@"
fi

if [ "$1" = 'bin/cassandra' ]; then

cd $CASSANDRA_HOME
ARGS="-f -p $CASSANDRA_PIDFILE"

: ${CASSANDRA_DAEMON:='org.apache.cassandra.service.ElassandraDaemon'}
export CASSANDRA_DAEMON

: ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}

: ${CASSANDRA_LISTEN_ADDRESS='auto'}
if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
fi

: ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}

if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
fi
: ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}

if [ -n "${CASSANDRA_NAME:+1}" ]; then
: ${CASSANDRA_SEEDS:="cassandra"}
fi
: ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}

sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONF/cassandra.yaml"

for yaml in \
broadcast_address \
broadcast_rpc_address \
cluster_name \
endpoint_snitch \
listen_address \
num_tokens \
rpc_address \
start_rpc \
; do
var="CASSANDRA_${yaml^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONF/cassandra.yaml"
fi
done

for rackdc in dc rack; do
var="CASSANDRA_${rackdc^^}"
val="${!var}"
if [ "$val" ]; then
sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONF/cassandra-rackdc.properties"
fi
done

# Additional cassandra.yaml variable substitution for env var CASSANDRA__*, substitute __ by .
set -x
for v in ${!CASSANDRA__*}; do
val="${!v}"
if [ "$val" ]; then
var=$(echo ${v:9}|sed 's/__/\./g')
case ${val} in
true) filter=$(echo "${var}=true");;
false) filter=$(echo "${var}=false");;
*) filter=$(echo "${var}=\"${val}\"");;
esac
yq --yaml-output ${filter} $CASSANDRA_CONF/cassandra.yaml > $CASSANDRA_CONF/cassandra2.yaml
mv $CASSANDRA_CONF/cassandra2.yaml $CASSANDRA_CONF/cassandra.yaml
fi
done

# Additional elasticsearch.yml variable substitution for env var ELASTICSEARCH__*, substitute __ by .
for v in ${!ELASTICSEARCH__*}; do
val="${!v}"
if [ "$val" ]; then
var=$(echo ${v:13}|sed 's/__/\./g')
case ${val} in
true) filter=$(echo "${var}=true");;
false) filter=$(echo "${var}=false");;
*) filter=$(echo "${var}=\"${val}\"");;
esac
yq --yaml-output ${filter} $CASSANDRA_CONF/elasticsearch.yml > $CASSANDRA_CONF/elasticsearch2.yaml
mv $CASSANDRA_CONF/elasticsearch2.yaml $CASSANDRA_CONF/elasticsearch.yaml
fi
done

# init script and cql
for f in docker-entrypoint-init.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.cql) echo "$0: running $f" && until cqlsh -f "$f"; do >&2 echo "Cassandra is unavailable - sleeping"; sleep 2; done & ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done

fi

exec $@ $ARGS
Loading

0 comments on commit 0796553

Please sign in to comment.