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

CI/CD Upgrade #2

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Docker Image CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build the Docker image
run: |
docker build -t killrvideo/killrvideo-integration-tests:$GITHUB_SHA -t killrvideo/killrvideo-integration-tests:latest .
docker login -u ${{ secrets.docker_user }} -p ${{ secrets.docker_password }}
docker push killrvideo/killrvideo-integration-tests:$GITHUB_SHA
docker push killrvideo/killrvideo-integration-tests:latest
50 changes: 6 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
FROM openjdk:8-jdk
FROM maven:3.6-jdk-8

ARG MAVEN_VERSION=3.5.0
ARG USER_HOME_DIR="/root"
ARG SHA=beb91419245395bd69a4a6edad5ca3ec1a8b64e41457672dc687c173a495f034
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
WORKDIR /root

RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-$MAVEN_VERSION-bin.tar.gz \
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn \
&& apt-get update \
&& apt-get install -y tar curl git \
&& rm -rf /var/lib/apt/lists/*
COPY pom.xml /root/
COPY src/ /root/src

ENV MAVEN_HOME=/usr/share/maven

ENV MAVEN_CONFIG=/root/.m2

#To be configured at runtime when launching the container with "--env KILLRVIDEO_DOCKER_IP=..."
ENV KILLRVIDEO_DOCKER_IP=99.99.99.99

WORKDIR /home

RUN chmod -R 755 /home \
&& mkdir -p /tmp/cucumber-report \
&& chmod -R 755 /tmp/cucumber-report \
&& mkdir /home/zeppelin \
&& chmod -R 755 /home/zeppelin


RUN cd /home \
&& git clone https://github.com/killrvideo/killrvideo-integration-tests.git

COPY zeppelin /home/zeppelin
ADD startup.sh /home

RUN chmod 755 /home/startup.sh

EXPOSE 8080/tcp
EXPOSE 8123/tcp

CMD ["/bin/bash","-c","/home/startup.sh"]

#CMD ["/bin/bash"]
RUN mvn dependency:copy-dependencies dependency:resolve-plugins test -DskipTests

CMD ["mvn", "surefire:test"]
39 changes: 0 additions & 39 deletions getenvironment.sh

This file was deleted.

18 changes: 12 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

<dependencies>

<dependency>
<groupId>com.evanlennick</groupId>
<artifactId>retry4j</artifactId>
<version>0.12.0</version>
</dependency>
<dependency>
<groupId>com.evanlennick</groupId>
<artifactId>retry4j</artifactId>
<version>0.12.0</version>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
Expand Down Expand Up @@ -72,7 +72,6 @@
</exclusions>
</dependency>


<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
Expand Down Expand Up @@ -157,6 +156,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.12.4</version>
</dependency>

</dependencies>

<build>
Expand All @@ -171,6 +176,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.datastax.driver.core.Session;
import com.datastax.killrvideo.it.util.HostAndPortSplitter;
import com.datastax.killrvideo.it.util.ServiceChecker;
import com.xqbase.etcd4j.EtcdClient;
import com.xqbase.etcd4j.EtcdNode;

@Configuration
public class CassandraConfiguration {
Expand All @@ -26,35 +24,19 @@ public class CassandraConfiguration {
private static final String KEYSPACE_NAME = "killrvideo";

@Inject
private EtcdClient etcdClient;
private KillrVideoProperties properties;

@Bean(destroyMethod = "close")
public Session getSession() throws Exception {
final List<EtcdNode> etcdNodes = etcdClient.listDir("killrvideo/services/cassandra");
if (CollectionUtils.isEmpty(etcdNodes)) {
throw new IllegalStateException(format("Cannot find any Cassandra service in etcd. " +
"Please wait until Cassandra has successfully started"));
} else {
final EtcdNode cassandraAddress = etcdNodes.get(0);
final String hostAndPort = cassandraAddress.value;
assert hostAndPort != null;
HostAndPortSplitter.ensureValidFormat(hostAndPort,
format("The %s is not a valid host:port format", hostAndPort));

final String address = HostAndPortSplitter.extractAddress(hostAndPort);
final int port = HostAndPortSplitter.extractPort(hostAndPort);

ServiceChecker.waitForService("Cassandra", address, port, WAIT_TIME_IN_SECONDS);

final Cluster cluster = Cluster
.builder()
.addContactPoint(address)
.withPort(port)
.withClusterName(CLUSTER_NAME)
.build();

return cluster.connect();
}
ServiceChecker.waitForService("Cassandra", properties.cassandraHost, properties.cassandraPort, WAIT_TIME_IN_SECONDS);

final Cluster cluster = Cluster
.builder()
.addContactPoint(properties.cassandraHost)
.withPort(properties.cassandraPort)
.withClusterName(CLUSTER_NAME)
.build();

return cluster.connect();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.datastax.killrvideo.it.async.KillrVideoThreadFactory;
import com.datastax.killrvideo.it.util.HostAndPortSplitter;
import com.datastax.killrvideo.it.util.ServiceChecker;
import com.xqbase.etcd4j.EtcdClient;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
Expand All @@ -39,48 +38,29 @@ public class KillrVideoITConfiguration {
public static final String SEARCH_SERVICE_NAME = "SearchService";
public static final String SUGGESTED_VIDEOS_SERVICE_NAME = "SuggestedVideoService";

@Inject
private EtcdClient etcdClient;

@Inject
private KillrVideoProperties properties;

@Bean
public ManagedChannel getManagedChannel() throws Exception {
final String grpcUserServiceUrl = "killrvideo/services/"
+ USER_SERVICE_NAME
+ "/"
+ properties.applicationName;

while (!ServiceChecker.isServicePresent(etcdClient, grpcUserServiceUrl)) {
System.out.println("Waiting 10 seconds for KillrVideoServer services to be registered: " + grpcUserServiceUrl);
Thread.sleep(10000);
}

final Optional<String> foundKillrVideoServer = Optional.ofNullable(etcdClient.get(grpcUserServiceUrl));
final String hostAndPort = properties.services.get(USER_SERVICE_NAME);
HostAndPortSplitter.ensureValidFormat(hostAndPort,
format("The %s is not a valid host:port format", hostAndPort));

if (!foundKillrVideoServer.isPresent()) {
throw new IllegalStateException(format("Cannot look up service name %s from etcd. Please ensure you start KillrVideoServer before",
grpcUserServiceUrl));
} else {
final String hostAndPort = foundKillrVideoServer.get();
HostAndPortSplitter.ensureValidFormat(hostAndPort,
format("The %s is not a valid host:port format", hostAndPort));
final String address = HostAndPortSplitter.extractAddress(hostAndPort);
final int port = HostAndPortSplitter.extractPort(hostAndPort);

final String address = HostAndPortSplitter.extractAddress(hostAndPort);
final int port = HostAndPortSplitter.extractPort(hostAndPort);
ServiceChecker.waitForService("KillrVideoServer " + USER_SERVICE_NAME, address, port, WAIT_TIME_IN_SECONDS);

ServiceChecker.waitForService("KillrVideoServer " + USER_SERVICE_NAME, address, port, WAIT_TIME_IN_SECONDS);
System.out.println("Waiting 2 seconds for KillrVideoServer complete startup (conservative approach)");

System.out.println("Waiting 2 seconds for KillrVideoServer complete startup (conservative approach)");
Thread.sleep(2000);

Thread.sleep(2000);
return ManagedChannelBuilder
.forAddress(address, port)
.usePlaintext(true)
.build();

return ManagedChannelBuilder
.forAddress(address, port)
.usePlaintext(true)
.build();
}
}

@Bean(destroyMethod = "shutdownNow")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,49 @@
import static java.lang.String.format;

import java.util.Optional;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.core.env.Environment;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class KillrVideoProperties {

private static final Logger LOGGER = LoggerFactory.getLogger(KillrVideoProperties.class);


public static final String APPLICATION_NAME = "killrvideo.application.name";
public static final String ETCD_PORT = "killrvideo.etcd.port";
public static final String KILLRVIDEO_DOCKER_IP = "KILLRVIDEO_DOCKER_IP";
public static final int WAIT_TIME_IN_SECONDS = 10;

public static final String APPLICATION_NAME = "killrvideo.application.name";
public static final String CASSANDRA_HOST = "killrvideo.cassandra.host";
public static final String CASSANDRA_PORT = "killrvideo.cassandra.port";

public final String applicationName;
public final int etcdPort;
public final String dockerIp;
public final String cassandraHost;
public final Integer cassandraPort;

public final HashMap<String, String> services = new HashMap<String, String>();

@Inject
private Environment env;

public KillrVideoProperties(Environment env) {
this.applicationName = env.getProperty(APPLICATION_NAME, "KillrVideo");
this.etcdPort = parseInt(env.getProperty(ETCD_PORT, "2379"));

/**
* Need to set env variable KILLRVIDEO_DOCKER_IP before launching application
*
final Optional<String> dockerIp = Optional.ofNullable(System.getenv(KILLRVIDEO_DOCKER_IP));
if (!dockerIp.isPresent()) {

final String errorMessage = format("Cannot find environment variable %s. " +
"Please set it before launching KillrVideoServer", KILLRVIDEO_DOCKER_IP);
LOGGER.error(errorMessage);
throw new IllegalStateException(errorMessage);

} else {
LOGGER.info("Setting docker ip to : " + dockerIp.get());
this.dockerIp = dockerIp.get();
}*/
this.dockerIp = "10.0.75.1";
this.cassandraHost = env.getProperty(CASSANDRA_HOST, "dse");
this.cassandraPort = Integer.parseInt(env.getProperty(CASSANDRA_PORT, "9042"));

this.services.put("UserManagementService", "backend:50101");
this.services.put("CommentsService", "backend:50101");
this.services.put("VideoCatalogService", "backend:50101");
this.services.put("RatingsService", "backend:50101");
this.services.put("StatisticsService", "backend:50101");
this.services.put("SearchService", "backend:50101");
this.services.put("SuggestedVideoService", "backend:50101");
}
}
Loading