Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
#453 Moved cli code into separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
frankscholten committed May 24, 2016
1 parent 1368964 commit cc83a10
Show file tree
Hide file tree
Showing 32 changed files with 165 additions and 102 deletions.
4 changes: 2 additions & 2 deletions bin/minimesos
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ docker run --rm -v "${MINIMESOS_HOST_DIR}":"${MINIMESOS_HOST_DIR}" \
-i \
--env DOCKER_HOST_IP=${DOCKER_HOST_IP} \
--entrypoint java \
containersol/minimesos:${MINIMESOS_TAG} \
containersol/minimesos-cli:${MINIMESOS_TAG} \
-Dminimesos.host.dir="${MINIMESOS_HOST_DIR}" \
-jar /usr/local/share/minimesos/minimesos.jar ${PARAMS}
-jar /usr/local/share/minimesos/minimesos-cli.jar ${PARAMS}
2 changes: 1 addition & 1 deletion minimesos/Dockerfile → cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM containersol/alpine3.3-java8-jre:v1
MAINTAINER Container Solutions BV <[email protected]>

ADD minimesos.jar /usr/local/share/minimesos/minimesos.jar
ADD minimesos-cli.jar /usr/local/share/minimesos/minimesos-cli.jar
125 changes: 125 additions & 0 deletions cli/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
import com.bmuschko.gradle.docker.tasks.image.DockerTagImage

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.bmuschko.docker-remote-api'

repositories {
mavenLocal()
mavenCentral()
maven {
url "https://jitpack.io"
}
}

group = "com.containersol.minimesos"

dependencies {
compile 'com.beust:jcommander:1.48'
compile 'org.slf4j:slf4j-api:1.7.12'

compile project(':minimesos')

testCompile 'junit:junit:4.11'
testCompile "org.mockito:mockito-core:1.+"
// using guru.nidi as maintenanance of the original project is dropped https://github.com/clarkware/jdepend/pull/9
testCompile "guru.nidi:jdepend:2.9.5"
}

mainClassName = "com.containersol.minimesos.main.Main"

ext {
imageName = imagePrefix + '/minimesos-cli'
}

test {
testLogging {
showStandardStreams = true
}
}

