Skip to content
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

Added generator for different cassandra versions #22

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cassandra/2.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions cassandra/2.0/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cd $(dirname $0)
docker build -t poklet/cassandra:2.0 .
6 changes: 6 additions & 0 deletions cassandra/2.0/src/datastax.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

7 changes: 7 additions & 0 deletions cassandra/2.0/src/epel6.repo
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions cassandra/2.0/src/start.sh
Original file line number Diff line number Diff line change
@@ -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=<public name>\"/ 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
10 changes: 10 additions & 0 deletions cassandra/2.0/src/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D
autorestart=true

[program:cassandra]
user=cassandra
command=cassandra -f
2 changes: 1 addition & 1 deletion cassandra/Dockerfile → cassandra/2.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions cassandra/2.1/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cd $(dirname $0)
docker build -t poklet/cassandra:2.1 .
6 changes: 6 additions & 0 deletions cassandra/2.1/src/datastax.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

7 changes: 7 additions & 0 deletions cassandra/2.1/src/epel6.repo
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions cassandra/2.1/src/start.sh
Original file line number Diff line number Diff line change
@@ -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=<public name>\"/ 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
10 changes: 10 additions & 0 deletions cassandra/2.1/src/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D
autorestart=true

[program:cassandra]
user=cassandra
command=cassandra -f
43 changes: 43 additions & 0 deletions cassandra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 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 <version_name: package_name> pair, e.g. "2.1": "dsc21".

###Install python requirements

```bash
pip install -r requirements.txt
```

###Examples:

####Generate Directory:

Generate directory 2.1 with Dockerfile and build.sh script:

```bash
./generate -v 2.1
```

####Generate Directory and build image:

```bash
./generate -v 2.1 -b
```

####List versions

```bash
./generate -l
```

####Help

```bash
./generate -h
```

3 changes: 0 additions & 3 deletions cassandra/build.sh

This file was deleted.

54 changes: 54 additions & 0 deletions cassandra/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python

from jinja2 import Environment, FileSystemLoader
import sys, argparse, os, shutil, stat
from subprocess import call

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_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_package
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_package.get(args.v, "latest")

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:])
42 changes: 42 additions & 0 deletions cassandra/latest/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions cassandra/latest/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cd $(dirname $0)
docker build -t poklet/cassandra:latest .
6 changes: 6 additions & 0 deletions cassandra/latest/src/datastax.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

7 changes: 7 additions & 0 deletions cassandra/latest/src/epel6.repo
Original file line number Diff line number Diff line change
@@ -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
Loading