use of com.bmuschko.gradle.docker.DockerExtension in project alfresco-docker-gradle-plugin by xenit-eu.
the class DockerConfigPlugin method apply.
@Override
public void apply(Project project) {
GradleVersionRequirement.atLeast("5.6", "use the " + PLUGIN_ID + " plugin");
// Set up deprecation warnings
Deprecation.setStartParameter(project.getGradle().getStartParameter());
project.getGradle().projectsEvaluated(g -> {
g.buildFinished(buildResult -> {
Deprecation.printSummary();
});
});
// Rest of the configuration
DockerConfig dockerConfig = new DockerConfig(project);
project.getPluginManager().apply(DockerRemoteApiPlugin.class);
DockerExtension dockerExtension = project.getExtensions().getByType(DockerExtension.class);
if (dockerConfig.getUrl() != null) {
dockerExtension.getUrl().set(dockerConfig.getUrl());
}
if (dockerConfig.getCertPath() != null) {
dockerExtension.getCertPath().set(new File(dockerConfig.getCertPath()));
}
if (dockerConfig.getRegistryUrl() != null) {
dockerExtension.registryCredentials(registryCredentials -> {
registryCredentials.getUrl().set(dockerConfig.getRegistryUrl());
registryCredentials.getUsername().set(dockerConfig.getRegistryUsername());
registryCredentials.getPassword().set(dockerConfig.getRegistryPassword());
});
}
project.getPlugins().withType(DockerComposePlugin.class, dockerComposePlugin -> {
ComposeSettings composeExtension = dockerComposePlugin.getComposeSettings();
composeExtension.getUseComposeFiles().add("docker-compose.yml");
composeExtension.getEnvironment().put("DOCKER_HOST", dockerExtension.getUrl().get());
composeExtension.getEnvironment().put("SERVICES_HOST", dockerConfig.getExposeIp());
composeExtension.getEnvironment().put("DOCKER_IP", dockerConfig.getExposeIp());
if (dockerConfig.getCertPath() != null) {
composeExtension.getEnvironment().put("DOCKER_CERT_PATH", dockerConfig.getCertPath());
}
});
project.getPlugins().withType(com.avast.gradle.dockercompose.DockerComposePlugin.class, dockerComposePlugin -> {
throw new GradleException("The com.avast.gradle.docker-compose plugin does not work together with " + PLUGIN_ID + ".\n" + "Use " + DockerComposePlugin.PLUGIN_ID + " for docker-compose functionality.");
});
if (project.getGradle().getStartParameter().isOffline()) {
// We need to create a separate task to disable pull on DockerBuildImage tasks, because in a doFirst block, providers are already finalized.
TaskProvider<DefaultTask> disableDockerBuildImagePull = project.getTasks().register("_" + PLUGIN_ID + "_disableDockerBuildImagePull_" + UUID.randomUUID(), DefaultTask.class, task -> {
task.setDescription("[" + PLUGIN_ID + " internal] Disables pull flag on DockerBuildImage tasks when Gradle runs in offline mode.");
task.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
project.getTasks().withType(DockerBuildImage.class).configureEach(dockerBuildImage -> {
if (dockerBuildImage.getPull().get()) {
dockerBuildImage.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
LOGGER.warn("Gradle is running in offline mode, automatic pull has been disabled.");
}
});
dockerBuildImage.getPull().set(false);
}
});
}
});
});
project.getTasks().withType(DockerBuildImage.class).configureEach(dockerBuildImage -> {
dockerBuildImage.dependsOn(disableDockerBuildImagePull);
});
}
}
Aggregations