use of org.curioswitch.gradle.plugins.gcloud.tasks.GcloudTask in project curiostack by curioswitch.
the class CurioDatabasePlugin method addTasks.
private static void addTasks(Project project) {
ImmutableDatabaseExtension config = project.getExtensions().getByType(DatabaseExtension.class);
FlywayExtension flyway = project.getExtensions().getByType(FlywayExtension.class);
flyway.user = "dbadmin";
flyway.password = config.devAdminPassword();
flyway.schemas = new String[] { config.dbName() };
Dockerfile generateDevDbDockerfile = project.getTasks().create("generateDevDbDockerfile", Dockerfile.class);
generateDevDbDockerfile.from("mysql:5.7");
generateDevDbDockerfile.environmentVariable("MYSQL_DATABASE", config.dbName());
generateDevDbDockerfile.environmentVariable("MYSQL_USER", config.devAdminUser());
String devAdminPassword = config.devAdminPassword();
if (devAdminPassword != null) {
generateDevDbDockerfile.environmentVariable("MYSQL_PASSWORD", devAdminPassword);
// Root privilege needs to be exposed to create users other than MYSQL_USER.
generateDevDbDockerfile.environmentVariable("MYSQL_ROOT_PASSWORD", devAdminPassword);
}
DockerBuildImage buildDevDbDockerImage = project.getTasks().create("buildDevDbDockerImage", DockerBuildImage.class);
buildDevDbDockerImage.dependsOn(generateDevDbDockerfile);
buildDevDbDockerImage.setInputDir(generateDevDbDockerfile.getDestFile().getParentFile());
buildDevDbDockerImage.setTag(config.devDockerImageTag());
GcloudTask pushDevDbDockerImage = project.getTasks().create("pushDevDbDockerImage", GcloudTask.class);
pushDevDbDockerImage.dependsOn(buildDevDbDockerImage);
pushDevDbDockerImage.setArgs(ImmutableList.of("docker", "--", "push", config.devDockerImageTag()));
project.getTasks().create("deployDevDb", DeployDevDbPodTask.class).dependsOn(pushDevDbDockerImage);
}
use of org.curioswitch.gradle.plugins.gcloud.tasks.GcloudTask in project curiostack by curioswitch.
the class GcloudPlugin method apply.
@Override
public void apply(Project project) {
project.getExtensions().create(ImmutableGcloudExtension.NAME, GcloudExtension.class, project);
ExtraPropertiesExtension ext = project.getExtensions().getExtraProperties();
ext.set(GcloudTask.class.getSimpleName(), GcloudTask.class);
ext.set(RequestNamespaceCertTask.class.getSimpleName(), RequestNamespaceCertTask.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()));
}
}
});
project.afterEvaluate(p -> {
SetupTask downloadSdkTask = project.getTasks().create(SetupTask.NAME, SetupTask.class);
ImmutableGcloudExtension config = project.getExtensions().getByType(GcloudExtension.class);
downloadSdkTask.setEnabled(config.download());
project.allprojects(proj -> {
proj.getPlugins().withType(CurioServerPlugin.class, unused -> {
DeploymentExtension deployment = proj.getExtensions().getByType(DeploymentExtension.class);
deployment.setImagePrefix(config.containerRegistry() + "/" + config.clusterProject() + "/");
});
});
project.allprojects(proj -> {
proj.getPlugins().withType(CurioDatabasePlugin.class, unused -> {
DatabaseExtension database = proj.getExtensions().getByType(DatabaseExtension.class);
database.setDevDockerImagePrefix(config.containerRegistry() + "/" + config.clusterProject() + "/");
});
});
GcloudTask createClusterProject = project.getTasks().create("gcloudCreateClusterProject", GcloudTask.class);
createClusterProject.setArgs(ImmutableList.of("alpha", "projects", "create", config.clusterProject()));
// This task currently always fails, probably due to a bug in the SDK. It attempts
// to create the same repo twice, and the second one fails with an error...
GcloudTask createSourceRepo = project.getTasks().create("gcloudCreateSourceRepository", GcloudTask.class);
createSourceRepo.setArgs(ImmutableList.of("alpha", "source", "repos", "create", config.sourceRepository()));
GcloudTask createCluster = project.getTasks().create("gcloudCreateCluster", GcloudTask.class);
List<String> createClusterArgs = new ArrayList<>();
createClusterArgs.addAll(ImmutableList.of("beta", "container", "clusters", "create", config.clusterName(), "--zone", config.clusterZone(), "--additional-zones", String.join(",", config.clusterAdditionalZones()), "--num-nodes", Integer.toString(config.clusterNumNodesPerZone()), "--enable-autorepair", "--enable-autoupgrade", "--machine-type", config.clusterMachineType(), "--scopes", "cloud-platform,storage-rw,default,sql-admin," + "https://www.googleapis.com/auth/ndev.clouddns.readwrite"));
if (config.clusterKubernetesVersion() != null) {
createClusterArgs.add("--cluster-version");
createClusterArgs.add(config.clusterKubernetesVersion());
}
createCluster.setArgs(Collections.unmodifiableList(createClusterArgs));
GcloudTask loginToCluster = project.getTasks().create("gcloudLoginToCluster", GcloudTask.class);
loginToCluster.setArgs(ImmutableList.of("container", "clusters", "get-credentials", config.clusterName(), "--zone", config.clusterZone()));
project.getTasks().create("createBuildCacheBucket", CreateBuildCacheBucket.class);
GcloudTask installBetaComponents = project.getTasks().create("gcloudInstallBetaComponents", GcloudTask.class, t -> t.setArgs(ImmutableList.of("components", "install", "beta")));
installBetaComponents.dependsOn(downloadSdkTask);
GcloudTask installKubectl = project.getTasks().create("gcloudInstallKubectl", GcloudTask.class, t -> t.setArgs(ImmutableList.of("components", "install", "kubectl")));
installKubectl.dependsOn(downloadSdkTask);
project.getTasks().create("gcloudSetup", t -> t.dependsOn(downloadSdkTask, installBetaComponents, installKubectl));
});
addGenerateCloudBuildTask(project);
}
Aggregations