You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by fg...@apache.org on 2018/09/10 23:33:52 UTC
[incubator-sdap-nexus] branch master updated: Update cassandra
image version. Made init script run on every startup. (#30)
This is an automated email from the ASF dual-hosted git repository.
fgreg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git
The following commit(s) were added to refs/heads/master by this push:
new c2881f1 Update cassandra image version. Made init script run on every startup. (#30)
c2881f1 is described below
commit c2881f1821f2252b5e35ff9ca422053826fedcc9
Author: fgreg <fg...@gmail.com>
AuthorDate: Mon Sep 10 16:33:50 2018 -0700
Update cassandra image version. Made init script run on every startup. (#30)
---
.../config/schemas/cassandra/nexustiles.cql | 4 +-
docker/cassandra/Dockerfile | 13 +++-
docker/cassandra/docker-entrypoint.sh | 85 ++++++++++++++++++++++
3 files changed, 97 insertions(+), 5 deletions(-)
diff --git a/data-access/config/schemas/cassandra/nexustiles.cql b/data-access/config/schemas/cassandra/nexustiles.cql
index f0b8e36..43304a7 100644
--- a/data-access/config/schemas/cassandra/nexustiles.cql
+++ b/data-access/config/schemas/cassandra/nexustiles.cql
@@ -1,8 +1,6 @@
CREATE KEYSPACE IF NOT EXISTS nexustiles WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
-DROP TABLE IF EXISTS nexustiles.sea_surface_temp;
-
-CREATE TABLE nexustiles.sea_surface_temp (
+CREATE TABLE IF NOT EXISTS nexustiles.sea_surface_temp (
tile_id uuid PRIMARY KEY,
tile_blob blob
);
diff --git a/docker/cassandra/Dockerfile b/docker/cassandra/Dockerfile
index e9c93b7..60acb5a 100644
--- a/docker/cassandra/Dockerfile
+++ b/docker/cassandra/Dockerfile
@@ -13,10 +13,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-FROM cassandra:2.2.8
+FROM cassandra:2.2
MAINTAINER Apache SDAP "dev@sdap.apache.org"
RUN apt-get update && apt-get -y install git && rm -rf /var/lib/apt/lists/*
-RUN cd / && git clone https://github.com/apache/incubator-sdap-nexus.git && cp -r /incubator-sdap-nexus/data-access/config/schemas/cassandra/nexustiles.cql /tmp/. && rm -rf /incubator-sdap-nexus
+RUN mkdir -p /docker-entrypoint-initdb.d && \
+ chown -R cassandra:cassandra /docker-entrypoint-initdb.d && \
+ chmod 777 /docker-entrypoint-initdb.d && \
+ cd /tmp && \
+ git clone https://github.com/apache/incubator-sdap-nexus.git && \
+ cp -r /tmp/incubator-sdap-nexus/data-access/config/schemas/cassandra/nexustiles.cql /docker-entrypoint-initdb.d/nexustiles.cql && \
+ rm -rf /tmp/incubator-sdap-nexus
+
+COPY docker-entrypoint.sh /usr/local/bin/
+ENTRYPOINT ["docker-entrypoint.sh"]
diff --git a/docker/cassandra/docker-entrypoint.sh b/docker/cassandra/docker-entrypoint.sh
new file mode 100755
index 0000000..b6410ed
--- /dev/null
+++ b/docker/cassandra/docker-entrypoint.sh
@@ -0,0 +1,85 @@
+#!/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
+ chown -R cassandra /var/lib/cassandra /var/log/cassandra "$CASSANDRA_CONFIG"
+ exec gosu cassandra "$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
+ }
+ '
+}
+
+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 -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/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_CONFIG/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_CONFIG/cassandra-rackdc.properties"
+ fi
+ done
+fi
+
+for f in /docker-entrypoint-initdb.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
+
+exec "$@"