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

Adding support to build cassandra-reaper docker images #76

Merged
merged 3 commits into from
May 3, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ To rebuild both the UI and Reaper :

```mvn clean package -Pbuild-ui```

To build the docker image :

```mvn clean package docker:build```

### Running Reaper

Expand Down
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm so glad you got this figured out! I couldn't, for the life of me, get this plugin to work correctly! :)

<version>0.4.13</version>
<configuration>
<imageName>cassandra-reaper</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<buildArgs>
<SHADED_JAR>cassandra-reaper-${project.version}.jar</SHADED_JAR>
</buildArgs>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>cassandra-reaper-${project.version}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Expand Down
61 changes: 61 additions & 0 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM openjdk:8-jre-alpine

ARG SHADED_JAR

ENV REAPER_SEGMENT_COUNT=200 \
REAPER_REPAIR_PARALELLISM=DATACENTER_AWARE \
REAPER_REPAIR_INTENSITY=0.9 \
REAPER_SCHEDULE_DAYS_BETWEEN=7 \
REAPER_REPAIR_RUN_THREADS=15 \
REAPER_HANING_REPAIR_TIMEOUT_MINS=30 \
REAPER_STORAGE_TYPE=memory \
REAPER_ENABLE_CORS=true \
REAPER_INCREMENTAL_REPAIR=false \
REAPER_ALLOW_UNREACHABLE_NODES=false \
REAPER_ENABLE_DYNAMIC_SEEDS=true \
REAPER_AUTO_SCHEDULE_ENABLED=false \
REAPER_AUTO_SCHEDULE_INITIAL_DELAY_PERIOD=PT15S \
REAPER_AUTO_SCHEDULE_PERIOD_BETWEEN_POLLS=PT10M \
REAPER_AUTO_SCHEDULE_TIME_BETWEEN_FIRST_SCHEDULE=PT5M \
REAPER_AUTO_SCHEDULE_TIME_BETWEEN_FIRST_SCHEDULE=PT6H \
REAPER_AUTO_SCHEDULE_EXCLUDED_KEYSPACES="[]" \
REAPER_JMX_PORTS="{}" \
REAPER_LOGGING_ROOT_LEVEL=INFO \
REAPER_LOGGERS="{}" \
REAPER_LOGGING_FORMAT='"%-6level [%d] [%t] %logger{5} - %msg %n"' \
REAPER_APP_PORT=8080 \
REAPER_APP_BIND_HOST="0.0.0.0" \
REAPER_ADMIN_PORT=8081 \
REAPER_ADMIN_BIND_HOST="0.0.0.0" \
REAPER_CASS_CLUSTER_NAME="clutername" \
REAPER_CASS_CONTACT_POINTS="[]" \
REAPER_CASS_KEYSPACE="cassandra-reaper" \
REAPER_CASS_AUTH_ENABLED="false" \
REAPER_CASS_AUTH_USERNAME="cassandra" \
REAPER_CASS_AUTH_PASSWORD="cassandra" \
REAPER_DB_DRIVER_CLASS="org.h2.Driver" \
REAPER_DB_URL="jdbc:h2:/var/lib/cassandra-reaper/db;MODE=PostgreSQL" \
DB_REAPER_DB_USERNAME="" \
DB_REAPER_DB_PASSWORD="" \
Copy link
Contributor

Choose a reason for hiding this comment

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

These two envars were left as DB_REAPER, while append-persistence.sh was correctly updated.

JAVA_OPTS=""

ADD cassandra-reaper.yml /etc/cassandra-reaper.yml
ADD entrypoint.sh /usr/local/bin/entrypoint.sh
ADD append-persistence.sh /usr/local/bin/append-persistence.sh
RUN addgroup -S reaper && \
adduser -S reaper reaper && \
apk add --no-cache 'su-exec>=0.2' && \
mkdir -p /var/lib/cassandra-reaper && \
chown reaper:reaper /etc/cassandra-reaper.yml && \
chown reaper:reaper /var/lib/cassandra-reaper && \
chown reaper:reaper /usr/local/bin/entrypoint.sh && \
chown reaper:reaper /usr/local/bin/append-persistence.sh && \
Copy link
Contributor

Choose a reason for hiding this comment

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

We could combine the above chown commands.

chmod u+x /usr/local/bin/entrypoint.sh && \
chmod u+x /usr/local/bin/append-persistence.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

We could combine the above chmod commands.


VOLUME /var/lib/cassandra-reaper

ADD ${SHADED_JAR} /usr/local/lib/cassandra-reaper.jar

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["cassandra-reaper"]
30 changes: 30 additions & 0 deletions src/main/docker/append-persistence.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

