forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate docker availability build logic (elastic#52548)
- Loading branch information
1 parent
f83d75d
commit c1a1047
Showing
17 changed files
with
650 additions
and
524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
buildSrc/src/main/java/org/elasticsearch/gradle/docker/DockerSupportPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.elasticsearch.gradle.docker; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.plugins.ExtraPropertiesExtension; | ||
import org.gradle.api.provider.Provider; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Plugin providing {@link DockerSupportService} for detecting Docker installations and determining requirements for Docker-based | ||
* Elasticsearch build tasks. | ||
* <p> | ||
* Additionally registers a task graph listener used to assert a compatible Docker installation exists when task requiring Docker are | ||
* scheduled for execution. Tasks may declare a Docker requirement via an extra property. If a compatible Docker installation is not | ||
* available on the build system an exception will be thrown prior to task execution. | ||
* | ||
* <pre> | ||
* task myDockerTask { | ||
* ext.requiresDocker = true | ||
* } | ||
* </pre> | ||
*/ | ||
public class DockerSupportPlugin implements Plugin<Project> { | ||
public static final String DOCKER_SUPPORT_SERVICE_NAME = "dockerSupportService"; | ||
public static final String DOCKER_ON_LINUX_EXCLUSIONS_FILE = ".ci/dockerOnLinuxExclusions"; | ||
public static final String REQUIRES_DOCKER_ATTRIBUTE = "requiresDocker"; | ||
|
||
@Override | ||
public void apply(Project project) { | ||
if (project != project.getRootProject()) { | ||
throw new IllegalStateException(this.getClass().getName() + " can only be applied to the root project."); | ||
} | ||
|
||
Provider<DockerSupportService> dockerSupportServiceProvider = project.getGradle() | ||
.getSharedServices() | ||
.registerIfAbsent( | ||
DOCKER_SUPPORT_SERVICE_NAME, | ||
DockerSupportService.class, | ||
spec -> spec.parameters( | ||
params -> { params.setExclusionsFile(new File(project.getRootDir(), DOCKER_ON_LINUX_EXCLUSIONS_FILE)); } | ||
) | ||
); | ||
|
||
// Ensure that if any tasks declare they require docker, we assert an available Docker installation exists | ||
project.getGradle().getTaskGraph().whenReady(graph -> { | ||
List<String> dockerTasks = graph.getAllTasks().stream().filter(task -> { | ||
ExtraPropertiesExtension ext = task.getExtensions().getExtraProperties(); | ||
return ext.has(REQUIRES_DOCKER_ATTRIBUTE) && (boolean) ext.get(REQUIRES_DOCKER_ATTRIBUTE); | ||
}).map(Task::getPath).collect(Collectors.toList()); | ||
|
||
if (dockerTasks.isEmpty() == false) { | ||
dockerSupportServiceProvider.get().failIfDockerUnavailable(dockerTasks); | ||
} | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.