Improve docker image building to use a stable working directory (#5433)

* add docker working directory parameters to image building
remove gitSha from "stable" buildId, to allow updates to a PR to kill pods

* split up chained null checks  onto separate lines

* fail build if docker image fails to build
force reporting task to run regardless of previous inputs

* add asterix to test name

* fix usages of System.hasProperty
This commit is contained in:
Stefano Franz 2019-09-05 13:23:41 +00:00 committed by GitHub
parent d10c74cbd0
commit 14b2882bd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerCommitImage import com.bmuschko.gradle.docker.tasks.image.DockerCommitImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
import com.bmuschko.gradle.docker.tasks.image.DockerTagImage import com.bmuschko.gradle.docker.tasks.image.DockerTagImage
import org.gradle.api.GradleException
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
@ -29,8 +30,9 @@ class ImageBuilding implements Plugin<Project> {
} }
DockerCreateContainer createBuildContainer = project.tasks.create('createBuildContainer', DockerCreateContainer) { DockerCreateContainer createBuildContainer = project.tasks.create('createBuildContainer', DockerCreateContainer) {
File gradleDir = new File((System.getProperty("java.io.tmpdir") + File.separator + "gradle")) File baseWorkingDir = new File(System.getProperty("docker.work.dir") ? System.getProperty("docker.work.dir") : System.getProperty("java.io.tmpdir"))
File mavenDir = new File((System.getProperty("java.io.tmpdir") + File.separator + "maven")) File gradleDir = new File(baseWorkingDir, "gradle")
File mavenDir = new File(baseWorkingDir, "maven")
doFirst { doFirst {
if (!gradleDir.exists()) { if (!gradleDir.exists()) {
gradleDir.mkdirs() gradleDir.mkdirs()
@ -59,6 +61,11 @@ class ImageBuilding implements Plugin<Project> {
DockerWaitContainer waitForBuildContainer = project.tasks.create('waitForBuildContainer', DockerWaitContainer) { DockerWaitContainer waitForBuildContainer = project.tasks.create('waitForBuildContainer', DockerWaitContainer) {
dependsOn logBuildContainer dependsOn logBuildContainer
targetContainerId createBuildContainer.getContainerId() targetContainerId createBuildContainer.getContainerId()
doLast {
if (getExitCode() != 0) {
throw new GradleException("Failed to build docker image, aborting build")
}
}
} }
DockerCommitImage commitBuildImageResult = project.tasks.create('commitBuildImageResult', DockerCommitImage) { DockerCommitImage commitBuildImageResult = project.tasks.create('commitBuildImageResult', DockerCommitImage) {

View File

@ -48,11 +48,12 @@ class KubesTest extends DefaultTask {
throw new GradleException("Apache Commons compress has not be loaded, this can happen if running from within intellj - please select \"delegate to gradle\" for build and test actions") throw new GradleException("Apache Commons compress has not be loaded, this can happen if running from within intellj - please select \"delegate to gradle\" for build and test actions")
} }
def gitSha = new BigInteger(project.hasProperty("corda_revision") ? project.property("corda_revision").toString() : "0", 36) def buildId = System.getProperty("buildId") ? System.getProperty("buildId") :
def buildId = System.hasProperty("buildId") ? System.getProperty("buildId") : "UNKNOWN_BUILD" (project.hasProperty("corda_revision") ? project.property("corda_revision").toString() : "0")
def currentUser = System.hasProperty("user.name") ? System.getProperty("user.name") : "UNKNOWN_USER"
String stableRunId = new BigInteger(64, new Random(gitSha.intValue() + buildId.hashCode() + currentUser.hashCode())).toString(36).toLowerCase() def currentUser = System.getProperty("user.name") ? System.getProperty("user.name") : "UNKNOWN_USER"
String stableRunId = new BigInteger(64, new Random(buildId.hashCode() + currentUser.hashCode())).toString(36).toLowerCase()
String suffix = new BigInteger(64, new Random()).toString(36).toLowerCase() String suffix = new BigInteger(64, new Random()).toString(36).toLowerCase()
io.fabric8.kubernetes.client.Config config = new io.fabric8.kubernetes.client.ConfigBuilder() io.fabric8.kubernetes.client.Config config = new io.fabric8.kubernetes.client.ConfigBuilder()

View File

@ -42,7 +42,6 @@ class ListTests extends DefaultTask {
FileCollection scanClassPath FileCollection scanClassPath
List<String> allTests List<String> allTests
def getTestsForFork(int fork, int forks, Integer seed) { def getTestsForFork(int fork, int forks, Integer seed) {
def gitSha = new BigInteger(project.hasProperty("corda_revision") ? project.property("corda_revision").toString() : "0", 36) def gitSha = new BigInteger(project.hasProperty("corda_revision") ? project.property("corda_revision").toString() : "0", 36)
if (fork >= forks) { if (fork >= forks) {
@ -66,7 +65,7 @@ class ListTests extends DefaultTask {
.collect { c -> (c.getSubclasses() + Collections.singletonList(c)) } .collect { c -> (c.getSubclasses() + Collections.singletonList(c)) }
.flatten() .flatten()
.collect { ClassInfo c -> .collect { ClassInfo c ->
c.getMethodInfo().filter { m -> m.hasAnnotation("org.junit.Test") }.collect { m -> c.name + "." + m.name } c.getMethodInfo().filter { m -> m.hasAnnotation("org.junit.Test") }.collect { m -> c.name + "." + m.name + "*" }
}.flatten() }.flatten()
.toSet() .toSet()

View File

@ -30,7 +30,6 @@ import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.testing.Test; import org.gradle.api.tasks.testing.Test;
import org.gradle.internal.logging.ConsoleRenderer; import org.gradle.internal.logging.ConsoleRenderer;
import org.gradle.internal.operations.BuildOperationExecutor; import org.gradle.internal.operations.BuildOperationExecutor;
import org.gradle.internal.operations.BuildOperationFailure;
import javax.inject.Inject; import javax.inject.Inject;
import java.io.File; import java.io.File;
@ -51,6 +50,11 @@ public class KubesReporting extends DefaultTask {
private List<Object> results = new ArrayList<Object>(); private List<Object> results = new ArrayList<Object>();
List<KubePodResult> podResults = new ArrayList<>(); List<KubePodResult> podResults = new ArrayList<>();
public KubesReporting() {
//force this task to always run, as it's responsible for parsing exit codes
getOutputs().upToDateWhen(t -> false);
}
@Inject @Inject
protected BuildOperationExecutor getBuildOperationExecutor() { protected BuildOperationExecutor getBuildOperationExecutor() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();