use of org.curioswitch.gradle.plugins.curioserver.ServerExtension in project curiostack by curioswitch.
the class GcloudPlugin method apply.
@Override
public void apply(Project project) {
var config = GcloudExtension.create(project);
project.getExtensions().getExtraProperties().set("keys", new KmsKeyDecrypter(project));
project.getPlugins().withType(ToolDownloaderPlugin.class, plugin -> plugin.registerToolIfAbsent("gcloud", tool -> {
tool.getArtifact().set("google-cloud-sdk");
tool.getVersion().set(ToolDependencies.getGcloudVersion(project));
tool.getBaseUrl().set("https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/");
tool.getArtifactPattern().set("[artifact]-[revision]-[classifier].[ext]");
tool.getPathSubDirs().add("google-cloud-sdk/bin");
var osClassifiers = tool.getOsClassifiers();
osClassifiers.getLinux().set("linux-x86_64");
osClassifiers.getMac().set("darwin-x86_64");
osClassifiers.getWindows().set("windows-x86_64");
}));
DownloadToolUtil.getSetupTask(project, "gcloud").configure(t -> t.dependsOn(DownloadToolUtil.getSetupTask(project, "miniconda-build")));
project.getPlugins().withType(CondaPlugin.class, plugin -> plugin.getCondas().withType(ModifiableCondaExtension.class).named("miniconda-build").configure(conda -> {
conda.getPackages().add("lz4-c");
conda.getPythonPackages().add("crcmod");
}));
ExtraPropertiesExtension ext = project.getExtensions().getExtraProperties();
ext.set(GcloudTask.class.getSimpleName(), GcloudTask.class);
project.getTasks().addRule(new Rule() {
@Override
public String getDescription() {
return "Pattern: \"gcloud_<command>\": Executes a Gcloud command.";
}
@Override
public void apply(String taskName) {
if (taskName.startsWith("gcloud_")) {
GcloudTask task = project.getTasks().create(taskName, GcloudTask.class);
List<String> tokens = ImmutableList.copyOf(taskName.split("_"));
task.setArgs(tokens.subList(1, tokens.size()));
}
}
});
var gcloudSetup = project.getTasks().register("gcloudSetup");
var gcloudInstallComponents = project.getTasks().register("gcloudInstallComponents", GcloudTask.class, t -> t.setArgs(ImmutableList.of("components", "install", "app-engine-python", "beta", "kubectl", "docker-credential-gcr")));
var gcloudLoginToCluster = project.getTasks().register("gcloudLoginToCluster", GcloudTask.class, t -> t.args(ImmutableList.of("container", "clusters", "get-credentials", config.getClusterName(), config.getClusterRegion().map(value -> System.getenv("CLOUDSDK_COMPUTE_ZONE") != null ? "--zone=" + System.getenv("CLOUDSDK_COMPUTE_ZONE") : "--region=" + value))));
project.allprojects(subproj -> subproj.getTasks().withType(KubectlTask.class).configureEach(t -> {
t.dependsOn(gcloudInstallComponents, gcloudLoginToCluster);
}));
project.getTasks().withType(UploadCodeCovCacheTask.class).configureEach(t -> t.setDest(config.getBuildCacheStorageBucket().map(value -> "gs://" + value + "/cloudbuild-cache-codecov.tar.gz")));
project.getTasks().withType(FetchCodeCovCacheTask.class).configureEach(t -> t.setSrc(config.getBuildCacheStorageBucket().map(value -> "gs://" + value + "/cloudbuild-cache-codecov.tar.gz")));
project.allprojects(proj -> proj.getPlugins().withType(CurioServerPlugin.class, unused -> {
ServerExtension server = proj.getExtensions().getByType(ServerExtension.class);
server.getImagePrefix().set(config.getContainerRegistry().map(value -> value + "/" + config.getClusterProject().get() + "/"));
}));
project.afterEvaluate(p -> {
if (System.getenv("CI") != null && project.getGradle().getStartParameter().isBuildCacheEnabled()) {
project.getPlugins().withType(ToolDownloaderPlugin.class).all(plugin -> plugin.tools().all(tool -> {
Provider<String> toolCachePath = config.getBuildCacheStorageBucket().map(value -> "gs://" + value + "/cloudbuild-cache-tool-" + tool.getName() + ".tar.lz4");
var downloadCache = project.getTasks().register("toolsFetchCache" + TaskUtil.toTaskSuffix(tool.getName()), FetchToolCacheTask.class, t -> {
t.setSrc(toolCachePath);
t.onlyIf(unused -> !Files.exists(DownloadedToolManager.get(project).getCuriostackDir().resolve(tool.getName())));
});
var uploadCache = project.getTasks().register("toolsUploadCache" + TaskUtil.toTaskSuffix(tool.getName()), UploadToolCacheTask.class, t -> {
t.setDest(toolCachePath);
t.srcPath(tool.getName());
tool.getAdditionalCachedDirs().get().forEach(t::srcPath);
});
DownloadToolUtil.getDownloadTask(project, tool.getName()).configure(t -> t.dependsOn(downloadCache));
// We disable cache upload by default and only enable it if a
// setup task was run.
uploadCache.configure(uc -> uc.setOnlyIf(unused -> "true".equals(System.getenv("CI_MASTER")) && DownloadToolUtil.getSetupTask(project, tool.getName()).get().getDidWork()));
project.getPlugins().withType(CurioGenericCiPlugin.class, unused -> project.getTasks().named("continuousBuild").configure(cb -> cb.finalizedBy(uploadCache)));
}));
}
gcloudSetup.configure(t -> t.dependsOn(gcloudInstallComponents));
});
addGenerateCloudBuildTask(project, config);
}
Aggregations