diff --git a/.travis.yml b/.travis.yml index 59d5e87e..4a5b4267 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ -language: java -jdk: - - openjdk11 +language: generic # Sudo required for doing docker build sudo: required @@ -9,15 +7,32 @@ services: # Build the app and a docker image script: -- mvn clean install -- docker build -t ${TRAVIS_COMMIT} --build-arg JAR_FILE=target/killrvideo-services-3.0.0.jar ./killrvideo-services +- travis_fold start docker_build +- docker run -v ${PWD}:/opt/killrvideo-java -w /opt/killrvideo-java maven mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B +- docker build -t ${TRAVIS_COMMIT} -t killrvideo-java-local . +- travis_fold end docker_build +- travis_fold start docker_dependencies_up +- docker-compose -f docker-compose.ci.yml up -d dse dse-config +- sleep 180 +- docker-compose -f docker-compose.ci.yml up -d backend +- sleep 180 +- docker-compose -f docker-compose.ci.yml exec backend echo 'Still alive!' || { echo "Backend is down"; docker-compose -f docker-compose.ci.yml logs dse-config backend; exit 1; } +- travis_fold end docker_dependencies_up +- docker run --network killrvideo-java_default killrvideo/killrvideo-integration-tests # If successful, see if we need to publish also after_success: -- test -z $TRAVIS_TAG && travis_terminate 0 +- "[ \"$TRAVIS_EVENT_TYPE\" = \"cron\" ] && { echo \"Ignore nightly builds\"; travis_terminate 0; }" +- test -z $TRAVIS_TAG && { echo "Ignore non-tagged builds"; travis_terminate 0; } - docker tag ${TRAVIS_COMMIT} killrvideo/killrvideo-java:${TRAVIS_TAG} - echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin - docker push killrvideo/killrvideo-java:${TRAVIS_TAG} +- "[ \"$(git tag --sort=-v:refname | grep -P \"^\\d+.\\d+.\\d+$\" | head -n1)\" == \"$TRAVIS_TAG\" ] && { docker tag ${TRAVIS_COMMIT} killrvideo/killrvideo-java:latest; docker push killrvideo/killrvideo-java:latest; }" + +after_failure: +- travis_fold start docker_logs +- docker-compose -f docker-compose.ci.yml logs dse-config backend +- travis_fold end docker_logs env: global: @@ -29,4 +44,3 @@ notifications: slack: rooms: secure: N6FrJ0l0gw2t1wnty/xPDKvLBZlzOAmkIbHjd4ZrtaC4vLU8iZP+YCRvQd7Vwzc97yDhHIZ41eGtjHjBIIeMX/3rfuS+6GA4VJgyNFGsP0f81YYHxiMOEUlVa2O6LBwbF3LokaFi3l7Iau1c5Op9c3LinhTdE0W6KG+2gxEqSKJkBcVJfK9SZGXg3+6qlq065BWx7xWlzoWgMFyipJJLW1BAqEzP5cc6hHozJ5H/8ucMaJbWQF+nOaIYUJdaop4ChSpe6EFyg0XNp+mIjJ2BxZ6hfYrAs69vwBapBepe4zEoR5xdN1dGUAIDqNY9rr4Npp8InFmBmnlL1xG6FeG73C2qfSr3Y2WziOtwececzmuQWI2Do9ioB5k0KtC4UAV42tpADUODrrwxE8S32tqgr0Pojg8FvgsM6O3twvF1UH3LLEyW7zDzuDpYdtvIROWZGerxyWqQIFI7MzragyL+ZiKKUOG1uKsA8DoeECcMHuUsDEsR/mHalmQGGl2ZNGpphAHg/1HtjB32VDCIuZpFHsqFG7BfMY2dg8Mm+ea4j9imOxM+2TFxbPhoIjIJq1o+/YvolrYviWgmQOpeFw0c1xXWSL5aXmBv2nUnlBaXxfzC9FTl0xmovJmKeYhqJ81TMa33gimsMeccZIDmzcMDsW82idsvtHeNDSX1wil5DXA= - diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..6f29f7f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11 + +MAINTAINER Cedrick Lunven +MAINTAINER Davig Gilardi + +ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/killrvideo-java.jar"] +EXPOSE 50101 + +# To create jar file, run `docker run -v ${PWD}:/opt/killrvideo-java -w /opt/killrvideo-java maven mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B` +COPY ./killrvideo-services/target/killrvideo-java.jar /killrvideo-java.jar diff --git a/README.md b/README.md index 1161eff5..9e93b421 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,16 @@ A reference application for Java developers looking to learn more about using [A ## The latest stable build of KillrVideo Java is [v2.1.0][v2.1.0]. Master is experimental. Please use v2.1.0 if you attempting to follow the instructions in the links below. +## Building Locally + +**Docker Way** + +`docker run -v ${PWD}:/opt/killrvideo-java -w /opt/killrvideo-java maven mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B` + +**Maven Way** + +`mvn install` + ## Running Locally Use these guides to get started running KillrVideo locally on your development machine: diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 00000000..525407c4 --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,24 @@ +version: '3' +services: + backend: + image: killrvideo-java-local + depends_on: + - dse + environment: + KILLRVIDEO_LOGGING_LEVEL: debug + KILLRVIDEO_DSE_CONTACT_POINTS: dse + + dse: + image: datastax/dse-server:6.7.4 + command: [ -s -g ] + environment: + DS_LICENSE: accept + cap_add: + - IPC_LOCK + ulimits: + memlock: -1 + + dse-config: + image: killrvideo/killrvideo-dse-config:3.0.0 + depends_on: + - dse diff --git a/killrvideo-commons/src/main/java/com/killrvideo/dse/conf/DseConfiguration.java b/killrvideo-commons/src/main/java/com/killrvideo/dse/conf/DseConfiguration.java index 02e4f0e1..b4ebcf16 100644 --- a/killrvideo-commons/src/main/java/com/killrvideo/dse/conf/DseConfiguration.java +++ b/killrvideo-commons/src/main/java/com/killrvideo/dse/conf/DseConfiguration.java @@ -81,11 +81,17 @@ public class DseConfiguration { @Value("#{environment.KILLRVIDEO_DSE_PASSWORD}") public Optional < String > dsePassword; - @Value("${killrvideo.cassandra.maxNumberOfTries: 10}") - private int maxNumberOfTries = 10; - - @Value("${killrvideo.cassandra.delayBetweenTries: 2}") - private int delayBetweenTries = 2; + @Value("${killrvideo.cassandra.maxNumberOfTries: 50}") + private Integer maxNumberOfTries; + + @Value("#{environment.KILLRVIDEO_MAX_NUMBER_RETRY}") + private Optional < Integer > maxNumberOfTriesFromEnvVar; + + @Value("${killrvideo.cassandra.delayBetweenTries: 3}") + private Integer delayBetweenTries; + + @Value("#{environment.KILLRVIDEO_DELAY_BETWEEN_RETRY}") + private Optional < Integer > delayBetweenTriesFromEnvVar; @Value("${killrvideo.ssl.CACertFileLocation: cassandra.cert}") private String sslCACertFileLocation; @@ -133,6 +139,14 @@ public DseSession initializeDSE() { return clusterConfig.build().connect(CommonConstants.KILLRVIDEO_KEYSPACE); }; + if (!maxNumberOfTriesFromEnvVar.isEmpty()) { + maxNumberOfTries = maxNumberOfTriesFromEnvVar.get(); + } + + if (!delayBetweenTriesFromEnvVar.isEmpty()) { + delayBetweenTries = delayBetweenTriesFromEnvVar.get(); + } + // Connecting to DSE with a retry mechanism : /* In docker deployments we may have to wait until all components are up and running. */ RetryConfig config = new RetryConfigBuilder() @@ -144,7 +158,7 @@ public DseSession initializeDSE() { return new CallExecutor(config) .afterFailedTry(s -> { - LOGGER.info("Attempt #{}/{} failed.. trying in {} seconds, waiting Dse to Start", atomicCount.getAndIncrement(), + LOGGER.info("Attempt #{}/{} failed.. trying in {} seconds, waiting for DSE to start...", atomicCount.getAndIncrement(), maxNumberOfTries, delayBetweenTries); }) .onFailure(s -> { LOGGER.error("Cannot connection to DSE after {} attempts, exiting", maxNumberOfTries); diff --git a/killrvideo-services/Dockerfile b/killrvideo-services/Dockerfile deleted file mode 100644 index 4fba129c..00000000 --- a/killrvideo-services/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM openjdk:11 - -MAINTAINER Cedrick Lunven -MAINTAINER Davig Gilardi - -######################################################## -## Environment Variables -######################################################## - -ARG KILLRVIDEO_DSE_CONTACT_POINTS -ENV KILLRVIDEO_DSE_CONTACT_POINTS ${KILLRVIDEO_DSE_CONTACT_POINTS} - -ARG KILLRVIDEO_DSE_USERNAME -ENV KILLRVIDEO_DSE_USERNAME ${KILLRVIDEO_DSE_USERNAME} - -ARG KILLRVIDEO_DSE_PASSWORD -ENV KILLRVIDEO_DSE_PASSWORD ${KILLRVIDEO_DSE_PASSWORD} - -VOLUME /tmp -ARG JAR_FILE -ADD ${JAR_FILE} app.jar -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] - -# Exposing expected port by WEBUI -EXPOSE 50101 diff --git a/pom.xml b/pom.xml index 1c98cbf1..31de2eb6 100644 --- a/pom.xml +++ b/pom.xml @@ -368,6 +368,8 @@ + killrvideo-java + kr.motd.maven