From 5f62644cc351385127c828c556786864e6b1b0b0 Mon Sep 17 00:00:00 2001 From: Martin Joehren Date: Sun, 5 Oct 2014 12:31:15 +0200 Subject: [PATCH 1/6] added generator for different cassandra versions --- cassandra/2.0/Dockerfile | 42 +++++++++++++++++++++++ cassandra/2.0/build.sh | 3 ++ cassandra/2.0/src/datastax.repo | 6 ++++ cassandra/2.0/src/epel6.repo | 7 ++++ cassandra/2.0/src/start.sh | 42 +++++++++++++++++++++++ cassandra/2.0/src/supervisord.conf | 10 ++++++ cassandra/{ => 2.1}/Dockerfile | 2 +- cassandra/2.1/build.sh | 3 ++ cassandra/2.1/src/datastax.repo | 6 ++++ cassandra/2.1/src/epel6.repo | 7 ++++ cassandra/2.1/src/start.sh | 42 +++++++++++++++++++++++ cassandra/2.1/src/supervisord.conf | 10 ++++++ cassandra/README.md | 30 ++++++++++++++++ cassandra/generate | 55 ++++++++++++++++++++++++++++++ cassandra/templates/Dockerfile.j2 | 42 +++++++++++++++++++++++ cassandra/templates/build.j2 | 3 ++ 16 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 cassandra/2.0/Dockerfile create mode 100755 cassandra/2.0/build.sh create mode 100644 cassandra/2.0/src/datastax.repo create mode 100644 cassandra/2.0/src/epel6.repo create mode 100755 cassandra/2.0/src/start.sh create mode 100644 cassandra/2.0/src/supervisord.conf rename cassandra/{ => 2.1}/Dockerfile (99%) create mode 100755 cassandra/2.1/build.sh create mode 100644 cassandra/2.1/src/datastax.repo create mode 100644 cassandra/2.1/src/epel6.repo create mode 100755 cassandra/2.1/src/start.sh create mode 100644 cassandra/2.1/src/supervisord.conf create mode 100644 cassandra/README.md create mode 100755 cassandra/generate create mode 100644 cassandra/templates/Dockerfile.j2 create mode 100755 cassandra/templates/build.j2 diff --git a/cassandra/2.0/Dockerfile b/cassandra/2.0/Dockerfile new file mode 100644 index 0000000..60c5b92 --- /dev/null +++ b/cassandra/2.0/Dockerfile @@ -0,0 +1,42 @@ +# Cassandra +# +# VERSION 1.0 + +FROM tianon/centos:6.5 + +# Add source repositories +ADD src/epel6.repo /etc/yum.repos.d/epel6.repo +ADD src/datastax.repo /etc/yum.repos.d/datastax.repo + +# Install Java, Install packages (sshd + supervisord + monitoring tools + cassandra) +RUN yum install -y wget tar openssh-server openssh-clients supervisor dsc20 sysstat sudo which && \ + yum clean all && \ + wget --progress=dot:giga -O /tmp/jdk.rpm --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-linux-x64.rpm" && \ + rpm -ivh /tmp/jdk.rpm && rm /tmp/jdk.rpm && \ + alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000 + +# Configure SSH server +# Create OpsCenter account +RUN mkdir -p /var/run/sshd && chmod -rx /var/run/sshd && \ + ssh-keygen -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key && \ + sed -ri 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config && \ + sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config && \ + sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config && \ + useradd -m -G users,root -p $(openssl passwd -1 "opscenter") opscenter && \ + echo "%root ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +# Configure supervisord +ADD src/supervisord.conf /etc/supervisord.conf +RUN mkdir -p /var/log/supervisor + +# Deploy startup script +ADD src/start.sh /usr/local/bin/start + +# Necessary since cassandra is trying to override the system limitations +# See https://groups.google.com/forum/#!msg/docker-dev/8TM_jLGpRKU/dewIQhcs7oAJ +RUN rm -f /etc/security/limits.d/cassandra.conf + +EXPOSE 7199 7000 7001 9160 9042 +EXPOSE 22 8012 61621 +USER root +CMD start \ No newline at end of file diff --git a/cassandra/2.0/build.sh b/cassandra/2.0/build.sh new file mode 100755 index 0000000..c864a8b --- /dev/null +++ b/cassandra/2.0/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cd $(dirname $0) +docker build -t poklet/cassandra:2.0 . \ No newline at end of file diff --git a/cassandra/2.0/src/datastax.repo b/cassandra/2.0/src/datastax.repo new file mode 100644 index 0000000..4deb084 --- /dev/null +++ b/cassandra/2.0/src/datastax.repo @@ -0,0 +1,6 @@ +[datastax] +name = DataStax Repo for Apache Cassandra +baseurl = http://rpm.datastax.com/community +enabled = 1 +gpgcheck = 0 + diff --git a/cassandra/2.0/src/epel6.repo b/cassandra/2.0/src/epel6.repo new file mode 100644 index 0000000..d4f18e0 --- /dev/null +++ b/cassandra/2.0/src/epel6.repo @@ -0,0 +1,7 @@ +[epel] +name = Extra Packages for Enterprise Linux 6 - $basearch +baseurl = http://download.fedoraproject.org/pub/epel/6/$basearch +mirrorlist = https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch +failovermethod=priority +enabled=1 +gpgcheck=0 diff --git a/cassandra/2.0/src/start.sh b/cassandra/2.0/src/start.sh new file mode 100755 index 0000000..1ea9122 --- /dev/null +++ b/cassandra/2.0/src/start.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Accept listen_address +IP=${LISTEN_ADDRESS:-`hostname --ip-address`} + +# Accept seeds via docker run -e SEEDS=seed1,seed2,... +SEEDS=${SEEDS:-$IP} + +# Backwards compatibility with older scripts that just passed the seed in +if [ $# == 1 ]; then SEEDS="$1,$SEEDS"; fi + +#if this container was linked to any other cassandra nodes, use them as seeds as well. +if [[ `env | grep _PORT_9042_TCP_ADDR` ]]; then + SEEDS="$SEEDS,$(env | grep _PORT_9042_TCP_ADDR | sed 's/.*_PORT_9042_TCP_ADDR=//g' | sed -e :a -e N -e 's/\n/,/' -e ta)" +fi + +echo Configuring Cassandra to listen at $IP with seeds $SEEDS + +# Setup Cassandra +DEFAULT=${DEFAULT:-/etc/cassandra/default.conf} +CONFIG=/etc/cassandra/conf + +rm -rf $CONFIG && cp -r $DEFAULT $CONFIG +sed -i -e "s/^listen_address.*/listen_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/^rpc_address.*/rpc_address: 0.0.0.0/" $CONFIG/cassandra.yaml +sed -i -e "s/# broadcast_address.*/broadcast_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/# broadcast_rpc_address.*/broadcast_rpc_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/^commitlog_segment_size_in_mb.*/commitlog_segment_size_in_mb: 64/" $CONFIG/cassandra.yaml +sed -i -e "s/- seeds: \"127.0.0.1\"/- seeds: \"$SEEDS\"/" $CONFIG/cassandra.yaml +sed -i -e "s/# JVM_OPTS=\"$JVM_OPTS -Djava.rmi.server.hostname=\"/ JVM_OPTS=\"$JVM_OPTS -Djava.rmi.server.hostname=$IP\"/" $CONFIG/cassandra-env.sh + +if [[ $SNITCH ]]; then + sed -i -e "s/endpoint_snitch: SimpleSnitch/endpoint_snitch: $SNITCH/" $CONFIG/cassandra.yaml +fi +if [[ $DC && $RACK ]]; then + echo "dc=$DC" > $CONFIG/cassandra-rackdc.properties + echo "rack=$RACK" >> $CONFIG/cassandra-rackdc.properties +fi + +# Start process +echo Starting Cassandra on $IP... +/usr/bin/supervisord diff --git a/cassandra/2.0/src/supervisord.conf b/cassandra/2.0/src/supervisord.conf new file mode 100644 index 0000000..e86df0c --- /dev/null +++ b/cassandra/2.0/src/supervisord.conf @@ -0,0 +1,10 @@ +[supervisord] +nodaemon=true + +[program:sshd] +command=/usr/sbin/sshd -D +autorestart=true + +[program:cassandra] +user=cassandra +command=cassandra -f diff --git a/cassandra/Dockerfile b/cassandra/2.1/Dockerfile similarity index 99% rename from cassandra/Dockerfile rename to cassandra/2.1/Dockerfile index 5027a29..69efdf5 100644 --- a/cassandra/Dockerfile +++ b/cassandra/2.1/Dockerfile @@ -39,4 +39,4 @@ RUN rm -f /etc/security/limits.d/cassandra.conf EXPOSE 7199 7000 7001 9160 9042 EXPOSE 22 8012 61621 USER root -CMD start +CMD start \ No newline at end of file diff --git a/cassandra/2.1/build.sh b/cassandra/2.1/build.sh new file mode 100755 index 0000000..ec80577 --- /dev/null +++ b/cassandra/2.1/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cd $(dirname $0) +docker build -t poklet/cassandra:2.1 . \ No newline at end of file diff --git a/cassandra/2.1/src/datastax.repo b/cassandra/2.1/src/datastax.repo new file mode 100644 index 0000000..4deb084 --- /dev/null +++ b/cassandra/2.1/src/datastax.repo @@ -0,0 +1,6 @@ +[datastax] +name = DataStax Repo for Apache Cassandra +baseurl = http://rpm.datastax.com/community +enabled = 1 +gpgcheck = 0 + diff --git a/cassandra/2.1/src/epel6.repo b/cassandra/2.1/src/epel6.repo new file mode 100644 index 0000000..d4f18e0 --- /dev/null +++ b/cassandra/2.1/src/epel6.repo @@ -0,0 +1,7 @@ +[epel] +name = Extra Packages for Enterprise Linux 6 - $basearch +baseurl = http://download.fedoraproject.org/pub/epel/6/$basearch +mirrorlist = https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch +failovermethod=priority +enabled=1 +gpgcheck=0 diff --git a/cassandra/2.1/src/start.sh b/cassandra/2.1/src/start.sh new file mode 100755 index 0000000..1ea9122 --- /dev/null +++ b/cassandra/2.1/src/start.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Accept listen_address +IP=${LISTEN_ADDRESS:-`hostname --ip-address`} + +# Accept seeds via docker run -e SEEDS=seed1,seed2,... +SEEDS=${SEEDS:-$IP} + +# Backwards compatibility with older scripts that just passed the seed in +if [ $# == 1 ]; then SEEDS="$1,$SEEDS"; fi + +#if this container was linked to any other cassandra nodes, use them as seeds as well. +if [[ `env | grep _PORT_9042_TCP_ADDR` ]]; then + SEEDS="$SEEDS,$(env | grep _PORT_9042_TCP_ADDR | sed 's/.*_PORT_9042_TCP_ADDR=//g' | sed -e :a -e N -e 's/\n/,/' -e ta)" +fi + +echo Configuring Cassandra to listen at $IP with seeds $SEEDS + +# Setup Cassandra +DEFAULT=${DEFAULT:-/etc/cassandra/default.conf} +CONFIG=/etc/cassandra/conf + +rm -rf $CONFIG && cp -r $DEFAULT $CONFIG +sed -i -e "s/^listen_address.*/listen_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/^rpc_address.*/rpc_address: 0.0.0.0/" $CONFIG/cassandra.yaml +sed -i -e "s/# broadcast_address.*/broadcast_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/# broadcast_rpc_address.*/broadcast_rpc_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/^commitlog_segment_size_in_mb.*/commitlog_segment_size_in_mb: 64/" $CONFIG/cassandra.yaml +sed -i -e "s/- seeds: \"127.0.0.1\"/- seeds: \"$SEEDS\"/" $CONFIG/cassandra.yaml +sed -i -e "s/# JVM_OPTS=\"$JVM_OPTS -Djava.rmi.server.hostname=\"/ JVM_OPTS=\"$JVM_OPTS -Djava.rmi.server.hostname=$IP\"/" $CONFIG/cassandra-env.sh + +if [[ $SNITCH ]]; then + sed -i -e "s/endpoint_snitch: SimpleSnitch/endpoint_snitch: $SNITCH/" $CONFIG/cassandra.yaml +fi +if [[ $DC && $RACK ]]; then + echo "dc=$DC" > $CONFIG/cassandra-rackdc.properties + echo "rack=$RACK" >> $CONFIG/cassandra-rackdc.properties +fi + +# Start process +echo Starting Cassandra on $IP... +/usr/bin/supervisord diff --git a/cassandra/2.1/src/supervisord.conf b/cassandra/2.1/src/supervisord.conf new file mode 100644 index 0000000..e86df0c --- /dev/null +++ b/cassandra/2.1/src/supervisord.conf @@ -0,0 +1,10 @@ +[supervisord] +nodaemon=true + +[program:sshd] +command=/usr/sbin/sshd -D +autorestart=true + +[program:cassandra] +user=cassandra +command=cassandra -f diff --git a/cassandra/README.md b/cassandra/README.md new file mode 100644 index 0000000..b5cbe5b --- /dev/null +++ b/cassandra/README.md @@ -0,0 +1,30 @@ +Generate Dockerfile +=================== + +Generate Dockerfile and all additional files per cassandra version in own directory. Calling the build.sh script will build the image with cassandra version tag. Files from templates directory will be used to to replace certain variables. src directory will directly copied into the new version directory. + +###Generate Directory: + +Generate directory 2.1 with Dockerfile and build.sh script: + +```bash +./generate.py -v 2.1 +``` + +###Generate Directory and build image: + +```bash +./generate.py -v 2.1 -b +``` + +###List versions + +```bash +./generate.py -l +``` + +###Help + +```bash +./generate.py -h +``` diff --git a/cassandra/generate b/cassandra/generate new file mode 100755 index 0000000..82244fd --- /dev/null +++ b/cassandra/generate @@ -0,0 +1,55 @@ +#!/usr/bin/python + +from jinja2 import Environment, FileSystemLoader +import sys, argparse, os, shutil, stat +from subprocess import call + + +default_version = "2.1" + +version_to_packge = {"2.1" : "dsc21", + "2.0" : "dsc20"} + + +def main(argv): + parser = argparse.ArgumentParser() + parser.add_argument('-v', help='cassandra version to use', choices=version_to_packge, default=default_version) + parser.add_argument('-l', help='show available versions', action='store_true' ) + parser.add_argument('-b', help='build image at the end (calls docker build ...)', action='store_true', default=False) + + args = parser.parse_args() + if args.l: + print version_to_packge + sys.exit(0) + + abspath = os.path.abspath(__file__) + dname = os.path.dirname(abspath) + os.chdir(dname) + + version = args.v + cassandra_version_directory = version + package = version_to_packge.get(args.v, default_version) + + env = Environment(loader=FileSystemLoader('templates')) + dockerfile_template = env.get_template('Dockerfile.j2') + build_template = env.get_template('build.j2') + + print "Generating Dockerfile with cassandra version " + version +" based on package " + package + copy_and_overwrite(cassandra_version_directory) + + dockerfile_template.stream(cassandra_package=package).dump(cassandra_version_directory + '/Dockerfile') + build_template.stream(cassandra_tag=version).dump(cassandra_version_directory + '/build.sh') + + st = os.stat(cassandra_version_directory + '/build.sh') + os.chmod(cassandra_version_directory + '/build.sh', st.st_mode | stat.S_IEXEC) + + if args.b: + call([cassandra_version_directory + "/build.sh"]) + +def copy_and_overwrite(to_path): + if os.path.exists(to_path): + shutil.rmtree(to_path) + shutil.copytree("src", to_path + "/src") + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/cassandra/templates/Dockerfile.j2 b/cassandra/templates/Dockerfile.j2 new file mode 100644 index 0000000..9435a45 --- /dev/null +++ b/cassandra/templates/Dockerfile.j2 @@ -0,0 +1,42 @@ +# Cassandra +# +# VERSION 1.0 + +FROM tianon/centos:6.5 + +# Add source repositories +ADD src/epel6.repo /etc/yum.repos.d/epel6.repo +ADD src/datastax.repo /etc/yum.repos.d/datastax.repo + +# Install Java, Install packages (sshd + supervisord + monitoring tools + cassandra) +RUN yum install -y wget tar openssh-server openssh-clients supervisor {{cassandra_package}} sysstat sudo which && \ + yum clean all && \ + wget --progress=dot:giga -O /tmp/jdk.rpm --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-linux-x64.rpm" && \ + rpm -ivh /tmp/jdk.rpm && rm /tmp/jdk.rpm && \ + alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000 + +# Configure SSH server +# Create OpsCenter account +RUN mkdir -p /var/run/sshd && chmod -rx /var/run/sshd && \ + ssh-keygen -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key && \ + sed -ri 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config && \ + sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config && \ + sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config && \ + useradd -m -G users,root -p $(openssl passwd -1 "opscenter") opscenter && \ + echo "%root ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +# Configure supervisord +ADD src/supervisord.conf /etc/supervisord.conf +RUN mkdir -p /var/log/supervisor + +# Deploy startup script +ADD src/start.sh /usr/local/bin/start + +# Necessary since cassandra is trying to override the system limitations +# See https://groups.google.com/forum/#!msg/docker-dev/8TM_jLGpRKU/dewIQhcs7oAJ +RUN rm -f /etc/security/limits.d/cassandra.conf + +EXPOSE 7199 7000 7001 9160 9042 +EXPOSE 22 8012 61621 +USER root +CMD start diff --git a/cassandra/templates/build.j2 b/cassandra/templates/build.j2 new file mode 100755 index 0000000..5be3ca5 --- /dev/null +++ b/cassandra/templates/build.j2 @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cd $(dirname $0) +docker build -t poklet/cassandra:{{cassandra_tag}} . From f69c6db90f215b7f28c13e93f5c9f2a1ef5bf48e Mon Sep 17 00:00:00 2001 From: Martin Joehren Date: Sun, 5 Oct 2014 12:36:19 +0200 Subject: [PATCH 2/6] added python requirements --- cassandra/README.md | 6 ++++++ cassandra/requirements.txt | 1 + 2 files changed, 7 insertions(+) create mode 100644 cassandra/requirements.txt diff --git a/cassandra/README.md b/cassandra/README.md index b5cbe5b..8f62ff6 100644 --- a/cassandra/README.md +++ b/cassandra/README.md @@ -3,6 +3,12 @@ Generate Dockerfile Generate Dockerfile and all additional files per cassandra version in own directory. Calling the build.sh script will build the image with cassandra version tag. Files from templates directory will be used to to replace certain variables. src directory will directly copied into the new version directory. +###Install python requirements + +```bash +pip install -r requirements.txt +``` + ###Generate Directory: Generate directory 2.1 with Dockerfile and build.sh script: diff --git a/cassandra/requirements.txt b/cassandra/requirements.txt new file mode 100644 index 0000000..8ce973e --- /dev/null +++ b/cassandra/requirements.txt @@ -0,0 +1 @@ +Jinja2 From 57a6073ab2031af074e1d4287b6ec55b098dd865 Mon Sep 17 00:00:00 2001 From: Martin Joehren Date: Sun, 5 Oct 2014 12:59:16 +0200 Subject: [PATCH 3/6] added latest --- cassandra/generate | 13 ++++----- cassandra/latest/Dockerfile | 42 +++++++++++++++++++++++++++ cassandra/latest/build.sh | 3 ++ cassandra/latest/src/datastax.repo | 6 ++++ cassandra/latest/src/epel6.repo | 7 +++++ cassandra/latest/src/start.sh | 42 +++++++++++++++++++++++++++ cassandra/latest/src/supervisord.conf | 10 +++++++ 7 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 cassandra/latest/Dockerfile create mode 100755 cassandra/latest/build.sh create mode 100644 cassandra/latest/src/datastax.repo create mode 100644 cassandra/latest/src/epel6.repo create mode 100755 cassandra/latest/src/start.sh create mode 100644 cassandra/latest/src/supervisord.conf diff --git a/cassandra/generate b/cassandra/generate index 82244fd..9a0fbe6 100755 --- a/cassandra/generate +++ b/cassandra/generate @@ -4,22 +4,21 @@ from jinja2 import Environment, FileSystemLoader import sys, argparse, os, shutil, stat from subprocess import call - -default_version = "2.1" - -version_to_packge = {"2.1" : "dsc21", +version_to_package = { + "latest" : "dsc21", + "2.1" : "dsc21", "2.0" : "dsc20"} def main(argv): parser = argparse.ArgumentParser() - parser.add_argument('-v', help='cassandra version to use', choices=version_to_packge, default=default_version) + parser.add_argument('-v', help='cassandra version to use', choices=version_to_package, default="latest") parser.add_argument('-l', help='show available versions', action='store_true' ) parser.add_argument('-b', help='build image at the end (calls docker build ...)', action='store_true', default=False) args = parser.parse_args() if args.l: - print version_to_packge + print version_to_package sys.exit(0) abspath = os.path.abspath(__file__) @@ -28,7 +27,7 @@ def main(argv): version = args.v cassandra_version_directory = version - package = version_to_packge.get(args.v, default_version) + package = version_to_package.get(args.v, "latest") env = Environment(loader=FileSystemLoader('templates')) dockerfile_template = env.get_template('Dockerfile.j2') diff --git a/cassandra/latest/Dockerfile b/cassandra/latest/Dockerfile new file mode 100644 index 0000000..69efdf5 --- /dev/null +++ b/cassandra/latest/Dockerfile @@ -0,0 +1,42 @@ +# Cassandra +# +# VERSION 1.0 + +FROM tianon/centos:6.5 + +# Add source repositories +ADD src/epel6.repo /etc/yum.repos.d/epel6.repo +ADD src/datastax.repo /etc/yum.repos.d/datastax.repo + +# Install Java, Install packages (sshd + supervisord + monitoring tools + cassandra) +RUN yum install -y wget tar openssh-server openssh-clients supervisor dsc21 sysstat sudo which && \ + yum clean all && \ + wget --progress=dot:giga -O /tmp/jdk.rpm --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-linux-x64.rpm" && \ + rpm -ivh /tmp/jdk.rpm && rm /tmp/jdk.rpm && \ + alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000 + +# Configure SSH server +# Create OpsCenter account +RUN mkdir -p /var/run/sshd && chmod -rx /var/run/sshd && \ + ssh-keygen -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key && \ + sed -ri 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config && \ + sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config && \ + sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config && \ + useradd -m -G users,root -p $(openssl passwd -1 "opscenter") opscenter && \ + echo "%root ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +# Configure supervisord +ADD src/supervisord.conf /etc/supervisord.conf +RUN mkdir -p /var/log/supervisor + +# Deploy startup script +ADD src/start.sh /usr/local/bin/start + +# Necessary since cassandra is trying to override the system limitations +# See https://groups.google.com/forum/#!msg/docker-dev/8TM_jLGpRKU/dewIQhcs7oAJ +RUN rm -f /etc/security/limits.d/cassandra.conf + +EXPOSE 7199 7000 7001 9160 9042 +EXPOSE 22 8012 61621 +USER root +CMD start \ No newline at end of file diff --git a/cassandra/latest/build.sh b/cassandra/latest/build.sh new file mode 100755 index 0000000..70d60d4 --- /dev/null +++ b/cassandra/latest/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cd $(dirname $0) +docker build -t poklet/cassandra:latest . \ No newline at end of file diff --git a/cassandra/latest/src/datastax.repo b/cassandra/latest/src/datastax.repo new file mode 100644 index 0000000..4deb084 --- /dev/null +++ b/cassandra/latest/src/datastax.repo @@ -0,0 +1,6 @@ +[datastax] +name = DataStax Repo for Apache Cassandra +baseurl = http://rpm.datastax.com/community +enabled = 1 +gpgcheck = 0 + diff --git a/cassandra/latest/src/epel6.repo b/cassandra/latest/src/epel6.repo new file mode 100644 index 0000000..d4f18e0 --- /dev/null +++ b/cassandra/latest/src/epel6.repo @@ -0,0 +1,7 @@ +[epel] +name = Extra Packages for Enterprise Linux 6 - $basearch +baseurl = http://download.fedoraproject.org/pub/epel/6/$basearch +mirrorlist = https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch +failovermethod=priority +enabled=1 +gpgcheck=0 diff --git a/cassandra/latest/src/start.sh b/cassandra/latest/src/start.sh new file mode 100755 index 0000000..1ea9122 --- /dev/null +++ b/cassandra/latest/src/start.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Accept listen_address +IP=${LISTEN_ADDRESS:-`hostname --ip-address`} + +# Accept seeds via docker run -e SEEDS=seed1,seed2,... +SEEDS=${SEEDS:-$IP} + +# Backwards compatibility with older scripts that just passed the seed in +if [ $# == 1 ]; then SEEDS="$1,$SEEDS"; fi + +#if this container was linked to any other cassandra nodes, use them as seeds as well. +if [[ `env | grep _PORT_9042_TCP_ADDR` ]]; then + SEEDS="$SEEDS,$(env | grep _PORT_9042_TCP_ADDR | sed 's/.*_PORT_9042_TCP_ADDR=//g' | sed -e :a -e N -e 's/\n/,/' -e ta)" +fi + +echo Configuring Cassandra to listen at $IP with seeds $SEEDS + +# Setup Cassandra +DEFAULT=${DEFAULT:-/etc/cassandra/default.conf} +CONFIG=/etc/cassandra/conf + +rm -rf $CONFIG && cp -r $DEFAULT $CONFIG +sed -i -e "s/^listen_address.*/listen_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/^rpc_address.*/rpc_address: 0.0.0.0/" $CONFIG/cassandra.yaml +sed -i -e "s/# broadcast_address.*/broadcast_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/# broadcast_rpc_address.*/broadcast_rpc_address: $IP/" $CONFIG/cassandra.yaml +sed -i -e "s/^commitlog_segment_size_in_mb.*/commitlog_segment_size_in_mb: 64/" $CONFIG/cassandra.yaml +sed -i -e "s/- seeds: \"127.0.0.1\"/- seeds: \"$SEEDS\"/" $CONFIG/cassandra.yaml +sed -i -e "s/# JVM_OPTS=\"$JVM_OPTS -Djava.rmi.server.hostname=\"/ JVM_OPTS=\"$JVM_OPTS -Djava.rmi.server.hostname=$IP\"/" $CONFIG/cassandra-env.sh + +if [[ $SNITCH ]]; then + sed -i -e "s/endpoint_snitch: SimpleSnitch/endpoint_snitch: $SNITCH/" $CONFIG/cassandra.yaml +fi +if [[ $DC && $RACK ]]; then + echo "dc=$DC" > $CONFIG/cassandra-rackdc.properties + echo "rack=$RACK" >> $CONFIG/cassandra-rackdc.properties +fi + +# Start process +echo Starting Cassandra on $IP... +/usr/bin/supervisord diff --git a/cassandra/latest/src/supervisord.conf b/cassandra/latest/src/supervisord.conf new file mode 100644 index 0000000..e86df0c --- /dev/null +++ b/cassandra/latest/src/supervisord.conf @@ -0,0 +1,10 @@ +[supervisord] +nodaemon=true + +[program:sshd] +command=/usr/sbin/sshd -D +autorestart=true + +[program:cassandra] +user=cassandra +command=cassandra -f From ebee763aa68c4cea1dc2c39beb56ea920d848511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=B6hren?= Date: Sun, 5 Oct 2014 13:15:42 +0200 Subject: [PATCH 4/6] Delete build.sh --- cassandra/build.sh | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 cassandra/build.sh diff --git a/cassandra/build.sh b/cassandra/build.sh deleted file mode 100755 index 6e7464f..0000000 --- a/cassandra/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -cd $(dirname $0) -docker build -t poklet/cassandra . From b6939244ca52f7082d0af9d7ab701226579a35c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=B6hren?= Date: Sun, 5 Oct 2014 13:23:55 +0200 Subject: [PATCH 5/6] Update README.md --- cassandra/README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cassandra/README.md b/cassandra/README.md index 8f62ff6..4ced6f9 100644 --- a/cassandra/README.md +++ b/cassandra/README.md @@ -1,7 +1,11 @@ -Generate Dockerfile -=================== +Cassandra Docker Images +======================== +You can find all neccessary files to build a certain docker image for a cassandra version in the directory with the version name. -Generate Dockerfile and all additional files per cassandra version in own directory. Calling the build.sh script will build the image with cassandra version tag. Files from templates directory will be used to to replace certain variables. src directory will directly copied into the new version directory. +##Generate Dockerfile in version directory for given version + +The file *generate* generates a Dockerfile and all additional files per cassandra version in its own directory. Calling the build.sh script in this directory will build the image with cassandra version tag. Files from templates directory will be used to replace certain variables. src directory will directly be copied into the new version directory. +New versions can be added in file *generator* in the dictionary 'version_to_package' by adding a pair, e.g. "2.1": "dsc21". ###Install python requirements @@ -9,7 +13,9 @@ Generate Dockerfile and all additional files per cassandra version in own direct pip install -r requirements.txt ``` -###Generate Directory: +###Examples: + +####Generate Directory: Generate directory 2.1 with Dockerfile and build.sh script: @@ -17,20 +23,21 @@ Generate directory 2.1 with Dockerfile and build.sh script: ./generate.py -v 2.1 ``` -###Generate Directory and build image: +####Generate Directory and build image: ```bash ./generate.py -v 2.1 -b ``` -###List versions +####List versions ```bash ./generate.py -l ``` -###Help +####Help ```bash ./generate.py -h ``` + From 78f0397fc0382c100fc2d57d54ff72df21d66de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=B6hren?= Date: Sun, 5 Oct 2014 13:26:31 +0200 Subject: [PATCH 6/6] Update README.md --- cassandra/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cassandra/README.md b/cassandra/README.md index 4ced6f9..568da88 100644 --- a/cassandra/README.md +++ b/cassandra/README.md @@ -20,24 +20,24 @@ pip install -r requirements.txt Generate directory 2.1 with Dockerfile and build.sh script: ```bash -./generate.py -v 2.1 +./generate -v 2.1 ``` ####Generate Directory and build image: ```bash -./generate.py -v 2.1 -b +./generate -v 2.1 -b ``` ####List versions ```bash -./generate.py -l +./generate -l ``` ####Help ```bash -./generate.py -h +./generate -h ```