polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [2/2] polygene-java git commit: build & docker-tests: revamp how Docker availability is detected
Date Sat, 25 Feb 2017 14:24:13 GMT
build & docker-tests: revamp how Docker availability is detected


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/431695a1
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/431695a1
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/431695a1

Branch: refs/heads/develop
Commit: 431695a190496f6b94f31a3c423dc1a6b0b63b06
Parents: 5860c1e
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Sat Feb 25 15:12:48 2017 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sat Feb 25 15:12:48 2017 +0100

----------------------------------------------------------------------
 .../polygene/gradle/code/CodePlugin.groovy      | 22 ++++++++++--
 .../internals/InternalDockerPlugin.groovy       | 38 +++++++++++++++++---
 internals/testsupport-internal/build.gradle     |  3 +-
 .../polygene/test/internal/DockerRule.java      |  8 ++---
 4 files changed, 60 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/431695a1/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy
----------------------------------------------------------------------
diff --git a/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy b/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy
index 1448341..eb605c9 100644
--- a/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy
+++ b/buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy
@@ -22,9 +22,11 @@ import org.apache.polygene.gradle.BasePlugin
 import org.apache.polygene.gradle.TaskGroups
 import org.apache.polygene.gradle.dependencies.DependenciesDeclarationExtension
 import org.apache.polygene.gradle.dependencies.DependenciesPlugin
+import org.gradle.api.Action
 import org.gradle.api.JavaVersion
 import org.gradle.api.Plugin
 import org.gradle.api.Project
+import org.gradle.api.Task
 import org.gradle.api.plugins.JavaPluginConvention
 import org.gradle.api.plugins.osgi.OsgiManifest
 import org.gradle.api.tasks.bundling.AbstractArchiveTask
@@ -38,6 +40,8 @@ import org.gradle.testing.jacoco.tasks.JacocoReport
 @CompileStatic
 class CodePlugin implements Plugin<Project>
 {
+  public static final String DOCKER_DISABLED_EXTRA_PROPERTY = 'dockerDisabled'
+
   @Override
   void apply( Project project )
   {
@@ -91,7 +95,7 @@ class CodePlugin implements Plugin<Project>
     def maxTestWorkers = ( parallel ? project.gradle.startParameter.maxWorkerCount : 1 )
as int
     // The space in the directory name is intentional
     def allTestsDir = project.file "$project.buildDir/tmp/test files"
-    project.tasks.withType( Test ) { Test testTask ->
+    def testTasks = project.tasks.withType( Test ) { Test testTask ->
       testTask.onlyIf { !project.hasProperty( 'skipTests' ) }
       testTask.testLogging.info.exceptionFormat = TestExceptionFormat.FULL
       testTask.maxHeapSize = '1g'
@@ -123,8 +127,22 @@ class CodePlugin implements Plugin<Project>
           project.delete testDir
         }
       }
-      testTask.inputs.property( 'polygeneTestSupportDockerHostEnv', System.getenv( 'DOCKER_HOST'
) )
     }
+    // Configuration task to honor disabling Docker when unavailable
+    project.tasks.create( 'configureDockerForTest', { Task task ->
+      // TODO Untangle docker connectivity check & test task configuration
+      task.dependsOn ':internals:testsupport-internal:checkDockerConnectivity'
+      testTasks.each { it.dependsOn task }
+      task.inputs.property 'polygeneTestSupportDockerDisabled',
+                           { project.findProperty( DOCKER_DISABLED_EXTRA_PROPERTY ) }
+      task.doLast {
+        boolean dockerDisabled = project.findProperty( DOCKER_DISABLED_EXTRA_PROPERTY )
+        testTasks.each { testTask ->
+          testTask.inputs.property 'polygeneTestSupportDockerDisabled', dockerDisabled
+          testTask.systemProperty 'DOCKER_DISABLED', dockerDisabled
+        }
+      }
+    } as Action<Task> )
   }
 
   private static void configureJar( Project project )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/431695a1/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy
----------------------------------------------------------------------
diff --git a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy
b/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy
index 898a075..cdfd95d 100644
--- a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy
+++ b/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/internals/InternalDockerPlugin.groovy
@@ -19,13 +19,17 @@ package org.apache.polygene.gradle.structure.internals
 
 import com.bmuschko.gradle.docker.DockerExtension
 import com.bmuschko.gradle.docker.DockerRemoteApiPlugin
+import com.bmuschko.gradle.docker.tasks.DockerVersion
 import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
 import groovy.transform.CompileStatic
 import org.apache.polygene.gradle.BasePlugin
+import org.apache.polygene.gradle.code.CodePlugin
 import org.apache.polygene.gradle.code.PublishNaming
 import org.apache.polygene.gradle.dependencies.DependenciesPlugin
+import org.gradle.api.Action
 import org.gradle.api.Plugin
 import org.gradle.api.Project
