Skip to content

Commit

Permalink
Simplifying docker usage.
Browse files Browse the repository at this point in the history
 - Now straight docker command line commands are used instead of
   using the Gradle docker plugin.
  • Loading branch information
danielbwatson committed Aug 22, 2016
1 parent 1b15fcd commit 0d39f04
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 195 deletions.
213 changes: 46 additions & 167 deletions metacat-functional-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,12 @@
* limitations under the License.
*/

import com.bmuschko.gradle.docker.tasks.DockerInfo
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.Dockerfile

ext {
if (project.hasProperty('startCluster')) {
startCluster = Boolean.getBoolean('startCluster')
} else {
startCluster = true
}
startCluster = project.hasProperty('startCluster') ? Boolean.getBoolean('startCluster') : true
logger.info("metacat-functional-tests: start cluster = '${startCluster}'")

if (project.hasProperty('stopCluster')) {
stopCluster = Boolean.getBoolean('stopCluster')
} else {
stopCluster = true
}
stopCluster = project.hasProperty('stopCluster') ? Boolean.getBoolean('stopCluster') : true
logger.info("metacat-functional-tests: stop cluster = '${stopCluster}'")

if (project.hasProperty('dockerHost')) {
dockerHost = project['dockerHost']
} else if (System.getenv('DOCKER_HOST')) {
dockerHost = System.getenv('DOCKER_HOST')?.replace('tcp:', 'https:')
} else {
dockerHost = 'http://localhost:2375'
}
logger.info("metacat-functional-tests: docker host '${dockerHost}'")

if (project.hasProperty('dockerIp')) {
dockerIp = project['dockerIp']
} else if (System.getenv('DOCKER_IP')) {
dockerIp = System.getenv('DOCKER_IP')
} else if (System.getenv('DOCKER_HOST')?.startsWith('tcp') || System.getenv('DOCKER_HOST')?.startsWith('http')) {
dockerIp = (System.getenv('DOCKER_HOST') =~ /:\/\/([0-9\.]+):/)[0][1]
} else {
dockerIp = 'localhost'
}
logger.info("metacat-functional-tests: docker ip '${dockerIp}'")

if (project.hasProperty('dockerCertPath')) {
dockerCertPath = new File(project['dockerCertPath'] as String)
} else if (System.getenv('DOCKER_CERT_PATH')) {
dockerCertPath = new File(System.getenv('DOCKER_CERT_PATH'))
} else {
dockerCertPath = null
}
logger.info("metacat-functional-tests: docker cert path '${dockerCertPath}'")

clusterWorkingDir = file("${rootDir}/metacat-functional-tests/metacat-test-cluster")
}

configurations {
Expand All @@ -81,18 +38,6 @@ sourceSets {
}
}

buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:3.0.1'
}
}

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

