Create cassandra microservice

Signed-off-by: wangjue <wang.jue@intel.com>
This commit is contained in:
wangjue
2019-06-21 01:41:08 +08:00
committed by Liu, Jianjun
parent 814cba04ff
commit 508bda672e
3 changed files with 185 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
FROM clearlinux:latest AS builder
# Move to latest Clear Linux release to ensure
# that the swupd command line arguments are
# correct
RUN swupd update --no-boot-update $swupd_args
# Grab os-release info from the minimal base image so
# that the new content matches the exact OS version
COPY --from=clearlinux/os-core:latest /usr/lib/os-release /
# Install additional content in a target directory
# using the os version from the minimal base
RUN source /os-release && \
mkdir /install_root \
&& swupd os-install -V ${VERSION_ID} \
--path /install_root --statedir /swupd-state \
--bundles=cassandra,python2-basic,which --no-scripts \
&& rm -rf /install_root/var/lib/swupd/*
# For some Host OS configuration with redirect_dir on,
# extra data are saved on the upper layer when the same
# file exists on different layers. To minimize docker
# image size, remove the overlapped files before copy.
RUN mkdir /os_core_install
COPY --from=clearlinux/os-core:latest / /os_core_install/
RUN cd / && \
find os_core_install | sed -e 's/os_core_install/install_root/' | xargs rm -d || true
FROM clearlinux/os-core:latest
MAINTAINER wang.jue@intel.com
COPY --from=builder /install_root /
ENV CASSANDRA_CONFIG /usr/share/cassandra/conf
ENV PATH /usr/share/cassandra/bin:$PATH
RUN mkdir -p /var/lib/cassandra/{cdc_raw,commitlog,data,hints,saved_caches} \
&& chown -R cassandra:cassandra /var/lib/cassandra "$CASSANDRA_CONFIG" \
&& chmod -R 777 /var/lib/cassandra "$CASSANDRA_CONFIG"
VOLUME /var/lib/cassandra
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
# 7000: intra-node communication
# 7001: TLS intra-node communication
# 7199: JMX
# 9042: CQL
# 9160: thrift service
EXPOSE 7000 7001 7199 9042 9160
CMD ["cassandra", "-f"]
+43
View File
@@ -0,0 +1,43 @@
Cassandra
==========
This provides a Clear Linux* Cassandra instance.
Build
-----
```
docker build -t clearlinux/cassandra .
```
Or just pull it from Dockerhub
---------------------------
```
docker pull clearlinux/cassandra
```
start a cassandra instance
-----------------------
```
docker run --name some-cassandra --network some-network -d clearlinux/cassandra:tag
```
connect to cassandra from cqlsh
---------------------
```
docker run -it --network some-network --rm clearlinux/cassandra cqlsh -h some-cassandra
```
benchmark test
---------------------
```
TBD
```
details of how-to
---------------------
Please refer to the official cassandra image [page](https://hub.docker.com/_/cassandra).
Extra Build ARGs
----------------
- ``swupd_args`` Specifies [SWUPD](https://github.com/clearlinux/swupd-client/blob/master/docs/swupd.1.rst#options) flags
Default build args in Docker are on: https://docs.docker.com/engine/reference/builder/#arg
+88
View File
@@ -0,0 +1,88 @@
#!/bin/bash
set -e
# first arg is `-f` or `--some-option`
# or there are no args
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
set -- cassandra -f "$@"
fi
# allow the container to be started with `--user`
if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
exec su cassandra -s /bin/bash -c "$BASH_SOURCE" "$@"
fi
_ip_address() {
# scrape the first non-localhost IP address of the container
# in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first
ip address | awk '
$1 == "inet" && $NF != "lo" {
gsub(/\/.+$/, "", $2)
print $2
exit
}
'
}
# "sed -i", but without "mv" (which doesn't work on a bind-mounted file, for example)
_sed-in-place() {
local filename="$1"; shift
local tempFile
tempFile="$(mktemp)"
sed "$@" "$filename" > "$tempFile"
cat "$tempFile" > "$filename"
rm "$tempFile"
}
if [ "$1" = 'cassandra' ]; then
: ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}
: ${CASSANDRA_LISTEN_ADDRESS='auto'}
if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
CASSANDRA_LISTEN_ADDRESS="$(_ip_address)"
fi
: ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}
if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
CASSANDRA_BROADCAST_ADDRESS="$(_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-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/'
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-in-place "$CASSANDRA_CONFIG/cassandra.yaml" \
-r 's/^(# )?('"$yaml"':).*/\2 '"$val"'/'
fi
done
for rackdc in dc rack; do
var="CASSANDRA_${rackdc^^}"
val="${!var}"
if [ "$val" ]; then
_sed-in-place "$CASSANDRA_CONFIG/cassandra-rackdc.properties" \
-r 's/^('"$rackdc"'=).*/\1 '"$val"'/'
fi
done
fi
exec "$@"