-
Notifications
You must be signed in to change notification settings - Fork 3.9k
CASSANDRA-18035: Add quick start development guide and ant targets for local docker development #1996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
CASSANDRA-18035: Add quick start development guide and ant targets for local docker development #1996
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| # | ||
| # 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. | ||
| # | ||
| # Forked from https://github.com/docker-library/cassandra/blob/b3332696b4a6a4405ebf95a4c4065543ee1a073d/4.0/Dockerfile | ||
| # | ||
| # WARNING: This Dockerfile has no warranties, should be used only for Cassandra development purposes. | ||
| # | ||
| FROM eclipse-temurin:11-jre-focal | ||
|
|
||
| ARG CASSANDRA_TARBALL | ||
|
|
||
| # explicitly set user/group IDs | ||
| RUN set -eux; \ | ||
| groupadd -r cassandra --gid=999; \ | ||
| useradd -r -g cassandra --uid=999 cassandra | ||
|
|
||
| RUN set -eux; \ | ||
| apt-get update; \ | ||
| apt-get install -y --no-install-recommends \ | ||
| # solves warning: "jemalloc shared library could not be preloaded to speed up memory allocations" | ||
| libjemalloc2 \ | ||
| # "free" is used by cassandra-env.sh | ||
| procps \ | ||
| # "cqlsh" needs a python interpreter | ||
| python3 \ | ||
| # "ip" is not required by Cassandra itself, but is commonly used in scripting Cassandra's configuration (since it is so fixated on explicit IP addresses) | ||
| iproute2 \ | ||
| # Cassandra will automatically use numactl if available | ||
| # https://github.com/apache/cassandra/blob/18bcda2d4c2eba7370a0b21f33eed37cb730bbb3/bin/cassandra#L90-L100 | ||
| # https://github.com/apache/cassandra/commit/604c0e87dc67fa65f6904ef9a98a029c9f2f865a | ||
| numactl \ | ||
| # required for docker health-check | ||
| netcat \ | ||
| ; \ | ||
| rm -rf /var/lib/apt/lists/*; \ | ||
| # https://issues.apache.org/jira/browse/CASSANDRA-15767 ("bin/cassandra" only looks for "libjemalloc.so" or "libjemalloc.so.1" which doesn't match our "libjemalloc.so.2") | ||
| libjemalloc="$(readlink -e /usr/lib/*/libjemalloc.so.2)"; \ | ||
| ln -sT "$libjemalloc" /usr/local/lib/libjemalloc.so; \ | ||
| ldconfig | ||
|
|
||
| # grab gosu for easy step-down from root | ||
| # https://github.com/tianon/gosu/releases | ||
| ENV GOSU_VERSION 1.14 | ||
| RUN set -eux; \ | ||
| savedAptMark="$(apt-mark showmanual)"; \ | ||
| apt-get update; \ | ||
| apt-get install -y --no-install-recommends ca-certificates dirmngr gnupg wget; \ | ||
| rm -rf /var/lib/apt/lists/*; \ | ||
| dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ | ||
| wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ | ||
| wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ | ||
| export GNUPGHOME="$(mktemp -d)"; \ | ||
| gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ | ||
| gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ | ||
| gpgconf --kill all; \ | ||
| rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ | ||
| apt-mark auto '.*' > /dev/null; \ | ||
| [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ | ||
| apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
| chmod +x /usr/local/bin/gosu; \ | ||
| gosu --version; \ | ||
| gosu nobody true | ||
| COPY $CASSANDRA_TARBALL cassandra-bin.tgz | ||
| ENV CASSANDRA_HOME /opt/cassandra | ||
| ENV CASSANDRA_CONF /etc/cassandra | ||
| ENV PATH $CASSANDRA_HOME/bin:$PATH | ||
|
|
||
| RUN set -eux; \ | ||
| savedAptMark="$(apt-mark showmanual)"; \ | ||
| apt-get update; \ | ||
| apt-get install -y --no-install-recommends ca-certificates dirmngr gnupg wget; \ | ||
| rm -rf /var/lib/apt/lists/*; \ | ||
| \ | ||
| apt-mark auto '.*' > /dev/null; \ | ||
| [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ | ||
| apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ | ||
| \ | ||
| mkdir -p "$CASSANDRA_HOME"; \ | ||
| tar --extract --file cassandra-bin.tgz --directory "$CASSANDRA_HOME" --strip-components 1; \ | ||
| rm cassandra-bin.tgz*; \ | ||
| \ | ||
| [ ! -e "$CASSANDRA_CONF" ]; \ | ||
| mv "$CASSANDRA_HOME/conf" "$CASSANDRA_CONF"; \ | ||
| ln -sT "$CASSANDRA_CONF" "$CASSANDRA_HOME/conf"; \ | ||
| \ | ||
| dpkgArch="$(dpkg --print-architecture)"; \ | ||
| case "$dpkgArch" in \ | ||
| ppc64el) \ | ||
| # https://issues.apache.org/jira/browse/CASSANDRA-13345 | ||
| # "The stack size specified is too small, Specify at least 328k" | ||
| grep -- '^-Xss256k$' "$CASSANDRA_CONF/jvm-server.options"; \ | ||
| sed -ri 's/^-Xss256k$/-Xss512k/' "$CASSANDRA_CONF/jvm-server.options"; \ | ||
| grep -- '^-Xss512k$' "$CASSANDRA_CONF/jvm-server.options"; \ | ||
| ;; \ | ||
| esac; \ | ||
| \ | ||
| mkdir -p "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra; \ | ||
| chown -R cassandra:cassandra "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra; \ | ||
| chmod 777 "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra; \ | ||
| chmod -R a+rwX "$CASSANDRA_CONF"; \ | ||
| ln -sT /var/lib/cassandra "$CASSANDRA_HOME/data"; \ | ||
| ln -sT /var/log/cassandra "$CASSANDRA_HOME/logs"; \ | ||
| \ | ||
| # smoke test | ||
| cassandra -v | ||
|
|
||
| VOLUME /var/lib/cassandra | ||
|
|
||
| COPY docker-entrypoint.sh /usr/local/bin/ | ||
| 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 | ||
|
|
||
| # Container is healthy when JMX port is up | ||
| HEALTHCHECK CMD /usr/bin/nc localhost -z 7199 || exit 1 | ||
|
|
||
| CMD ["cassandra", "-f"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #!/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. | ||
| # | ||
| # Forked from https://github.com/docker-library/cassandra/blob/51b30b5d78616d8db73153dede5df440d0ea7fc4/4.0/docker-entrypoint.sh | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. |
||
| find "$CASSANDRA_CONF" /var/lib/cassandra /var/log/cassandra \ | ||
| \! -user cassandra -exec chown cassandra '{}' + | ||
| 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" { next } # only lines with ip addresses | ||
| $NF == "lo" { next } # skip loopback devices | ||
| $2 ~ /^127[.]/ { next } # skip loopback addresses | ||
| $2 ~ /^169[.]254[.]/ { next } # skip link-local addresses | ||
| { | ||
| 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'} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all of these in this |
||
|
|
||
| : ${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_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 | ||
|
|
||
| exec "$@" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/bin/bash | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| # | ||
| # 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 -e | ||
|
|
||
| function display_help { | ||
| echo | ||
| echo "Use 'docker-exec -it cassandra-test <CMD>' to execute commands on this container." | ||
| echo "ie. docker exec -it cassandra-test nodetool status" | ||
| echo "ie. docker exec -it cassandra-test cqlsh" | ||
| } | ||
|
|
||
| if ! docker info > /dev/null 2>&1; then | ||
| echo "Docker is not running, please retry after starting docker." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if local image exists | ||
| if [[ "$(docker images -q apache/cassandra-test 2> /dev/null)" == "" ]]; then | ||
| echo "cassandra-test image does not exist, please create it with 'ant docker-build'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if container is already running | ||
| if [ $( docker ps -a -f name=cassandra-test | wc -l ) -eq 2 ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDEA says:
|
||
| echo "cassandra-test container is already running, please stop it with 'ant docker-stop'." | ||
| display_help | ||
| exit 1 | ||
| fi | ||
|
|
||
| ## Create network if does not exist | ||
| docker network create cassandra-test 2>/dev/null || true | ||
|
|
||
| CONTAINER_ID=`docker run --rm --name cassandra-test --network cassandra-test -d apache/cassandra-test` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDEA says: |
||
|
|
||
| until [ "$( docker container inspect -f '{{.State.Health.Status}}' $CONTAINER_ID )" != "starting" ] | ||
| do | ||
| echo "Waiting for cassandra-test container $CONTAINER_ID to start." | ||
| sleep 5 | ||
| done | ||
|
|
||
| if [ "$( docker container inspect -f '{{.State.Health.Status}}' $CONTAINER_ID )" != "healthy" ]; then | ||
| echo "Cassandra test container $CONTAINER_ID started but is unhealty." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "cassandra-test container started with id $CONTAINER_ID" | ||
| display_help | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/bash | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldnt this be |
||
| # | ||
| # 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 -e | ||
|
|
||
| if ! docker info > /dev/null 2>&1; then | ||
| echo "Docker is not running, please retry after starting docker." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ $( docker ps -a -f name=cassandra-test | wc -l ) -eq 2 ]; then | ||
| CONTAINER=`docker rm --force cassandra-test` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDEA says |
||
| if [ $? -eq 0 ]; then | ||
| echo "Stopped and removed container '$CONTAINER'"; | ||
| fi | ||
| else | ||
| echo "cassandra-test container is not running" | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| .gitignore | ||
|
|
||
| # C* | ||
| docker/cassandra-bin.tgz | ||
| build/ | ||
| src/gen-java/ | ||
| src/resources/org/apache/cassandra/config/ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be replaced by nodetool status returning 0 exit code. The fact that this port is up does not necessarily mean that nodetool status will be successful as port is open but the node is still booting anyway under the hood.