dependencies {
warproject project(path: ':metacat-server', configuration: 'archives')

Expand All @@ -108,140 +53,82 @@ dependencies {
testCompile "com.facebook.presto:presto-hive-hadoop2:${presto_version}"
}

docker {
url = project.ext.dockerHost
certPath = project.ext.dockerCertPath
}

task expandWar(type: Copy) {
dependsOn ':metacat-server:war'

from { configurations.warproject.collect { zipTree(it) } }
into file("${buildDir}/metacat-war-expanded/ROOT")
}

task dockerInfo(type: DockerInfo)

task createWarDockerfile(type: Dockerfile) {
task createWarDockerfile() {
dependsOn 'expandWar'

destFile = project.file('build/metacat-war-expanded/Dockerfile')
from 'tomcat:8.0-jre8'
maintainer 'Netflix OSS "[email protected]"'
volume '/usr/local/tomcat/logs', '/etc/metacat'
runCommand 'rm -rf /usr/local/tomcat/webapps'
copyFile './ROOT', '/usr/local/tomcat/webapps/ROOT'
ext.destFile = project.file('build/metacat-war-expanded/Dockerfile')

outputs.file ext.destFile

doLast {
ext.destFile.text = """
FROM tomcat:8.0-jre8
MAINTAINER [email protected]
VOLUME ["/usr/local/tomcat/logs", "/etc/metacat"]
EXPOSE 7001 7101 12001 12002
RUN rm -rf /usr/local/tomcat/webapps
COPY ./ROOT /usr/local/tomcat/webapps/ROOT
""".trim()
}
}

task buildWarImage(type: DockerBuildImage) {
task buildWarImage(type: Exec) {
dependsOn 'createWarDockerfile'
inputDir = createWarDockerfile.destFile.parentFile
tag = 'netflix_metacat_test/metacat_server'

inputs.file createWarDockerfile.destFile

commandLine 'docker', 'build', '--pull', '--tag', 'netflix_metacat_test/metacat_server', createWarDockerfile.destFile.parentFile
}

task startMetacatCluster(type: Exec) {
workingDir = clusterWorkingDir

environment 'PATH', '/usr/local/bin:/usr/bin:/bin'
environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:')
if (project.ext.dockerCertPath) {
environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath
environment 'DOCKER_TLS_VERIFY', '1'
if (project.ext.startCluster) {
commandLine rootProject.file('scripts/start_metacat_test_cluster.sh'), project.file('metacat-test-cluster/docker-compose.yml')
} else {
commandLine '/bin/echo', 'skipping cluster start'
}

commandLine './startCluster.sh'
}

task stopMetacatCluster(type: Exec) {
workingDir = clusterWorkingDir

environment 'PATH', '/usr/local/bin:/usr/bin:/bin'
environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:')
if (project.ext.dockerCertPath) {
environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath
environment 'DOCKER_TLS_VERIFY', '1'
if (project.ext.stopCluster) {
commandLine rootProject.file('scripts/stop_metacat_test_cluster.sh'), project.file('metacat-test-cluster/docker-compose.yml')
} else {
commandLine '/bin/echo', 'skipping cluster stop'
}

commandLine './stopCluster.sh'
}

task metacatPorts {
if (project.ext.startCluster) {
dependsOn 'startMetacatCluster'
}
dependsOn 'startMetacatCluster'
ext.http_port = null
ext.metacat_hive_thrift_port = null
ext.metacat_s3_thrift_port = null
ext.hive_thrift_port = null

doLast {
new ByteArrayOutputStream().withStream { os ->
exec {
workingDir = clusterWorkingDir

environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:')
if (project.ext.dockerCertPath) {
environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath
environment 'DOCKER_TLS_VERIFY', '1'
}

commandLine './printDockerPort.sh', project.ext.dockerIp, 'label=com.netflix.metacat.oss.test.war', 8080
standardOutput = os
}
ext.http_port = os.toString().trim()
logger.info("metacat-functional-tests: metacat http_port '{}'", ext.http_port)
}

new ByteArrayOutputStream().withStream { os ->
exec {
workingDir = clusterWorkingDir

environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:')
if (project.ext.dockerCertPath) {
environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath
environment 'DOCKER_TLS_VERIFY', '1'
}

commandLine './printDockerPort.sh', project.ext.dockerIp, 'label=com.netflix.metacat.oss.test.war', 12001
standardOutput = os
}
ext.metacat_hive_thrift_port = os.toString().trim()
logger.info("metacat-functional-tests: metacat thrift_port '{}'", ext.metacat_hive_thrift_port)
}

new ByteArrayOutputStream().withStream { os ->
exec {
workingDir = clusterWorkingDir

environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:')
if (project.ext.dockerCertPath) {
environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath
environment 'DOCKER_TLS_VERIFY', '1'
def get_docker_port = { String label, int exposed_port ->
new ByteArrayOutputStream().withStream { os ->
exec {
commandLine rootProject.file('scripts/print_docker_port.sh'), "label=${label}", exposed_port
standardOutput = os
}

commandLine './printDockerPort.sh', project.ext.dockerIp, 'label=com.netflix.metacat.oss.test.war', 12002
standardOutput = os
return os.toString().trim()
}
ext.metacat_s3_thrift_port = os.toString().trim()
logger.info("metacat-functional-tests: metacat thrift_port '{}'", ext.metacat_s3_thrift_port)
}

new ByteArrayOutputStream().withStream { os ->
exec {
workingDir = clusterWorkingDir

environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:')
if (project.ext.dockerCertPath) {
environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath
environment 'DOCKER_TLS_VERIFY', '1'
}
ext.http_port = get_docker_port('com.netflix.metacat.oss.test.war', 8080)
ext.metacat_hive_thrift_port = get_docker_port('com.netflix.metacat.oss.test.war', 12001)
ext.metacat_s3_thrift_port = get_docker_port('com.netflix.metacat.oss.test.war', 12002)
ext.hive_thrift_port = get_docker_port('com.netflix.metacat.oss.test.hive', 9083)

commandLine './printDockerPort.sh', project.ext.dockerIp, 'label=com.netflix.metacat.oss.test.hive', 9083
standardOutput = os
}
ext.hive_thrift_port = os.toString().trim()
logger.info("metacat-functional-tests: metacat hive_thrift_port '{}'", ext.hive_thrift_port)
}
logger.info('metacat-functional-tests: metacat http_port {}, metacat_hive_thrift_port {}, ' +
'metacat_s3_thrift_port {}, hive_thrift_port {}',
ext.http_port, ext.metacat_hive_thrift_port, ext.metacat_s3_thrift_port, ext.hive_thrift_port)
}
}

Expand All @@ -252,7 +139,6 @@ task functionalTest(type: Test) {

doFirst {
def properties = [
'metacat_docker_ip' : project.ext.dockerIp as String,
'metacat_http_port' : metacatPorts.http_port as String,
'metacat_hive_thrift_port' : metacatPorts.metacat_hive_thrift_port as String,
'metacat_s3_thrift_port' : metacatPorts.metacat_s3_thrift_port as String,
Expand All @@ -269,13 +155,6 @@ task functionalTest(type: Test) {
showStandardStreams = true
}

if (project.ext.startCluster) {
dependsOn 'startMetacatCluster', 'metacatPorts'
} else {
dependsOn 'metacatPorts'
}

if (project.ext.stopCluster) {
finalizedBy 'stopMetacatCluster'
}
dependsOn 'startMetacatCluster', 'metacatPorts'
finalizedBy 'stopMetacatCluster'
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ class MetacatFunctionalSpec extends Specification {
public static final long BATCH_ID = System.currentTimeSeconds()

def setupSpec() {
String dockerIp = System.properties['metacat_docker_ip']?.toString()?.trim()
assert dockerIp, 'Required system property "metacat_docker_ip" is not set'
String httpPort = System.properties['metacat_http_port']?.toString()?.trim()
assert httpPort, 'Required system property "metacat_http_port" is not set'

def client = Client.builder()
.withHost("http://$dockerIp:$httpPort")
.withHost("http://localhost:$httpPort")
.withDataTypeContext('pig')
.withUserName('metacat-test')
.withClientAppName('metacat-test')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,21 @@ class MetacatThriftFunctionalSpec extends Specification {
});

def setupSpec() {
String dockerIp = System.properties['metacat_docker_ip']?.toString()?.trim()
assert dockerIp, 'Required system property "metacat_docker_ip" is not set'
String thriftPort = System.properties['metacat_hive_thrift_port']?.toString()?.trim()
assert thriftPort, 'Required system property "metacat_hive_thrift_port" is not set'
metacatHiveThriftUri = "thrift://${dockerIp}:${thriftPort}".toString()
metacatHiveThriftUri = "thrift://localhost:${thriftPort}".toString()
TestCatalogs.findByCatalogName('hive-metastore').thriftUri = metacatHiveThriftUri

// TODO enable this, commenting out because s3 type currently doesn't have enough places to store parameters
// currently only table.location.info.parameters and we need 2 more parameters
// thriftPort = System.properties['metacat_s3_thrift_port']?.toString()?.trim()
// assert thriftPort, 'Required system property "metacat_s3_thrift_port" is not set'
// metacatS3ThriftUri = "thrift://${dockerIp}:${thriftPort}".toString()
// metacatS3ThriftUri = "thrift://localhost:${thriftPort}".toString()
// TestCatalogs.findByCatalogName('s3-mysql-db').thriftUri = metacatS3ThriftUri

thriftPort = System.properties['hive_thrift_port']?.toString()?.trim()
assert thriftPort, 'Required system property "hive_thrift_port" is not set'
hiveThriftUri = "thrift://${dockerIp}:${thriftPort}".toString()
hiveThriftUri = "thrift://localhost:${thriftPort}".toString()

TestCatalogs.resetAll()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@

set -x

if [[ ( $# -eq 0 ) || ( -z "$1" ) || ( -z "$2" ) || ( -z "$3" ) ]]; then
echo "Usage: ./printDockerPort.sh [docker_host_ip] [docker_container_filter] [container_port_number]"
exit 1
fi

# Adding /usr/local/bin to the path if it is not already present
if [ -d "/usr/local/bin" ] && [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
PATH="${PATH:+"$PATH:"}/usr/local/bin"
fi

DOCKER_IP=$1
DOCKER_FILTER=$2
DOCKER_PORT_NUM=$3
DOCKER_FILTER=$1
DOCKER_PORT_NUM=$2

DOCKER_CONTAINER=$(docker ps -a -q --filter $DOCKER_FILTER 2>/dev/null)
if [ ! "$DOCKER_CONTAINER" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ set -x
echo PATH is $PATH
echo DOCKER env is $(env | grep DOCKER)

# Usage: ./startCluster.sh
# Usage: ./startCluster.sh docker-compose.yml
COMPOSE_FILE=$1

docker-compose up storage-barrier #>> build/docker_compose.log 2>&1
docker-compose --file $COMPOSE_FILE up storage-barrier #>> build/docker_compose.log 2>&1
if [ $? -ne 0 ]; then
echo "Unable to start storage containers"
exit 9
fi

docker-compose up service-barrier #>> build/docker_compose.log 2>&1
docker-compose --file $COMPOSE_FILE up service-barrier #>> build/docker_compose.log 2>&1
if [ $? -ne 0 ]; then
echo "Unable to start service containers"
exit 10
fi

docker-compose up metacat-barrier #>> build/docker_compose.log 2>&1
docker-compose --file $COMPOSE_FILE up metacat-barrier #>> build/docker_compose.log 2>&1
if [ $? -ne 0 ]; then
echo "Unable to start metacat service container"
exit 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

set -x

# Usage: ./stopCluster.sh
# Usage: ./stopCluster.sh docker-compose.yml
COMPOSE_FILE=$1

docker-compose stop -t 30
docker-compose --file $COMPOSE_FILE stop -t 30
if [ $? -ne 0 ]; then
echo "Unable to stop docker-compose"
exit 9
fi

docker-compose rm -f
docker-compose --file $COMPOSE_FILE rm -f
if [ $? -ne 0 ]; then
echo "Unable to remove docker compose containers"
exit 10
Expand Down

0 comments on commit 0d39f04

Please sign in to comment.