├── .dockerignore ├── .gitignore ├── .travis.yml ├── README.adoc ├── poststart.d ├── 01-bootstrap-schemas.sh ├── 02-bootstrap-datatypes.sh └── 99-join-cluster.sh ├── prestart.d ├── 00-update-riak-conf.sh └── 01-maybe-update-cluster-convergence.sh ├── rel_to_pkg.sh ├── riak-cluster.sh ├── test ├── riak_docker │ ├── __init__.py │ └── test_fixtures.py ├── schemas │ ├── GeoCheckin.sql │ └── test.dt ├── test_riak_container.py └── user.conf └── vars.adoc /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /Dockerfile 3 | /abuild 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | services: 4 | - docker 5 | 6 | before_script: 7 | - gem install asciibuild 8 | - '[ "false" == "$TRAVIS_PULL_REQUEST" ] && docker login -u $DOCKER_USER -p $DOCKER_PASSWORD' 9 | 10 | script: 11 | - travis_retry asciibuild $ASCIIBUILD_OPTS -a travis=$TRAVIS -a skip_publish=$TRAVIS_PULL_REQUEST README.adoc 12 | 13 | env: 14 | global: 15 | - RIAK_TS_VERSION=1.5.2 16 | - RIAK_20_VERSION=2.0.7 17 | - RIAK_21_VERSION=2.1.4 18 | - RIAK_22_VERSION=2.2.3 19 | matrix: 20 | - ASCIIBUILD_OPTS="-a os_family=centos -a os_version=7 -a riak_flavor=kv -a riak_version=$RIAK_20_VERSION" 21 | - ASCIIBUILD_OPTS="-a os_family=centos -a os_version=7 -a riak_flavor=kv -a riak_version=$RIAK_21_VERSION" 22 | - ASCIIBUILD_OPTS="-a os_family=centos -a os_version=7 -a riak_flavor=kv -a riak_version=$RIAK_22_VERSION" 23 | - ASCIIBUILD_OPTS="-a os_family=centos -a os_version=7 -a riak_flavor=ts -a riak_version=$RIAK_TS_VERSION" 24 | - ASCIIBUILD_OPTS="-a os_family=ubuntu -a os_version=14.04 -a riak_flavor=kv -a riak_version=$RIAK_20_VERSION" 25 | - ASCIIBUILD_OPTS="-a os_family=ubuntu -a os_version=14.04 -a riak_flavor=kv -a riak_version=$RIAK_21_VERSION" 26 | - ASCIIBUILD_OPTS="-a os_family=ubuntu -a os_version=14.04 -a riak_flavor=kv -a riak_version=$RIAK_22_VERSION -a latest" 27 | - ASCIIBUILD_OPTS="-a os_family=ubuntu -a os_version=14.04 -a riak_flavor=ts -a riak_version=$RIAK_TS_VERSION -a latest" 28 | - ASCIIBUILD_OPTS="-a os_family=debian -a os_version=8 -a riak_flavor=ts -a riak_version=$RIAK_TS_VERSION" 29 | 30 | deploy: 31 | provider: s3 32 | access_key_id: $ACCESS_KEY 33 | secret_access_key: $SECRET_KEY 34 | bucket: basho-ci-logs 35 | local_dir: abuild 36 | upload-dir: $TRAVIS_REPO_SLUG/$TRAVIS_BRANCH 37 | skip_cleanup: true 38 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Riak in Docker 2 | Jon Brisbin 3 | 4 | This asciibuild footnote:[https://github.com/jbrisbin/asciibuild] file can be used to build a wide variety of variations of Docker containers for running a Riak cluster. It runs a single node per container instance and by setting the `CLUSTER_COORDINATOR` environment variable to the IP address of a "master" node (the primary or seed node of a cluster), subsequent containers can be automatically joined into a cluster. 5 | 6 | image:https://travis-ci.org/basho-labs/riak-docker.svg[link="https://travis-ci.org/basho-labs/riak-docker"] 7 | 8 | include::vars.adoc[] 9 | 10 | .Variables to Set that influence the build 11 | * `riak_version`: {riak_version} 12 | * `riak_flavor`: {riak_flavor} 13 | * `riak_tag`: {riak_tag} 14 | * `riak_explorer_version`: {riak_explorer_version} 15 | * `riak_client_version`: {riak_client_version} 16 | 17 | [[switches]] 18 | .Variables for turning on or off components 19 | * `openjdk`: _set or unset_ Whether or not to include OpenJDK 8 20 | * `docker`: _set or unset_ Whether or not to include the Docker command-line tools 21 | * `riak_explorer`: _set or unset_ Whether or not to include Riak Explorer 22 | * `riak_client`: _set or unset_ Whether or not to include the Riak Python client 23 | 24 | == Create Image 25 | 26 | .Riak Docker 27 | [source,Dockerfile] 28 | [asciibuild,Dockerfile,image="{riak_tag}",run=true,run_opts="--label role=cluster --name {riak_pkg} -p 8087:8087 -p 8098:8098 -v /var/run/docker.sock:/var/run/docker.sock"] 29 | ---- 30 | FROM {{os_family}}:{{os_version}} 31 | 32 | ENV OS_FAMILY {{os_family}} 33 | ENV OS_VERSION {{os_version}} 34 | ifdef::os_flavor[] 35 | ENV OS_FLAVOR {{os_flavor}} 36 | endif::[] 37 | 38 | ifdef::ubuntu,debian[] 39 | ENV DEBIAN_FRONTEND noninteractive 40 | ENV DEBCONF_NONINTERACTIVE_SEEN true 41 | 42 | # Install essentials 43 | RUN apt-get update 44 | RUN apt-get dist-upgrade -y 45 | RUN apt-get install -y apt-transport-https 46 | RUN apt-get install -y python python-six python-pkg-resources python-openssl 47 | RUN apt-get install -y curl 48 | RUN apt-get install -y libapr1 realpath jq unzip 49 | RUN apt-get install -y iproute iputils-ping 50 | 51 | ifdef::openjdk[] 52 | # Install OpenJDK 8 53 | RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DA1A4A13543B466853BAF164EB9B1D8886F44E2A 54 | ifdef::ubuntu[] 55 | RUN echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu {{os_flavor}} main" >/etc/apt/sources.list.d/openjdk.list 56 | RUN echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu {{os_flavor}} main" >>/etc/apt/sources.list.d/openjdk.list 57 | endif::ubuntu[] 58 | ifdef::debian+jessie[] 59 | RUN echo "deb http://http.debian.net/debian jessie-backports main" >/etc/apt/sources.list.d/openjdk.list 60 | endif::debian+jessie[] 61 | RUN apt-get update 62 | RUN apt-get install -y openjdk-8-jre-headless openjdk-8-jdk-headless 63 | endif::openjdk[] 64 | endif::ubuntu,debian[] 65 | 66 | ifdef::centos[] 67 | # Install essentials 68 | RUN yum install -y epel-release 69 | RUN yum -q -y install openssl curl python python-six python-setuptools ca-certificates jq which unzip 70 | ifdef::openjdk[] 71 | RUN yum -q -y install java-1.8.0-openjdk 72 | endif::openjdk[] 73 | endif::centos[] 74 | 75 | ifdef::docker[] 76 | # Install Docker for command-line utilities 77 | ifdef::ubuntu,debian[] 78 | RUN apt-get install -y docker 79 | endif::[] 80 | ifdef::centos[] 81 | RUN yum install -y docker 82 | endif::[] 83 | endif::docker[] 84 | 85 | ENV RIAK_VERSION {{riak_version}} 86 | ENV RIAK_HOME {{riak_home}} 87 | ifndef::riak_ts[] 88 | ENV RIAK_FLAVOR KV 89 | endif::[] 90 | ifdef::riak_ts[] 91 | ENV RIAK_FLAVOR TS 92 | endif::[] 93 | ifeval::["{pkg_format}" == "tgz"] 94 | RUN \ 95 | mkdir -p $RIAK_HOME && \ 96 | curl -sL {{riak_tgz_baseurl}}/{{os_family}}-{{os_version}}/{{riak_pkg}}-oss/{{riak_pkg}}-{{riak_version}}/{{riak_pkg}}-{{riak_version}}-bin.tgz | tar -zxf - -C $RIAK_HOME 97 | COPY rel_to_pkg.sh /tmp 98 | RUN chmod a+x /tmp/rel_to_pkg.sh && /tmp/rel_to_pkg.sh 99 | ENV PATH $RIAK_HOME/bin:$PATH 100 | endif::[] 101 | ifeval::["{pkg_format}" != "tgz"] 102 | RUN curl -s https://packagecloud.io/install/repositories/basho/{{riak_pkg}}/script.{{pkg_format}}.sh | bash 103 | ifdef::ubuntu,debian[] 104 | RUN apt-get install -y {{riak_pkg}}={{riak_version}}-1 105 | endif::[] 106 | ifdef::centos[] 107 | RUN yum install -y {{riak_pkg}}-{{riak_version}} 108 | endif::[] 109 | endif::[] 110 | 111 | ifdef::riak_explorer[] 112 | # Install Riak Explorer 113 | RUN curl -sSL https://github.com/basho-labs/riak_explorer/releases/download/{{riak_explorer_version}}/riak_explorer-{{riak_explorer_version}}.patch-{{os_family}}-{{os_version}}.tar.gz | tar -zxf - -C $RIAK_HOME --strip-components 2 114 | RUN for f in riak_pb riak_kv riak_ts riak_dt riak_search riak_yokozuna;do rm -f $RIAK_HOME/lib/basho-patches/$f*; done 115 | endif::riak_explorer[] 116 | 117 | ifdef::riak_client[] 118 | # Install the Python client 119 | ifdef::ubuntu,debian[] 120 | RUN apt-get install -y build-essential libssl-dev libffi-dev python-dev python-pip 121 | endif::[] 122 | ifdef::centos[] 123 | RUN yum groups install -y 'Development Tools' 124 | RUN yum install -y openssl-devel python-devel libffi-devel python-pip 125 | endif::[] 126 | RUN pip install --upgrade pip cryptography pyparsing appdirs riak 127 | endif::riak_client[] 128 | 129 | # Expose default ports 130 | EXPOSE 8087 131 | EXPOSE 8098 132 | 133 | # Expose volumes for data and logs 134 | VOLUME /var/log/riak 135 | VOLUME /var/lib/riak 136 | 137 | # Install custom start script 138 | COPY riak-cluster.sh $RIAK_HOME/riak-cluster.sh 139 | RUN chmod a+x $RIAK_HOME/riak-cluster.sh 140 | # Install custom hooks 141 | COPY prestart.d /etc/riak/prestart.d 142 | COPY poststart.d /etc/riak/poststart.d 143 | 144 | # Prepare for bootstrapping schemas 145 | RUN mkdir -p /etc/riak/schemas 146 | 147 | WORKDIR /var/lib/riak 148 | 149 | CMD ["{{riak_home}}/riak-cluster.sh"] 150 | 151 | # Clean up APT cache 152 | RUN rm -rf /var/lib/apt/lists/* /tmp/* 153 | ---- 154 | 155 | === Building the Image 156 | 157 | This file is an asciibuild-enabled AsciiDoc file. It is also heavily parameterized in order to produce a wide variety of variations. Some of the variations possible include: 158 | 159 | .Docker Image Variations 160 | * Riak KV 161 | - Based on `ubuntu:14.04` 162 | - Based on `centos:7` 163 | * Riak TS 164 | - Based on `ubuntu:14.04` 165 | - Based on `centos:7` 166 | - Based on `debian:8` 167 | * Optional components (enabled or disabled link:#switches[based on the attributes set]) 168 | - http://openjdk.java.net/[OpenJDK 8] 169 | - https://github.com/basho-labs/riak_explorer[Riak Explorer] 170 | - https://www.docker.com/[Docker] 171 | - https://github.com/basho/riak-python-client[Riak Python client] 172 | 173 | This asciibuild file will produce a riak_{riak_flavor} image based on {os_family}:{os_version}. Optional components included in this build: 174 | 175 | .Optional Components 176 | ifdef::openjdk[] 177 | * OpenJDK 8 178 | endif::[] 179 | ifdef::docker[] 180 | * Docker 181 | endif::[] 182 | ifdef::riak_explorer[] 183 | * Riak Explorer 184 | endif::[] 185 | ifdef::riak_client[] 186 | * Riak Python Client 187 | endif::[] 188 | 189 | To build the image using `asciibuild`, process this README file: 190 | 191 | .Invoke Asciibuild 192 | [source,bash] 193 | ---- 194 | asciibuild README.adoc 195 | ---- 196 | 197 | To change the variation of image produced, set attributes according to the following configuration matrix: 198 | 199 | .Alternative Configuration 200 | |=== 201 | | *Attribute Value* | *Produces* 202 | | `-a os_family=ubuntu -a os_version=14.04` | Ubuntu Trusty image 203 | | `-a os_family=centos -a os_version=7` | CentOS 7 image 204 | | `-a openjdk!` | Turns off OpenJDK install 205 | | `-a docker!` | Turns off Docker install 206 | | `-a riak_explorer!` | Turns off Riak Explorer install 207 | | `-a riak_client!` | Turns off Riak Python Client install 208 | |=== 209 | 210 | == Test Single Node 211 | 212 | Validate the container is started by waiting for it to fully boot, then access the `/stats` endpoint. 213 | 214 | .Wait for riak_kv to start 215 | [source,bash] 216 | [asciibuild,bash,container="Riak Docker"] 217 | ---- 218 | riak-admin wait-for-service riak_kv 219 | ---- 220 | 221 | .Check node Status 222 | [source,bash] 223 | [asciibuild,bash] 224 | ---- 225 | function stats() { 226 | echo `curl -s localhost:8098/stats | jq -r '.vnode_gets'` 227 | } 228 | # There should be no read stats for an empty cluster 229 | [ "0" == "$(stats)" ] 230 | # Increment the read stats 231 | curl -s localhost:8098/types/default/buckets/notfound/keys/notfound 232 | # Wait for stats to be eventually-consistent 233 | sleep 1 234 | # Verify read stats have incremented 235 | [ "3" == "$(stats)" ] 236 | ---- 237 | 238 | == Test User Conf 239 | 240 | To augment the `riak.conf` file with additional settings, mount a `user.conf` file into the `/etc/riak/` directory. Each line should follow the pattern `setting = value`. Each line will be split on the `=` and made into a regex passed to `sed` that matches the setting key and replaces the value with the value you specify in `user.conf`. 241 | 242 | .Patch Configuration File 243 | [source,bash] 244 | [asciibuild,bash] 245 | ---- 246 | # {{=<% %>=}} 247 | CONTAINER=$(docker run --label role=cluster -d -P -v `pwd`/test/user.conf:/etc/riak/user.conf <% riak_tag %>) 248 | docker exec $CONTAINER riak-admin wait-for-service riak_kv 249 | 250 | # Check that the backend was set to leveldb 251 | BACKEND=$(docker exec $CONTAINER riak config effective | egrep "^storage_backend" | cut -d= -f2 | tr -d ' ') 252 | [ "$BACKEND" == "leveldb" ] 253 | ---- 254 | 255 | == Test Cluster 256 | 257 | This Docker image has support for automatically creating a cluster by setting the environment variable `COORDINATOR_NODE` to the IP address of a node to which you want to join when the container starts. 258 | 259 | .Start additional Cluster Nodes 260 | [source,bash] 261 | [asciibuild,bash] 262 | ---- 263 | # {{=<% %>=}} 264 | # Discover coordinator node IP 265 | COORDINATOR_NODE=$(docker inspect -f {{.NetworkSettings.IPAddress}} <% riak_pkg %>) 266 | 267 | # Start new nodes for the cluster 268 | for i in 1 2; do 269 | CONTAINER=$(docker run -d --label=asciibuild.name="Riak in Docker" --label=role=cluster -e COORDINATOR_NODE=$COORDINATOR_NODE <% riak_tag %>) 270 | # Wait for node to completely start 271 | docker exec $CONTAINER riak-admin wait-for-service riak_kv 272 | done 273 | 274 | # Wait for cluster to settle some 275 | sleep 5 276 | 277 | # Verify three nodes report up 278 | STATUS=$(docker exec <% riak_pkg %> riak-admin cluster status --format csv | tail -n 3 | cut -d, -f3) 279 | [ "$(echo $STATUS)" == "up up up" ] 280 | ---- 281 | 282 | ifdef::riak_explorer[] 283 | == Test Bucket Type Bootstrapping 284 | 285 | This Docker image has support for automatically boostrapping bucket types and TS tables. Files in `/etc/riak/schemas/` that end in `.dt` will be read and the name of the file (minus the extension `.dt`) will be used as the bucket name and the contents of the file should contain a single line, which is the bucket type to use. 286 | 287 | ./etc/riak/schemas/my_bucket.dt 288 | ---- 289 | counter 290 | ---- 291 | 292 | If the boostrapping script found the above, it would translate that into a `riak-admin bucket-type create`, followed by a `riak-admin bucket-type activate`. 293 | 294 | .Datatype Bootstrapping 295 | [source,bash] 296 | ---- 297 | riak-admin bucket-type create my_bucket '{"props":{"datatype":"counter"}}' 298 | riak-admin bucket-type activate my_bucket 299 | ---- 300 | 301 | To enable automatic bootstrapping, mount the schemas into the container via volume, or `COPY` the resources into the `/etc/riak/schemas` directory in a derived container. 302 | 303 | .Mount via Volume 304 | [source,bash] 305 | [asciibuild,bash] 306 | ---- 307 | # {{=<% %>=}} 308 | SCHEMAS_CONTAINER=$(docker run -d -P --label role=schemas -v $(pwd)/test/schemas:/etc/riak/schemas <% riak_tag %>) 309 | docker exec $SCHEMAS_CONTAINER riak-admin wait-for-service riak_kv 310 | 311 | # Discover the IP of the container 312 | IP=$(docker inspect -f '{{.NetworkSettings.IPAddress}}' $SCHEMAS_CONTAINER) 313 | 314 | # Only way to ensure bucket types exist is to wait for script to complete. 315 | # There's no way to know when it's done, so we just do a sleep. 316 | sleep 5 317 | 318 | # Check that the bucket type has been defined 319 | BUCKET_TYPES=$(docker exec $SCHEMAS_CONTAINER curl -s $IP:8098/admin/explore/clusters/default/bucket_types) 320 | [[ ! -z "$BUCKET_TYPES" ]] 321 | 322 | [ "$(echo $BUCKET_TYPES | jq -r '.bucket_types[] | select(.id == "test") | .props.datatype')" == "counter" ] 323 | if [ '<% riak_flavor %>' == 'ts' ]; then 324 | # Check that the TS tables have been created 325 | [ "$(echo $BUCKET_TYPES | jq -r '.bucket_types[] | select(.id == "GeoCheckin") | .props.ddl.local_key[]' | tr -d '\n')" == "idtime" ] 326 | fi 327 | 328 | # Remove the container 329 | docker rm -f $SCHEMAS_CONTAINER || true 330 | ---- 331 | endif::riak_explorer[] 332 | 333 | ifdef::riak_client[] 334 | == Test Riak Client 335 | 336 | Test that the Python Riak Client can interact with the cluster. 337 | 338 | .Pytest Container 339 | [source,Dockerfile] 340 | [asciibuild,Dockerfile,image=riak-docker-tests,run=true,run_opts="--link {riak_pkg} --label role=pytests -i -v $(pwd)/test:/usr/src/test -v /var/run/docker.sock:/var/run/docker.sock"] 341 | ---- 342 | FROM alpine 343 | RUN apk add --no-cache py2-pip bash ca-certificates docker 344 | RUN pip install --upgrade pip pytest riak 345 | WORKDIR /usr/src/test 346 | CMD /bin/cat 347 | ---- 348 | 349 | Run the `py.test` tests found in the link:test/[test/] folder. 350 | 351 | .Run Tests 352 | [source,bash] 353 | [asciibuild,bash,container="Pytest Container"] 354 | ---- 355 | py.test -v 356 | ---- 357 | 358 | .Cleanup Test Container 359 | [source,bash] 360 | [asciibuild,bash] 361 | ---- 362 | # Don't fail the build if cleanup doesn't happen 363 | set +e 364 | 365 | # Remove Python resources 366 | for f in __pycache__ .cache *.pyc; do 367 | rm -Rf $(find test -name $f -print) || true 368 | done 369 | docker rm -f $(docker ps -aqf label=role=pytests) || true 370 | ---- 371 | endif::riak_client[] 372 | 373 | == Cleanup 374 | 375 | Clean up temporary and transitory files that get rebuilt each time this build is run. 376 | 377 | This step can be skipped by setting the attribute `skip_clean` when running the build. 378 | 379 | ifndef::skip_clean[] 380 | .Cleanup 381 | [source,bash] 382 | [asciibuild,bash] 383 | ---- 384 | # Don't fail the build if cleanup doesn't happen 385 | set +e 386 | 387 | # Remove the Dockerfile we generate 388 | rm -Rf Dockerfile 389 | # Remove the cluster and other containers we started for tests 390 | for r in cluster schemas; do 391 | docker rm -f $(docker ps -aqf label=role=$r) || true 392 | done 393 | ---- 394 | endif::[] 395 | 396 | == Publish 397 | 398 | Tag and publish the image if the attribute `publish` is set when running the build. 399 | 400 | * `publish`: {publish} 401 | 402 | ifdef::publish[] 403 | :docker_image_name: riak-{riak_flavor}:{os_family}-{riak_version} 404 | ifdef::docker_org[] 405 | :docker_image_tag: {docker_org}/{docker_image_name} 406 | endif::docker_org[] 407 | ifndef::docker_org[] 408 | :docker_image_tag: {docker_image_name} 409 | endif::docker_org[] 410 | 411 | .Tag Image 412 | [source,bash] 413 | [asciibuild,bash] 414 | ---- 415 | docker tag {{riak_tag}} {{docker_image_tag}} 416 | # Push specific version 417 | docker push {{docker_image_tag}} 418 | ---- 419 | 420 | ifdef::latest[] 421 | ifdef::docker_org[] 422 | :docker_latest_tag: {docker_org}/riak-{riak_flavor}:latest 423 | endif::docker_org[] 424 | ifndef::docker_org[] 425 | :docker_latest_tag: riak-{riak_flavor}:latest 426 | endif::docker_org[] 427 | 428 | .Tag Latest Image 429 | [source,bash] 430 | [asciibuild,bash] 431 | ---- 432 | # Push 'latest' tag 433 | docker tag {{riak_tag}} {{docker_latest_tag}} 434 | docker push {{docker_latest_tag}} 435 | ---- 436 | endif::latest[] 437 | endif::publish[] 438 | -------------------------------------------------------------------------------- /poststart.d/01-bootstrap-schemas.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$RIAK_FLAVOR" == "TS" ]; then 4 | # Create TS buckets 5 | echo "Looking for CREATE TABLE schemas in $SCHEMAS_DIR..." 6 | for f in $(find $SCHEMAS_DIR -name *.sql -print); do 7 | BUCKET_NAME=$(basename -s .sql $f) 8 | BUCKET_DEF=$(cat $f) 9 | $RIAK_ADMIN bucket-type create $BUCKET_NAME '{"props":{"table_def":"'$BUCKET_DEF'"}}' 10 | $RIAK_ADMIN bucket-type activate $BUCKET_NAME 11 | done 12 | fi 13 | -------------------------------------------------------------------------------- /poststart.d/02-bootstrap-datatypes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Create KV bucket types 4 | echo "Looking for datatypes in $SCHEMAS_DIR..." 5 | for f in $(find $SCHEMAS_DIR -name *.dt -print); do 6 | BUCKET_NAME=$(basename -s .dt $f) 7 | BUCKET_DT=$(cat $f) 8 | $RIAK_ADMIN bucket-type create $BUCKET_NAME "{\"props\":{\"datatype\":\"$BUCKET_DT\"}}" 9 | $RIAK_ADMIN bucket-type activate $BUCKET_NAME 10 | done 11 | -------------------------------------------------------------------------------- /poststart.d/99-join-cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Maybe join to a cluster 4 | if [[ -z "$($RIAK_ADMIN cluster status | egrep $COORDINATOR_NODE_HOST)" && "$COORDINATOR_NODE_HOST" != "$HOST" ]]; then 5 | # Not already in this cluster, so join 6 | echo "Connecting to cluster coordinator $COORDINATOR_NODE" 7 | curl -sSL $HOST:8098/admin/control/clusters/default/join/riak@$COORDINATOR_NODE_HOST 8 | fi 9 | -------------------------------------------------------------------------------- /prestart.d/00-update-riak-conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Add standard config items 4 | cat <>$RIAK_CONF 5 | nodename = riak@$HOST 6 | distributed_cookie = $CLUSTER_NAME 7 | listener.protobuf.internal = $HOST:$PB_PORT 8 | listener.http.internal = $HOST:$HTTP_PORT 9 | END 10 | 11 | # Maybe add user config items 12 | if [ -s $USER_CONF ]; then 13 | cat $USER_CONF >>$RIAK_CONF 14 | fi -------------------------------------------------------------------------------- /prestart.d/01-maybe-update-cluster-convergence.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RING_SIZE=$(awk -F'=' '/ring_size/{print $2}' $RIAK_CONF | sed 's/[ ]//') 4 | CLUSTER_CONVERGENCE=${CLUSTER_CONVERGENCE:-standard} 5 | 6 | if [[ "fast" == "$CLUSTER_CONVERGENCE" && ! -e $RIAK_ADVANCED_CONF ]]; then 7 | cat <$RIAK_ADVANCED_CONF 8 | [ 9 | {riak_core, [ 10 | {vnode_parallel_start, $RING_SIZE}, 11 | {forced_ownership_handoff, $RING_SIZE}, 12 | {handoff_concurrency, $RING_SIZE} 13 | ]} 14 | ]. 15 | END 16 | fi 17 | -------------------------------------------------------------------------------- /rel_to_pkg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | RIAK_HOME=${RIAK_HOME:-/usr/lib/riak} 6 | ETC_DIR=/etc/riak 7 | DATA_DIR=/var/lib/riak 8 | LOG_DIR=/var/log/riak 9 | 10 | # Make sure dirs exist 11 | for d in $DATA_DIR $LOG_DIR; do 12 | mkdir -p $d 13 | done 14 | 15 | # Use a global /etc dir 16 | ln -s $RIAK_HOME/etc $ETC_DIR 17 | 18 | # Patch config file to point to installed paths 19 | sed -i -r "s#platform_bin_dir = (.*)#platform_bin_dir = $RIAK_HOME/bin#g" $ETC_DIR/riak.conf 20 | sed -i -r "s#platform_data_dir = (.*)#platform_data_dir = $DATA_DIR#g" $ETC_DIR/riak.conf 21 | sed -i -r "s#platform_etc_dir = (.*)#platform_etc_dir = $RIAK_HOME/etc#g" $ETC_DIR/riak.conf 22 | sed -i -r "s#platform_lib_dir = (.*)#platform_lib_dir = $RIAK_HOME/lib#g" $ETC_DIR/riak.conf 23 | sed -i -r "s#platform_log_dir = (.*)#platform_log_dir = $LOG_DIR#g" $ETC_DIR/riak.conf 24 | -------------------------------------------------------------------------------- /riak-cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Cluster start script to bootstrap a Riak cluster. 4 | # 5 | set -ex 6 | 7 | if [[ -x /usr/sbin/riak ]]; then 8 | export RIAK=/usr/sbin/riak 9 | else 10 | export RIAK=$RIAK_HOME/bin/riak 11 | fi 12 | export RIAK_CONF=/etc/riak/riak.conf 13 | export USER_CONF=/etc/riak/user.conf 14 | export RIAK_ADVANCED_CONF=/etc/riak/advanced.config 15 | if [[ -x /usr/sbin/riak-admin ]]; then 16 | export RIAK_ADMIN=/usr/sbin/riak-admin 17 | else 18 | export RIAK_ADMIN=$RIAK_HOME/bin/riak-admin 19 | fi 20 | export SCHEMAS_DIR=/etc/riak/schemas/ 21 | 22 | # Set ports for PB and HTTP 23 | export PB_PORT=${PB_PORT:-8087} 24 | export HTTP_PORT=${HTTP_PORT:-8098} 25 | 26 | # Use ping to discover our HOSTNAME because it's easier and more reliable than other methods 27 | export HOST=$(ping -c1 $HOSTNAME | awk '/^PING/ {print $3}' | sed 's/[()]//g')||'127.0.0.1' 28 | 29 | # CLUSTER_NAME is used to name the nodes and is the value used in the distributed cookie 30 | export CLUSTER_NAME=${CLUSTER_NAME:-riak} 31 | 32 | # The COORDINATOR_NODE is the first node in a cluster to which other nodes will eventually join 33 | export COORDINATOR_NODE=${COORDINATOR_NODE:-$HOSTNAME} 34 | export COORDINATOR_NODE_HOST=$(ping -c1 $COORDINATOR_NODE | awk '/^PING/ {print $3}' | sed 's/[()]//g')||'127.0.0.1' 35 | 36 | # Run all prestart scripts 37 | PRESTART=$(find /etc/riak/prestart.d -name *.sh -print | sort) 38 | for s in $PRESTART; do 39 | . $s 40 | done 41 | 42 | # Start the node and wait until fully up 43 | $RIAK start 44 | $RIAK_ADMIN wait-for-service riak_kv 45 | 46 | # Run all poststart scripts 47 | POSTSTART=$(find /etc/riak/poststart.d -name *.sh -print | sort) 48 | for s in $POSTSTART; do 49 | . $s 50 | done 51 | 52 | # Trap SIGTERM and SIGINT and tail the log file indefinitely 53 | tail -n 1024 -f /var/log/riak/console.log & 54 | PID=$! 55 | trap "$RIAK stop; kill $PID" SIGTERM SIGINT 56 | wait $PID 57 | -------------------------------------------------------------------------------- /test/riak_docker/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/basho-labs/riak-docker/99e76df573cdb34377bdccbe4a0649ccafb2fd27/test/riak_docker/__init__.py -------------------------------------------------------------------------------- /test/riak_docker/test_fixtures.py: -------------------------------------------------------------------------------- 1 | import json 2 | import pytest 3 | import subprocess 4 | from riak import RiakClient, RiakNode 5 | 6 | @pytest.fixture 7 | def client(request): 8 | ids = subprocess.check_output(['docker', 'ps', '-qaf', 'label=role=cluster']).strip().split('\n') 9 | info = json.loads(subprocess.check_output(['docker', 'inspect'] + ids)) 10 | ips = [(i['NetworkSettings']['Networks']).values()[0]['IPAddress'] for i in info] 11 | return RiakClient(nodes=[RiakNode(host=ip) for ip in ips]) 12 | -------------------------------------------------------------------------------- /test/schemas/GeoCheckin.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE GeoCheckin 2 | ( 3 | id SINT64 NOT NULL, 4 | time TIMESTAMP NOT NULL, 5 | region VARCHAR NOT NULL, 6 | state VARCHAR NOT NULL, 7 | weather VARCHAR NOT NULL, 8 | temperature DOUBLE, 9 | PRIMARY KEY ( 10 | (id, QUANTUM(time, 15, 'm')), 11 | id, time 12 | ) 13 | ) 14 | -------------------------------------------------------------------------------- /test/schemas/test.dt: -------------------------------------------------------------------------------- 1 | counter 2 | -------------------------------------------------------------------------------- /test/test_riak_container.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from riak_docker.test_fixtures import client 3 | 4 | class TestRiakContainer: 5 | 6 | def test_can_ping_cluster(self, client): 7 | # Should be able to ping the nodes on internal IP 8 | assert client.ping() 9 | -------------------------------------------------------------------------------- /test/user.conf: -------------------------------------------------------------------------------- 1 | storage_backend = leveldb 2 | search = on -------------------------------------------------------------------------------- /vars.adoc: -------------------------------------------------------------------------------- 1 | :riak_home: /usr/lib/riak 2 | :riak_flavor: kv 3 | ifeval::["{riak_flavor}" == "kv"] 4 | :!riak_ts: 5 | :riak_pkg: riak 6 | endif::[] 7 | ifeval::["{riak_flavor}" == "ts"] 8 | :riak_ts: 9 | :riak_pkg: riak-ts 10 | endif::[] 11 | :riak_version: 2.2.0 12 | :riak_tag: riak-{riak_flavor}:{riak_version} 13 | :riak_explorer: 14 | :riak_explorer_version: 1.4.1 15 | :python_version: 2.7 16 | :python_lib_dir: /usr/lib/python{python_version}/dist-packages 17 | :riak_client: 18 | :riak_client_version: 2.7.0 19 | :protobuf_version: 2.6.1 20 | :os_family: ubuntu 21 | :os_version: 14.04 22 | ifeval::["{os_family}" == "ubuntu"] 23 | :ubuntu: 24 | :!debian: 25 | :!centos: 26 | :!osx: 27 | :pkg_format: deb 28 | ifeval::["{os_version}" == "14.04"] 29 | :trusty: 30 | ifeval::["{travis}" == "true"] 31 | :publish: 32 | endif::[] 33 | :os_flavor: trusty 34 | endif::[] 35 | endif::[] 36 | ifeval::["{os_family}" == "debian"] 37 | :!ubuntu: 38 | :debian: 39 | :!centos: 40 | :!osx: 41 | :pkg_format: deb 42 | ifeval::["{os_version}" == "8"] 43 | :jessie: 44 | :os_flavor: jessie 45 | endif::[] 46 | endif::[] 47 | ifeval::["{os_family}" == "centos"] 48 | :!ubuntu: 49 | :!debian: 50 | :centos: 51 | :!osx: 52 | :pkg_format: rpm 53 | :python_lib_dir: /usr/lib/python{python_version}/site-packages 54 | :riak_home: /usr/lib64/riak 55 | endif::[] 56 | ifeval::["{os_family}" == "osx"] 57 | :!ubuntu: 58 | :!debian: 59 | :!centos: 60 | :osx: 61 | :pkg_format: tgz 62 | ifeval::["{os_version}" == "10.11"] 63 | :el_capitan: 64 | :os_flavor: el_capitan 65 | endif::[] 66 | endif::[] 67 | :openjdk: 68 | :docker: 69 | ifeval::["{pkg_format}" == "tgz"] 70 | :riak_tgz_baseurl: https://basholabs.artifactoryonline.com/basholabs/build 71 | endif::[] 72 | :docker_org: basho 73 | ifeval::["{skip_publish}" == "true"] 74 | :publish!: 75 | :latest!: 76 | endif::[] 77 | --------------------------------------------------------------------------------