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 1 commit
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
54 changes: 54 additions & 0 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM openjdk:8-jre-alpine

ARG SHADED_JAR

ENV DW_REAPER_SEGMENT_COUNT=200 \
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the DW_ prefix?

Copy link
Author

Choose a reason for hiding this comment

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

So, that was just for "Dropwizard" but since the application is effectively REAPER we could just drop the prefix as that is likely clearer.

DW_REAPER_REPAIR_PARALELLISM=DATACENTER_AWARE \
DW_REAPER_REPAIR_INTENSITY=0.9 \
DW_REAPER_SCHEDULE_DAYS_BETWEEN=7 \
DW_REAPER_REPAIR_RUN_THREADS=15 \
DW_REAPER_HANING_REPAIR_TIMEOUT_MINS=30 \
DW_REAPER_STORAGE_TYPE=memory \
DW_REAPER_ENABLE_CORS=true \
DW_REAPER_INCREMENTAL_REPAIR=false \
DW_REAPER_ALLOW_UNREACHABLE_NODES=false \
DW_REAPER_ENABLE_DYNAMIC_SEEDS=true \
DW_REAPER_AUTO_SCHEDULE_ENABLED=false \
DW_REAPER_AUTO_SCHEDULE_INITIAL_DELAY_PERIOD=PT15S \
DW_REAPER_AUTO_SCHEDULE_PERIOD_BETWEEN_POLLS=PT10M \
DW_REAPER_AUTO_SCHEDULE_TIME_BETWEEN_FIRST_SCHEDULE=PT5M \
DW_REAPER_AUTO_SCHEDULE_TIME_BETWEEN_FIRST_SCHEDULE=PT6H \
DW_REAPER_AUTO_SCHEDULE_EXCLUDED_KEYSPACES="[]" \
DW_REAPER_JMX_PORTS="{}" \
DW_REAPER_LOGGING_ROOT_LEVEL=INFO \
DW_REAPER_LOGGERS="{}" \
DW_REAPER_LOGGING_FORMAT='"%-6level [%d] [%t] %logger{5} - %msg %n"' \
DW_REAPER_APP_PORT=8080 \
DW_REAPER_APP_BIND_HOST="0.0.0.0" \
DW_REAPER_ADMIN_PORT=8081 \
DW_REAPER_ADMIN_BIND_HOST="0.0.0.0" \
DW_REAPER_CASS_CLUSTER_NAME="clutername" \
DW_REAPER_CASS_CONTACT_POINTS="[]" \
DW_REAPER_CASS_KEYSPACE="cassandra-reaper" \
DW_REAPER_CASS_AUTH_ENABLED="false" \
DW_REAPER_CASS_AUTH_USERNAME="cassandra" \
DW_REAPER_CASS_AUTH_PASSWORD="cassandra" \
DW_REAPER_DB_DRIVER_CLASS="org.h2.Driver" \
DW_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 /root/cassandra-reaper.yml
ADD entrypoint.sh /root/entrypoint.sh
ADD append-persistence.sh /root/append-persistence.sh
RUN mkdir -p /var/lib/cassandra-reaper/data && \
chmod u+x /root/entrypoint.sh && \
chmod u+x /root/append-persistence.sh

VOLUME /var/lib/cassandra-reaper/data

ADD ${SHADED_JAR} /root/cassandra-reaper.jar

ENTRYPOINT ["/root/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 ${DW_REAPER_STORAGE_TYPE} in
"cassandra")
cat <<EOT >> /root/cassandra-reaper.yml
cassandra:
clusterName: ${DW_REAPER_CASS_CLUSTER_NAME}
contactPoints: ${DW_REAPER_CASS_CONTACT_POINTS}
keyspace: ${DW_REAPER_CASS_KEYSPACE}
EOT

if [ "true" = "${DW_REAPER_CASS_AUTH_ENABLED}" ]; then
cat <<EOT >> /root/cassandra-reaper.yml
authProvider:
type: plainText
username: ${DW_REAPER_CASS_AUTH_USERNAME}
password: ${DW_REAPER_CASS_AUTH_PASSWORD}
EOT
fi
;;
"database")
cat <<EOT >> /root/cassandra-reaper.yml
database:
driverClass: ${DW_REAPER_DB_DRIVER_CLASS}
url: ${DW_REAPER_DB_URL}
user: ${DW_REAPER_DB_USERNAME}
password: ${DW_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: ${DW_REAPER_SEGMENT_COUNT}
repairParallelism: ${DW_REAPER_REPAIR_PARALELLISM}
repairIntensity: ${DW_REAPER_REPAIR_INTENSITY}
scheduleDaysBetween: ${DW_REAPER_SCHEDULE_DAYS_BETWEEN}
repairRunThreadCount: ${DW_REAPER_REPAIR_RUN_THREADS}
hangingRepairTimeoutMins: ${DW_REAPER_HANING_REPAIR_TIMEOUT_MINS}
storageType: ${DW_REAPER_STORAGE_TYPE}
enableCrossOrigin: ${DW_REAPER_ENABLE_CORS}
incrementalRepair: ${DW_REAPER_INCREMENTAL_REPAIR}
allowUnreachableNodes: ${DW_REAPER_ALLOW_UNREACHABLE_NODES}
enableDynamicSeedList: ${DW_REAPER_ENABLE_DYNAMIC_SEEDS}

autoScheduling:
enabled: ${DW_REAPER_AUTO_SCHEDULE_ENABLED}
initialDelayPeriod: ${DW_REAPER_AUTO_SCHEDULE_INITIAL_DELAY_PERIOD}
periodBetweenPolls: ${DW_REAPER_AUTO_SCHEDULE_PERIOD_BETWEEN_POLLS}
timeBeforeFirstSchedule: ${DW_REAPER_AUTO_SCHEDULE_TIME_BETWEEN_FIRST_SCHEDULE}
scheduleSpreadPeriod: ${DW_REAPER_AUTO_SCHEDULE_TIME_BETWEEN_FIRST_SCHEDULE}
excludedKeyspaces: ${DW_REAPER_AUTO_SCHEDULE_EXCLUDED_KEYSPACES}

jmxPorts: ${DW_REAPER_JMX_PORTS}

logging:
level: ${DW_REAPER_LOGGING_ROOT_LEVEL}
loggers: ${DW_REAPER_LOGGERS}
appenders:
- type: console
logFormat: ${DW_REAPER_LOGGING_FORMAT}

server:
type: default
applicationConnectors:
- type: http
port: ${DW_REAPER_APP_PORT}
bindHost: ${DW_REAPER_APP_BIND_HOST}
adminConnectors:
- type: http
port: ${DW_REAPER_ADMIN_PORT}
bindHost: ${DW_REAPER_ADMIN_BIND_HOST}
requestLog:
appenders: []

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

if [ "$1" = 'cassandra-reaper' ]; then
/root/append-persistence.sh
exec java -jar ${JAVA_OPTS} /root/cassandra-reaper.jar server /root/cassandra-reaper.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

Using gosu might be most secure, but I can handle that at a later date.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed. I can do it as part of this pull request and refactor to remove the DW_

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