+import org.gradle.api.logging.LogLevel
 
 @CompileStatic
 class InternalDockerPlugin implements Plugin<Project>
@@ -40,6 +44,7 @@ class InternalDockerPlugin implements Plugin<Project>
     project.plugins.apply BasePlugin
     project.plugins.apply DependenciesPlugin
     applyDockerPlugin( project )
+    applyDockerSwitch( project )
     applyDockerBuildImage( project )
   }
 
@@ -47,9 +52,29 @@ class InternalDockerPlugin implements Plugin<Project>
   {
     project.plugins.apply DockerRemoteApiPlugin
     def dockerExtension = project.extensions.getByType DockerExtension
-    dockerExtension.certPath = dockerCertPath ?
-                               new File( dockerCertPath ) :
-                               new File( System.getProperty( 'user.home' ), '.boot2docker/certs/boot2docker-vm'
)
+    // TLS support
+    if( dockerCertPath )
+    {
+      dockerExtension.certPath = new File( dockerCertPath )
+    }
+  }
+
+  private void applyDockerSwitch( Project project )
+  {
+    project.tasks.create( 'checkDockerConnectivity', DockerVersion, { DockerVersion task
->
+      task.onError = { ex ->
+        // Disable Docker for this build
+        project.rootProject.extensions.extraProperties.set( CodePlugin.DOCKER_DISABLED_EXTRA_PROPERTY,
true )
+        if( project.logger.isEnabled( LogLevel.INFO ) )
+        {
+          project.logger.info 'Unable to connect to Docker, all Docker tasks will be SKIPPED',
ex
+        }
+        else
+        {
+          project.logger.lifecycle "Unable to connect to Docker, all Docker tasks will be
SKIPPED\n  ${ ( ( Exception ) ex ).message }"
+        }
+      }
+    } as Action<DockerVersion> )
   }
 
   private void applyDockerBuildImage( Project project )
@@ -62,7 +87,12 @@ class InternalDockerPlugin implements Plugin<Project>
       project.tasks.create( taskName, DockerBuildImage ) { DockerBuildImage task ->
         task.group = 'docker'
         task.description = "Build $dockerName Docker image"
-        task.onlyIf { dockerHost }
+        task.dependsOn 'checkDockerConnectivity'
+        task.onlyIf {
+          def extra = project.rootProject.extensions.extraProperties
+          !( extra.has( CodePlugin.DOCKER_DISABLED_EXTRA_PROPERTY ) &&
+             extra.get( CodePlugin.DOCKER_DISABLED_EXTRA_PROPERTY ) )
+        }
         task.inputs.property 'dockerMachineName', dockerMachineName
         task.inputs.property 'dockerHostEnv', dockerHost
         task.inputs.property 'dockerCertPath', dockerCertPath

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/431695a1/internals/testsupport-internal/build.gradle
----------------------------------------------------------------------
diff --git a/internals/testsupport-internal/build.gradle b/internals/testsupport-internal/build.gradle
index d65e648..fc70ba0 100644
--- a/internals/testsupport-internal/build.gradle
+++ b/internals/testsupport-internal/build.gradle
@@ -21,7 +21,8 @@ apply plugin: 'polygene-internal-docker'
 
 dependencies {
   api polygene.core.testsupport
-  api libraries.docker_junit
+
+  implementation libraries.docker_junit
 
   runtimeOnly polygene.core.runtime
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/431695a1/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java
----------------------------------------------------------------------
diff --git a/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java
b/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java
index cea44c8..dce7150 100644
--- a/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java
+++ b/internals/testsupport-internal/src/main/java/org/apache/polygene/test/internal/DockerRule.java
@@ -25,11 +25,11 @@ import org.junit.runners.model.Statement;
 import pl.domzal.junit.docker.rule.DockerRuleBuilder;
 import pl.domzal.junit.docker.rule.WaitFor;
 
-import static org.junit.Assume.assumeNotNull;
+import static org.junit.Assume.assumeFalse;
 
 public class DockerRule implements TestRule
 {
-    private final String dockerHost = System.getenv( "DOCKER_HOST" );
+    private final boolean dockerDisabled = Boolean.valueOf( System.getProperty( "DOCKER_DISABLED",
"false" ) );
     private final pl.domzal.junit.docker.rule.DockerRule dockerRule;
 
     public DockerRule( String image, int... portsToWaitFor )
@@ -39,7 +39,7 @@ public class DockerRule implements TestRule
 
     public DockerRule( String image, Map<String, String> environment, int... portsToWaitFor
)
     {
-        if( dockerHost == null )
+        if( dockerDisabled )
         {
             dockerRule = null;
         }
@@ -58,7 +58,7 @@ public class DockerRule implements TestRule
     @Override
     public Statement apply( Statement base, Description description )
     {
-        assumeNotNull( dockerHost );
+        assumeFalse( dockerDisabled );
         return dockerRule.apply( base, description );
     }
 


Mime
View raw message