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

Attempt building debian, jar, and rpm packages using Dockerfiles #46

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
693cce9
Attempt building debian, jar, and rpm packages using Dockerfiles
joaquincasares Feb 1, 2017
02127cf
New changes to build debian packages and build locally, instead of fr…
joaquincasares Feb 2, 2017
29d6d73
git needed to pull bower packages. might also be needed for rhel and …
joaquincasares Feb 2, 2017
294ddbb
committed git package to wrong dockerfile
joaquincasares Feb 2, 2017
6cac1cd
Add instructions for retrieving the built jar. Make the docker/jar au…
joaquincasares Feb 2, 2017
2c087d6
Finish Cassandra-backed Docker example
joaquincasares Feb 3, 2017
bba357b
Documentation tweaks. Lock down docker images to tags.
joaquincasares Feb 3, 2017
16a33be
Add links to urls
joaquincasares Feb 3, 2017
2fc1b8e
Add down command
joaquincasares Feb 3, 2017
c17b8ca
Allow Docker to build rpm packages.
joaquincasares Feb 3, 2017
615cd81
Simpler run commands and inline comments
joaquincasares Feb 8, 2017
d11a122
Include jmxAuth key in sample yamls
joaquincasares Feb 8, 2017
ebf37c9
No longer use mounted volumes to simplify testing workflows
joaquincasares Feb 9, 2017
18f0df2
Remove the configuration to have Cassandra auto-restart
joaquincasares Feb 9, 2017
f03f1cb
Fix and simplify rpm building
joaquincasares Feb 9, 2017
398101e
Forgot to upload docker-entrypoint.sh
joaquincasares Feb 9, 2017
1c0406b
Simplify .deb creation
joaquincasares Feb 9, 2017
0d8f7c5
Cleaner jar building
joaquincasares Feb 9, 2017
7c026bf
Test docker-compose with new setup
joaquincasares Feb 10, 2017
6312bda
Confirm in-memory and cassandra-backend work as expected.
joaquincasares Feb 10, 2017
e571a21
Use 127.0.0.1 to contact cassandra by default
joaquincasares Feb 10, 2017
dc77d4c
Add ability to define Cassandra node from docker-compose.yml
joaquincasares Feb 10, 2017
e27ddb3
Phrasing
joaquincasares Feb 10, 2017
0ffaa7c
README updates
joaquincasares Feb 10, 2017
ab6b1fc
Don't bind to a specific jar version
joaquincasares Feb 10, 2017
9c057d9
Reorg Docker Readme and Dockerfiles
joaquincasares Feb 10, 2017
3d37f35
Remove debuild and consolidate build command
joaquincasares Feb 10, 2017
7e75c56
Documenaion cleanup and enhancement
joaquincasares Feb 10, 2017
4ebf674
Include production-ready container note
joaquincasares Feb 10, 2017
57c1030
Don't repeat the build process.
joaquincasares Feb 10, 2017
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
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# editor files
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip this file.

Not needed in #134 .

*.iml
*~
.idea/
.DS_Store

