Skip to content

Commit

Permalink
CDB-39: Add DSE Docker files for local testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard Tudenhoefner committed Jun 22, 2020
1 parent 5bb6033 commit 96a9e47
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ buildNumber.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# DSE-related files
dse-db*.jar
dse-db*.pom
dse-commons*.jar
dse-commons*.pom
settings.xml

.metadata
bin/
tmp/
Expand Down
26 changes: 26 additions & 0 deletions Dockerfile-build-dse
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM maven:3.6.3-jdk-8-slim

WORKDIR /build

COPY pom.xml ./
COPY management-api-agent/pom.xml ./management-api-agent/pom.xml
COPY management-api-common/pom.xml ./management-api-common/pom.xml
COPY management-api-server/pom.xml ./management-api-server/pom.xml
COPY management-api-shim-3.x/pom.xml ./management-api-shim-3.x/pom.xml
COPY management-api-shim-4.x/pom.xml ./management-api-shim-4.x/pom.xml
COPY management-api-shim-dse-6.8/pom.xml ./management-api-shim-dse-6.8/pom.xml
# this duplicates work done in the next steps, but this should provide
# a solid cache layer that only gets reset on pom.xml changes
RUN mvn -q -ff -T 1C install && rm -rf target

COPY dse-commons-6.8.2-SNAPSHOT* /root/.m2/repository/com/datastax/dse/dse-commons/6.8.2-SNAPSHOT/
COPY dse-db-6.8.2-SNAPSHOT* /root/.m2/repository/com/datastax/dse/dse-db/6.8.2-SNAPSHOT/
COPY settings.xml /root/.m2/

COPY management-api-agent ./management-api-agent
COPY management-api-common ./management-api-common
COPY management-api-server ./management-api-server
COPY management-api-shim-3.x ./management-api-shim-3.x
COPY management-api-shim-4.x ./management-api-shim-4.x
COPY management-api-shim-dse-6.8 ./management-api-shim-dse-6.8
RUN mvn -q -ff package -DskipTests -P dse
31 changes: 31 additions & 0 deletions Dockerfile-dse-68
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM management-api-for-dse-builder as builder

FROM datastax/dse-server:6.8.0-ubi7-1

# accept the License
ENV DS_LICENSE=accept

COPY --from=builder /build/management-api-common/target/datastax-mgmtapi-common-0.1.0-SNAPSHOT.jar /opt/dse/
COPY --from=builder /build/management-api-agent/target/datastax-mgmtapi-agent-0.1.0-SNAPSHOT.jar /opt/dse/
COPY --from=builder /build/management-api-server/target/datastax-mgmtapi-server-0.1.0-SNAPSHOT.jar /opt/mgmtapi/
COPY --from=builder /build/management-api-shim-3.x/target/datastax-mgmtapi-shim-3.x-0.1.0-SNAPSHOT.jar /opt/mgmtapi/
COPY --from=builder /build/management-api-shim-4.x/target/datastax-mgmtapi-shim-4.x-0.1.0-SNAPSHOT.jar /opt/mgmtapi/

USER root
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

RUN microdnf update -y && rm -rf /var/cache/yum
RUN microdnf install wget procps python iproute net-tools -y && microdnf clean all

# backwards compat with upstream ENTRYPOINT
COPY dse-68/docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh && \
ln -sf /usr/local/bin/docker-entrypoint.sh /docker-entrypoint.sh

EXPOSE 9103
EXPOSE 8080

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["mgmtapi"]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ Finally build the Management API image:
> curl http://localhost:8080/api/v0/probes/readiness
OK

## Usage with DSE

A DSE jar must be locally available before running the Management API with DSE. Details are described in the [DSE README](management-api-shim-dse-6.8/README.md).
Once you have DSE jars published locally, follow these steps:
```
# The builder image needs to have the DSE jars, poms, and the Maven settings.xml (that provides access to Artifactory) and so we have to copy them over after building DSE:
cp $HOME/.m2/repository/com/datastax/dse/dse-db/6.8.2-SNAPSHOT/dse-db-6.8.2-SNAPSHOT.{jar,pom} $PWD
cp $HOME/.m2/repository/com/datastax/dse/dse-commons/6.8.2-SNAPSHOT/dse-commons-6.8.2-SNAPSHOT.{jar,pom} $PWD
cp $HOME/.m2/settings.xml $PWD
docker build -t management-api-for-dse-builder -f ./Dockerfile-build-dse .
docker build -t mgmtapi-dse -f Dockerfile-dse-68 .
docker run -p 8080:8080 -it --rm mgmtapi-dse
```

### Using the Service with a locally installed C* or DSE instance

Expand Down
20 changes: 20 additions & 0 deletions dse-68/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM datastax/dse-server:6.8.0-ubi7-1

USER root
RUN microdnf update && rm -rf /var/cache/yum && \
microdnf install libjemalloc1 procps python iproute2 numactl iproute2 net-tools && microdnf clean all

ENV DS_LICENSE=accept
ENV PATH $DSE_HOME/bin:$PATH

# smoke test
USER dse:root
RUN dse -v

VOLUME ["/var/lib/cassandra", "/var/lib/spark", "/var/lib/dsefs", "/var/log/cassandra", "/var/log/spark"]

COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh /docker-entrypoint.sh # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["dse", "cassandra", "-f"]
160 changes: 160 additions & 0 deletions dse-68/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/bin/bash
set -e

# first arg is `-f` or `--some-option`
# or there are no args
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
set -- dse cassandra -f "$@"
fi

if [ "$CASSANDRA_CONF" == "" ]; then
export CASSANDRA_CONF=/opt/dse/resources/cassandra/conf
fi

# allow the container to be started with `--user`
if [ "$1" = 'mgmtapi' -a "$(id -u)" = '0' ]; then
find "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra \
\! -user dse -exec chown dse '{}' +
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" = 'mgmtapi' ]; then
echo "Starting Management API"

if ! grep -qxF "JVM_OPTS=\"\$JVM_OPTS -javaagent:/opt/dse/datastax-mgmtapi-agent-0.1.0-SNAPSHOT.jar\"" < /opt/dse/resources/cassandra/conf/cassandra-env.sh ; then
# ensure newline at end of file
echo "" >> /opt/dse/resources/cassandra/conf/cassandra-env.sh
echo "JVM_OPTS=\"\$JVM_OPTS -javaagent:/opt/dse/datastax-mgmtapi-agent-0.1.0-SNAPSHOT.jar\"" >> /opt/dse/resources/cassandra/conf/cassandra-env.sh
fi

# Set this if you want to ignore default env variables, i.e. when running inside an operator
if [ $IGNORE_DEFAULTS ]; then
CASSANDRA_RPC_ADDRESS='0.0.0.0'
CASSANDRA_BROADCAST_RPC_ADDRESS="$(_ip_address)"
else
: ${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"}

CASSANDRA_YAML="cassandra.yaml"
if [ $CASSANDRA_DEPLOYMENT ]; then
CASSANDRA_DEPLOYMENT=`echo "$CASSANDRA_DEPLOYMENT" | awk '{print tolower($0)}'`
CASSANDRA_YAML="cassandra-$CASSANDRA_DEPLOYMENT.yaml"
fi

_sed-in-place "$CASSANDRA_CONF/$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_CONF/$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_CONF/cassandra-rackdc.properties" \
-r 's/^('"$rackdc"'=).*/\1 '"$val"'/'
fi
done
fi

MGMT_API_ARGS=""

# Hardcoding these for now
MGMT_API_CASSANDRA_SOCKET="--db-socket /tmp/db.sock"
MGMT_API_LISTEN_TCP="--host tcp://0.0.0.0:8080"
MGMT_API_LISTEN_SOCKET="--host file:///tmp/oss-mgmt.sock"

MGMT_API_ARGS="$MGMT_API_ARGS $MGMT_API_CASSANDRA_SOCKET $MGMT_API_LISTEN_TCP $MGMT_API_LISTEN_SOCKET"

# These will generally come from the k8s operator
if [ ! -z "$MGMT_API_EXPLICIT_START" ]; then
MGMT_API_EXPLICIT_START="--explicit-start $MGMT_API_EXPLICIT_START"
MGMT_API_ARGS="$MGMT_API_ARGS $MGMT_API_EXPLICIT_START"
fi

if [ ! -z "$MGMT_API_TLS_CA_CERT_FILE" ]; then
MGMT_API_TLS_CA_CERT_FILE="--tlscacert $MGMT_API_TLS_CA_CERT_FILE"
MGMT_API_ARGS="$MGMT_API_ARGS $MGMT_API_TLS_CA_CERT_FILE"
fi
if [ ! -z "$MGMT_API_TLS_CERT_FILE" ]; then
MGMT_API_TLS_CERT_FILE="--tlscert $MGMT_API_TLS_CERT_FILE"
MGMT_API_ARGS="$MGMT_API_ARGS $MGMT_API_TLS_CERT_FILE"
fi
if [ ! -z "$MGMT_API_TLS_KEY_FILE" ]; then
MGMT_API_TLS_KEY_FILE="--tlskey $MGMT_API_TLS_KEY_FILE"
MGMT_API_ARGS="$MGMT_API_ARGS $MGMT_API_TLS_KEY_FILE"
fi

if [ ! -z "$MGMT_API_PID_FILE" ]; then
MGMT_API_PID_FILE="--pidfile $MGMT_API_PID_FILE"
MGMT_API_ARGS="$MGMT_API_ARGS $MGMT_API_PID_FILE"
fi

MGMT_API_DSE_HOME="--db-home ${DSE_HOME}"
MGMT_API_ARGS="$MGMT_API_ARGS $MGMT_API_DSE_HOME"

if [ ! -z "$MGMT_API_NO_KEEP_ALIVE" ]; then
MGMT_API_NO_KEEP_ALIVE="--no-keep-alive $MGMT_API_NO_KEEP_ALIVE"
MGMT_API_ARGS="$MGMT_API_ARGS $MGMT_API_NO_KEEP_ALIVE"
fi

MGMT_API_JAR="$(find "/opt/mgmtapi" -name *server*.jar)"

echo "Running" java ${MGMT_API_JAVA_OPTS} -Xms128m -Xmx128m -jar "$MGMT_API_JAR" $MGMT_API_ARGS
exec java ${MGMT_API_JAVA_OPTS} -Xms128m -Xmx128m -jar "$MGMT_API_JAR" $MGMT_API_ARGS

fi

exec "$@"

0 comments on commit 96a9e47

Please sign in to comment.