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

Fix intermittent build failure, ensuring docker test output is still usable #4692

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions buildSrc/src/main/groovy/Docker.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,8 @@ class Docker {
// Single task with explicit inputs and outputs, to let gradle detect if it is up to date, and let docker
// cache what it can.

// Sync outputs to the desired location
def syncAfterBuildAndRun = project.tasks.register("${taskName}Sync", Sync) { sync ->
sync.with {
// run the provided closure first
cfg.copyOut.execute(sync)

// then set the from location
from dockerCopyLocation
}
}

// Note that if "showLogsOnSuccess" is true, we don't run this way, since that would omit logs when cached.
return project.tasks.register(taskName, CombinedDockerRunTask) { cacheableDockerTask ->
def buildAndRun = project.tasks.register("${taskName}Run", CombinedDockerRunTask) { cacheableDockerTask ->
cacheableDockerTask.with {
// mark inputs, depend on dockerfile task and input sync task
inputs.files(makeImage.get().outputs.files)
Expand Down Expand Up @@ -345,7 +334,36 @@ class Docker {

remotePath.set(cfg.containerOutPath)
outputDir.set(project.file(dockerCopyLocation))
finalizedBy syncAfterBuildAndRun
}
}

// Handle copying failure. This is now distinct from the "actual" Sync task that depends directly
// on the CombinedDockerRunTask.
def syncAfterFail = project.tasks.register("${taskName}SyncAfterFail", Sync) { sync ->
sync.with {
// run the provided closure first
cfg.copyOut.execute(sync)

// then set the from location
from dockerCopyLocation

onlyIf { buildAndRun.get().state.failure != null }
}
}
buildAndRun.configure {t ->
t.finalizedBy syncAfterFail
}

// Sync outputs to the desired location
return project.tasks.register(taskName, Sync) { sync ->
sync.with {
dependsOn buildAndRun

// run the provided closure first
cfg.copyOut.execute(sync)

// then set the from location
from dockerCopyLocation
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class CombinedDockerRunTask extends AbstractDockerRemoteApiTask {
throw new GradleException("${failedMessage}, check logs for details")
}
}

} finally {
if (containerId == null) {
return;
Expand Down