task executableJar(type: Jar) {
baseName = "minimesos-cli"
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
manifest {
attributes(
'Main-Class': mainClassName,
'Implementation-Version': project.version
)
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
}

artifacts {
archives executableJar
}

task copyFilesForDocker(type: Copy) {
dependsOn 'executableJar'
from "build/libs/minimesos-cli-${project.version}.jar"
into 'build/docker'
rename { String fileName ->
fileName.replace("-${project.version}", "")
}
}

task copyDockerfile(type: Copy) {
dependsOn 'copyFilesForDocker'
from "Dockerfile"
into 'build/docker'
}

afterEvaluate { project ->
if (new File(project.projectDir, 'Dockerfile').exists()) {
if (!project.hasProperty('imageName')) {
throw new GradleException('Root directory of ' + project.name
+ ' contains Dockerfile, but it does not define project.ext.imageName value')
}
docker.url = 'unix:///var/run/docker.sock'
if (!System.properties['os.name'].equals('Mac OS X')) {
docker.certPath = null
}
if (System.env.DOCKER_HOST) {
docker.url = "$System.env.DOCKER_HOST".replace("tcp", "https")
if (System.env.DOCKER_CERT_PATH) {
docker.certPath = new File(System.env.DOCKER_CERT_PATH)
}
}
task buildDockerImage(type: DockerBuildImage, dependsOn: [copyDockerfile], description: 'build Docker image') {
inputDir = new File("${buildDir}/docker")
tag = project.imageName
}
project.build.dependsOn buildDockerImage
['snapshot', 'version'].each { aTag ->
String uppercasedName = aTag.capitalize()
task "tagDockerImageWith$uppercasedName"(type: DockerTagImage, description: 'tag Docker image') {
imageId = project.imageName
tag = ('version'.equals(aTag)) ? project.version : aTag
repository = project.imageName
force = true
}
task "publishDockerImageWith$uppercasedName"(type: DockerPushImage, dependsOn: ["tagDockerImageWith$uppercasedName"],
description: 'publish Docker image') {
imageName = project.imageName
tag = ('version'.equals(aTag)) ? project.version : aTag
doFirst {
['dockerHubUsername', 'dockerHubPassword', 'dockerHubEmail'].each {
assert project.hasProperty(it): 'Undefined "' + it + '" property'
}
docker {
registryCredentials {
username = project.property('dockerHubUsername')
password = project.property('dockerHubPassword')
email = project.property('dockerHubEmail')
}
}
}
}
}
}
}

assemble.dependsOn executableJar
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import com.containersol.minimesos.cluster.MesosCluster;
import com.containersol.minimesos.cluster.MesosClusterFactory;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito;

import java.io.PrintStream;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class CommandUninstallTest {

private ByteArrayOutputStream outputStream;
Expand All @@ -33,13 +29,13 @@ public void initTest() {
outputStream = new ByteArrayOutputStream();
ps = new PrintStream(outputStream, true);

marathon = mock(Marathon.class);
marathon = Mockito.mock(Marathon.class);

mesosCluster = mock(MesosCluster.class);
when(mesosCluster.getMarathon()).thenReturn(marathon);
mesosCluster = Mockito.mock(MesosCluster.class);
Mockito.when(mesosCluster.getMarathon()).thenReturn(marathon);

repository = mock(ClusterRepository.class);
when(repository.loadCluster(any(MesosClusterFactory.class))).thenReturn(mesosCluster);
repository = Mockito.mock(ClusterRepository.class);
Mockito.when(repository.loadCluster(Matchers.any(MesosClusterFactory.class))).thenReturn(mesosCluster);

commandUninstall = new CommandUninstall(ps);
commandUninstall.setRepository(repository);
Expand All @@ -48,21 +44,21 @@ public void initTest() {

@Test
public void execute() {
doNothing().when(marathon).deleteApp("app");
Mockito.doNothing().when(marathon).deleteApp("app");

commandUninstall.execute();

String result = outputStream.toString();
assertEquals("Deleted app 'app'\n", result);
Assert.assertEquals("Deleted app 'app'\n", result);
}

@Test
public void execute_appDoesNotExist() {
doThrow(new MinimesosException("App does not exist")).when(marathon).deleteApp("app");
Mockito.doThrow(new MinimesosException("App does not exist")).when(marathon).deleteApp("app");

commandUninstall.execute();

String result = outputStream.toString();
assertEquals("", result);
Assert.assertEquals("", result);
}
}
File renamed without changes.
8 changes: 8 additions & 0 deletions cli/src/test/resources/configFiles/minimal-minimesosFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
minimesos {
clusterName = "minimesos-test"
mapPortsToHost = false
loggingLevel = "INFO"
mapAgentSandboxVolume = false
mesosVersion = "0.25"
timeout = 60
}
16 changes: 16 additions & 0 deletions cli/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration debug="false">

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36}: %msg%n</pattern>
</encoder>
</appender>

<logger name="com.containersol.minimesos" level="debug"/>

<root level="warn">
<appender-ref ref="console" />
</root>

</configuration>
83 changes: 0 additions & 83 deletions minimesos/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
import com.bmuschko.gradle.docker.tasks.image.DockerTagImage

ext {
imageName = imagePrefix + '/minimesos'
}

tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
Expand Down Expand Up @@ -104,29 +96,6 @@ task installMinimesosScript(type: Copy) {
into "/usr/local/bin"
}

task copyExecutableJar(type: Copy) {
dependsOn 'executableJar'
rename { String fileName ->
fileName.replace("-${project.version}-all", "")
}
from "build/libs/minimesos-${project.version}-all.jar"
into 'build/libs'
}

task copyFilesForDocker(type: Copy) {
dependsOn 'copyExecutableJar'
from "build/libs/minimesos.jar"
into 'build/docker'
rename { String fileName ->
fileName.replace("-${project.version}", "")
}
}

task copyDockerfile(type: Copy) {
dependsOn 'copyFilesForDocker'
from "Dockerfile"
into 'build/docker'
}

artifacts {
archives executableJar
Expand All @@ -138,55 +107,3 @@ test {
}
}

afterEvaluate { project ->
if (new File(project.projectDir, 'Dockerfile').exists()) {
if (!project.hasProperty('imageName')) {
throw new GradleException('Root directory of ' + project.name
+ ' contains Dockerfile, but it does not define project.ext.imageName value')
}
docker.url = 'unix:///var/run/docker.sock'
if (!System.properties['os.name'].equals('Mac OS X')) {
docker.certPath = null
}
if (System.env.DOCKER_HOST) {
docker.url = "$System.env.DOCKER_HOST".replace("tcp", "https")
if (System.env.DOCKER_CERT_PATH) {
docker.certPath = new File(System.env.DOCKER_CERT_PATH)
}
}
task buildDockerImage(type: DockerBuildImage, dependsOn: [copyDockerfile], description: 'build Docker image') {
inputDir = new File("${buildDir}/docker")
tag = project.imageName
}
project.build.dependsOn buildDockerImage
['snapshot', 'version'].each { aTag ->
String uppercasedName = aTag.capitalize()
task "tagDockerImageWith$uppercasedName"(type: DockerTagImage, description: 'tag Docker image') {
imageId = project.imageName
tag = ('version'.equals(aTag)) ? project.version : aTag
repository = project.imageName
force = true
}
task "publishDockerImageWith$uppercasedName"(type: DockerPushImage, dependsOn: ["tagDockerImageWith$uppercasedName"],
description: 'publish Docker image') {
imageName = project.imageName
tag = ('version'.equals(aTag)) ? project.version : aTag
doFirst {
['dockerHubUsername', 'dockerHubPassword', 'dockerHubEmail'].each {
assert project.hasProperty(it): 'Undefined "' + it + '" property'
}
docker {
registryCredentials {
username = project.property('dockerHubUsername')
password = project.property('dockerHubPassword')
email = project.property('dockerHubEmail')
}
}
}
}
}
}
}

assemble.dependsOn copyExecutableJar
// install.dependsOn installMinimesosScript
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include "minimesos"
include "test-framework-docker:scheduler"
include "test-framework-docker:executor"
include "test-framework-docker:system-test"
include "cli"

0 comments on commit cc83a10

Please sign in to comment.