case ${REAPER_STORAGE_TYPE} in
"cassandra")
cat <<EOT >> /etc/cassandra-reaper.yml
cassandra:
clusterName: ${REAPER_CASS_CLUSTER_NAME}
contactPoints: ${REAPER_CASS_CONTACT_POINTS}
keyspace: ${REAPER_CASS_KEYSPACE}
EOT

if [ "true" = "${REAPER_CASS_AUTH_ENABLED}" ]; then
cat <<EOT >> /etc/cassandra-reaper.yml
authProvider:
type: plainText
username: ${REAPER_CASS_AUTH_USERNAME}
password: ${REAPER_CASS_AUTH_PASSWORD}
EOT
fi
;;
"database")
cat <<EOT >> /etc/cassandra-reaper.yml
database:
driverClass: ${REAPER_DB_DRIVER_CLASS}
url: ${REAPER_DB_URL}
user: ${REAPER_DB_USERNAME}
password: ${REAPER_DB_PASSWORD}
EOT

esac
43 changes: 43 additions & 0 deletions src/main/docker/cassandra-reaper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

segmentCount: ${REAPER_SEGMENT_COUNT}
repairParallelism: ${REAPER_REPAIR_PARALELLISM}
repairIntensity: ${REAPER_REPAIR_INTENSITY}
scheduleDaysBetween: ${REAPER_SCHEDULE_DAYS_BETWEEN}
repairRunThreadCount: ${REAPER_REPAIR_RUN_THREADS}
hangingRepairTimeoutMins: ${REAPER_HANING_REPAIR_TIMEOUT_MINS}
storageType: ${REAPER_STORAGE_TYPE}
enableCrossOrigin: ${REAPER_ENABLE_CORS}
incrementalRepair: ${REAPER_INCREMENTAL_REPAIR}
allowUnreachableNodes: ${REAPER_ALLOW_UNREACHABLE_NODES}
enableDynamicSeedList: ${REAPER_ENABLE_DYNAMIC_SEEDS}

autoScheduling:
enabled: ${REAPER_AUTO_SCHEDULE_ENABLED}
initialDelayPeriod: ${REAPER_AUTO_SCHEDULE_INITIAL_DELAY_PERIOD}
periodBetweenPolls: ${REAPER_AUTO_SCHEDULE_PERIOD_BETWEEN_POLLS}
timeBeforeFirstSchedule: ${REAPER_AUTO_SCHEDULE_TIME_BETWEEN_FIRST_SCHEDULE}
scheduleSpreadPeriod: ${REAPER_AUTO_SCHEDULE_TIME_BETWEEN_FIRST_SCHEDULE}
excludedKeyspaces: ${REAPER_AUTO_SCHEDULE_EXCLUDED_KEYSPACES}

jmxPorts: ${REAPER_JMX_PORTS}

logging:
level: ${REAPER_LOGGING_ROOT_LEVEL}
loggers: ${REAPER_LOGGERS}
appenders:
- type: console
logFormat: ${REAPER_LOGGING_FORMAT}

server:
type: default
applicationConnectors:
- type: http
port: ${REAPER_APP_PORT}
bindHost: ${REAPER_APP_BIND_HOST}
adminConnectors:
- type: http
port: ${REAPER_ADMIN_PORT}
bindHost: ${REAPER_ADMIN_BIND_HOST}
requestLog:
appenders: []

9 changes: 9 additions & 0 deletions src/main/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if [ "$1" = 'cassandra-reaper' ]; then
su-exec reaper /usr/local/bin/append-persistence.sh
exec su-exec reaper java -jar ${JAVA_OPTS} \
/usr/local/lib/cassandra-reaper.jar server /etc/cassandra-reaper.yml
fi

exec "$@"
7 changes: 7 additions & 0 deletions src/main/java/com/spotify/reaper/ReaperApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;

import io.dropwizard.configuration.EnvironmentVariableSubstitutor;
import io.dropwizard.configuration.SubstitutingSourceProvider;
import org.apache.cassandra.repair.RepairParallelism;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.flywaydb.core.Flyway;
Expand Down Expand Up @@ -97,6 +99,11 @@ public String getName() {
public void initialize(Bootstrap<ReaperApplicationConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets/", "/webui", "index.html"));
bootstrap.getObjectMapper().registerModule(new JavaTimeModule());

// enable using environment variables in yml files
final SubstitutingSourceProvider envSourceProvider = new SubstitutingSourceProvider(
bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false));
bootstrap.setConfigurationSourceProvider(envSourceProvider);
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice configuration management extension!

}

@Override
Expand Down