# docker files
docker/production-reaper/*.jar
docker/production-reaper/*.yaml
docker-compose.yml

# build paths
packages/
target/
*.deb
*.jar
*.rpm
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ bin/
.settings/
.project
build/
docker/production-reaper/*.yaml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed.

Other lines are implemented in #134 .

*.deb
*.jar
*.rpm
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Using mvn:
VERSION := $(shell mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -v '\[')
VERSION := `mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -v '\['`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in #134 .


# Using python:
#VERSION := $(shell python -c "import xml.etree.ElementTree as ET; print(ET.parse(open('pom.xml')).getroot().find('{http://maven.apache.org/POM/4.0.0}version').text)")
# VERSION := `python -c "import xml.etree.ElementTree as ET; print(ET.parse(open('pom.xml')).getroot().find('{http://maven.apache.org/POM/4.0.0}version').text)"`

package:
mvn package

prepare:
# needs to once at least once to pre-download dependencies
echo $(VERSION)

mkdir -p build/usr/share/cassandra-reaper
mkdir -p build/usr/local/bin
mkdir -p build/etc/init.d
Expand All @@ -26,7 +29,7 @@ rpm: prepare
rm -f reaper_*.rpm
fpm -s dir -t rpm -n reaper -v $(VERSION) --pre-install debian/preinstall.sh -C build .

all: package deb
all: package deb rpm

clean:
rm -rf reaper_*.deb reaper_*.rpm
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The current version supports running Apache Cassandra cluster repairs in a segme
opportunistically running multiple parallel repairs at the same time on different nodes
within the cluster. Basic repair scheduling functionality is also supported.

Reaper comes with a GUI, which if you're running in local mode can be at http://localhost:8080/webui/
Reaper comes with a GUI, which if you're running in local mode can be at http://localhost:8080/webui/index.html
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug has already been fixed.


Please see the [Issues](https://github.com/thelastpickle/cassandra-reaper/issues) section for more
information on planned development, and known issues.
Expand Down Expand Up @@ -63,8 +63,8 @@ use the provided CLI tool in *bin/spreaper* to call the service.

Run the tool with *-h* or *--help* option to see usage instructions.

Notice that you can also build a Debian package from this project by using *debuild*, for example:
`debuild -uc -us -b`
Notice that you can also build Debian and RPM package from this project by using *Make*, for example:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in #134 .

`make all`.


Configuration
Expand Down Expand Up @@ -346,6 +346,20 @@ After modifying the `resource/cassandra-reaper.yaml` config file, Reaper can be

```java -jar target/cassandra-reaper-X.X.X.jar server resource/cassandra-reaper.yaml```

Once started, the UI can be accessed through : `http://127.0.0.1:8080/webui/`
Once started, the UI can be accessed through : `http://127.0.0.1:8080/webui/index.html`

Reaper can also be accessed using the REST API exposed on port 8080, or using the command line tool `bin/spreaper`


Docker Support
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer relevant.

--------------

Docker support and documentation has been added to [./docker](./docker). The
README.md within that directory includes instructions for:

* Building Debian, RPM, and jar packages using Docker.
* Running an In-Memory Reaper deployment.
* Running a Cassandra-backed Reaper deployment.
* With a containerized Cassandra.
* With a Cassandra cluster located at a different IP address.
* Building a production-ready Docker container.
62 changes: 62 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: "2.1"

services:
reaper-in-memory:
build:
context: .
dockerfile: docker/reaper/Dockerfile
command: java -jar cassandra-reaper-0.4.0-SNAPSHOT.jar server cassandra-reaper/resource/cassandra-reaper-memory.yaml
ports:
# web ui port
- "8080:8080"
# admin ui port
- "8081:8081"

reaper-setup:
build:
context: .
dockerfile: docker/reaper-setup/Dockerfile
command: cassandra
links:
- cassandra:cassandra

reaper:
build:
context: .
dockerfile: docker/reaper/Dockerfile
command: cassandra
links:
- cassandra:cassandra
ports:
# web ui port
- "8080:8080"
# admin ui port
- "8081:8081"
restart: always

cassandra:
image: cassandra:3.0.10
env_file:
- docker/cassandra.env

# disable swap:
# https://github.com/docker/docker/issues/18894#issuecomment-167177866
# https://github.com/docker/compose/pull/3542
mem_limit: 4g
memswap_limit: 4g
mem_swappiness: 0

# expose these ports to any container with a link to `cassandra`
ports:
# intra-node communication
- "7000:7000"
# TLS intra-node communication
- "7001:7001"
# JMX
- "7199:7199"
# CQL
- "9042:9042"

# required in production environments:
# volumes:
# - ./data/cassandra_reaper:/var/lib/cassandra
135 changes: 135 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
Docker Support and Infrastructure for Reaper
============================================

The following software is required:

* [Docker](https://docs.docker.com/engine/installation/)
* [Docker Compose](https://docs.docker.com/compose/install/)

**Note**: The following commands are all assumed to be run from the root
repository directory.


Building Reaper Packages Using Docker
-------------------------------------

This command installs all dependencies needed to build the Debian, jar,
and RPM packages:

docker build --tag reaper-build-packages --file docker/build-packages/Dockerfile .

This command builds the packages into the host machine's `./packages` directory:

docker run -ti -v `pwd`/packages:/usr/src/app/packages reaper-build-packages


Running In-Memory Reaper Using Docker Compose
---------------------------------------------

These commands will build the jar file into the `./packages` directory:

docker build --tag reaper-build-packages --file docker/build-packages/Dockerfile .
docker run -ti -v `pwd`/packages:/usr/src/app/packages reaper-build-packages

This command will build the service images using the previously built jar file:

docker-compose build

This command will run Reaper in in-memory mode:

docker-compose up reaper-in-memory

The following URLs become available:

* Main Interface: [http://localhost:8080/webui/index.html](http://localhost:8080/webui/index.html)
* Operational Interface: [http://localhost:8081](http://localhost:8081)


Running Cassandra-backed Reaper using Docker Compose
----------------------------------------------------

After having built the images as described in the
`Running In-Memory Reaper Using Docker Compose` section, ensure there are no
running containers by using:

docker-compose down

Then, ensure there exists a running Cassandra container. This can be confirmed
once `Starting listening for CQL clients` appears in the log output:

docker-compose up cassandra

If not already initialized, make sure the Cassandra cluster has the correct
schema:

docker-compose run reaper-setup

Once Cassandra's schema has been initialized, run Reaper:

docker-compose up reaper

The following URLs become available:

* Main Interface: [http://localhost:8080/webui/index.html](http://localhost:8080/webui/index.html)
* Operational Interface: [http://localhost:8081](http://localhost:8081)

**Note**: Although Reaper will be using a Cassandra backend, the Dockerized
Cassandra container will be running with JMX accessible *only* from localhost.
Therefore, another Cassandra cluster with proper JMX settings will need to
be created in order for Reaper to monitor a cluster.

In order for JMX authentication to be set up correctly, the following settings
must be in effect on the Cassandra-side:

* cassandra.yaml
* `seeds`: must be set to the host's private IP address.
* `listen_address`: must be set to the host's private IP address.
* `rpc_address`: must be set to the host's private IP address.
* cassandra-env.sh
* `LOCAL_JMX` must resolve to something other than "yes".
* /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/management/jmxremote.access
* Should include a line in the format of: `<user> readwrite`.
* /etc/cassandra/jmxremote.password
* Should include a line in the format of: `<user> <password>`.
* Have `600` file permissions.
* Be owned by the `cassandra` user and group.



Running Cassandra-backed Reaper using Docker Compose and External Cassandra Cluster
-----------------------------------------------------------------------------------

If you wish to use an existing Cassandra backend on a separate machine, instead
of the provided containerized Cassandra, the directions are the same as the
above sections with a few differences:

* Update `./docker-compose.yml`'s `reaper` and `reaper-setup` services to use
`command`s that match an existing Cassandra node's IP address.
* Initialize the schema using: `docker-compose run reaper-setup`.
* Run Reaper using: `docker-compose up reaper`.

**Note**: Because Docker networking can use different settings and use of the
correct JMX settings are required for this sort of setup, using a Cassandra cluster not
located at `127.0.0.1`, or `localhost`, is ideal.


Shutting Down Docker Compose Containers
---------------------------------------

To shut everything down all containers that were started using `docker-compose`
command, run:

docker-compose down


Using a Docker Container in Production
--------------------------------------

To facilitate production environments where Docker is heavily in use, we've
provided a Dockerfile example for building an ideal production image. That file
and README can be found in [./production-reaper](./production-reaper).

There is a [ticket](https://github.com/thelastpickle/cassandra-reaper/issues/51)
to deploy new Docker images to Docker Hub on each release. Once this ticket has
been closed, the instructions should stay the same while the Dockerfile is
simpler and pre-built using Docker Hub's automated build system.
45 changes: 45 additions & 0 deletions docker/build-packages/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM ubuntu:16.04
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in #134 .


# use a common app path, copied from python-onbuild:latest
ENV WORKDIR /usr/src/app
RUN mkdir -p ${WORKDIR}
WORKDIR ${WORKDIR}

# install dependencies
RUN apt-get update \
&& apt-get install -y \
curl \
&& curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh \
&& bash nodesource_setup.sh \
&& apt-get update \
&& apt-get install -y \
build-essential \
git \
maven \
nodejs \
openjdk-8-jdk \
rpm \
ruby-dev \
&& mvn --version \
&& gem install fpm \
&& npm install -g bower

# cache maven dependencies, useful during Dockerfile testing
COPY pom.xml /tmp
COPY reaper_ui/*.json reaper_ui/*.js /tmp/reaper_ui/
WORKDIR /tmp
RUN mvn clean package \
&& mvn clean package -Pbuild-ui
WORKDIR ${WORKDIR}

# grab source
COPY . ${WORKDIR}/cassandra-reaper
WORKDIR ${WORKDIR}/cassandra-reaper

# target directory for final build
RUN mkdir ${WORKDIR}/packages
VOLUME ${WORKDIR}/packages

# Add entrypoint script
COPY docker/build-packages/docker-entrypoint.sh ${WORKDIR}
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]
17 changes: 17 additions & 0 deletions docker/build-packages/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in #134 .


set -x

# build jar
# build web UI
# build Debian and RPM packages
# copy built packages into a mounted volume
mvn clean package -Pbuild-ui \
&& make all \
&& cp *.deb *.rpm target/*.jar ${WORKDIR}/packages

# cd into the directory that contains the built packages
cd ${WORKDIR}/packages

# execute any provided command
$@
18 changes: 18 additions & 0 deletions docker/cassandra.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# leave blank to auto configure
CASSANDRA_LISTEN_ADDRESS
CASSANDRA_BROADCAST_ADDRESS
CASSANDRA_RPC_ADDRESS

# name of this Cassandra cluster
CASSANDRA_CLUSTER_NAME='reaper'

# leave as is, or manually configure
CASSANDRA_SEEDS
CASSANDRA_NUM_TOKENS=32

# snitch information
CASSANDRA_DC=us-east-1
CASSANDRA_RACK=rack1
CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch
18 changes: 18 additions & 0 deletions docker/production-reaper/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:16.04
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated for #76.


# use a common app path, copied from python-onbuild:latest
ENV WORKDIR /usr/src/app
RUN mkdir -p ${WORKDIR}
WORKDIR ${WORKDIR}

# install Java
RUN apt-get update \
&& apt-get install -y \
openjdk-8-jdk

# grab jar and configuration from the build directory
COPY ./*.jar ${WORKDIR}/
COPY cassandra-reaper*.yaml ${WORKDIR}/

# start the reaper process
CMD java -jar cassandra-reaper*.jar server cassandra-reaper*.yaml
Loading