use of com.bmuschko.gradle.docker.tasks.image.DockerPushImage in project micronaut-gradle-plugin by micronaut-projects.
the class MicronautDockerPlugin method configureDockerBuild.
private Optional<TaskProvider<MicronautDockerfile>> configureDockerBuild(Project project, TaskContainer tasks, TaskProvider<BuildLayersTask> buildLayersTask, String imageName) {
File f = project.file(adaptTaskName("Dockerfile", imageName));
TaskProvider<? extends Dockerfile> dockerFileTask;
String dockerFileTaskName = adaptTaskName("dockerfile", imageName);
Provider<RegularFile> targetDockerFile = project.getLayout().getBuildDirectory().file("docker/" + imageName + "/Dockerfile");
if (f.exists()) {
dockerFileTask = tasks.register(dockerFileTaskName, Dockerfile.class, task -> {
task.setGroup(BasePlugin.BUILD_GROUP);
task.setDescription("Builds a Docker File for image " + imageName);
task.getDestFile().set(targetDockerFile);
task.instructionsFromTemplate(f);
});
} else {
dockerFileTask = tasks.register(dockerFileTaskName, MicronautDockerfile.class, task -> {
task.setGroup(BasePlugin.BUILD_GROUP);
task.setDescription("Builds a Docker File for image " + imageName);
task.getDestFile().set(targetDockerFile);
task.setupDockerfileInstructions();
});
}
TaskProvider<DockerBuildImage> dockerBuildTask = tasks.register(adaptTaskName("dockerBuild", imageName), DockerBuildImage.class, task -> {
task.dependsOn(buildLayersTask);
task.setGroup(BasePlugin.BUILD_GROUP);
task.setDescription("Builds a Docker Image (image " + imageName + ")");
if (f.exists()) {
task.getDockerFile().set(f);
} else {
task.getDockerFile().convention(dockerFileTask.flatMap(Dockerfile::getDestFile));
}
task.getImages().set(Collections.singletonList(project.getName()));
;
task.getInputDir().set(dockerFileTask.flatMap(Dockerfile::getDestDir));
});
TaskProvider<DockerPushImage> pushDockerImage = tasks.register(adaptTaskName("dockerPush", imageName), DockerPushImage.class, task -> {
task.dependsOn(dockerBuildTask);
task.setGroup("upload");
task.setDescription("Pushes the " + imageName + " Docker Image");
task.getImages().set(dockerBuildTask.flatMap(DockerBuildImage::getImages));
});
if (!f.exists()) {
return Optional.of((TaskProvider<MicronautDockerfile>) dockerFileTask);
}
return Optional.empty();
}
use of com.bmuschko.gradle.docker.tasks.image.DockerPushImage in project micronaut-gradle-plugin by micronaut-projects.
the class MicronautDockerPlugin method configureNativeDockerBuild.
private TaskProvider<NativeImageDockerfile> configureNativeDockerBuild(Project project, TaskContainer tasks, TaskProvider<BuildLayersTask> buildLayersTask, String imageName) {
File f = project.file(adaptTaskName("DockerfileNative", imageName));
TaskProvider<NativeImageDockerfile> dockerFileTask;
String dockerfileNativeTaskName = adaptTaskName("dockerfileNative", imageName);
Provider<RegularFile> targetDockerFile = project.getLayout().getBuildDirectory().file("docker/native-" + imageName + "/DockerfileNative");
if (f.exists()) {
dockerFileTask = tasks.register(dockerfileNativeTaskName, NativeImageDockerfile.class, task -> {
task.setGroup(BasePlugin.BUILD_GROUP);
task.setDescription("Builds a Native Docker File for image " + imageName);
task.instructionsFromTemplate(f);
task.getDestFile().set(targetDockerFile);
});
} else {
dockerFileTask = tasks.register(dockerfileNativeTaskName, NativeImageDockerfile.class, task -> {
task.setGroup(BasePlugin.BUILD_GROUP);
task.setDescription("Builds a Native Docker File for image " + imageName);
task.getDestFile().set(targetDockerFile);
});
}
TaskProvider<PrepareDockerContext> prepareContext = tasks.register(adaptTaskName("dockerPrepareContext", imageName), PrepareDockerContext.class, context -> {
// Because docker requires all files to be found in the build context we need to
// copy the configuration file directories into the build context
context.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("docker/native-" + imageName + "/config-dirs"));
context.getInputDirectories().from(dockerFileTask.map(t -> t.getNativeImageOptions().get().getConfigurationFileDirectories()));
});
TaskProvider<DockerBuildImage> dockerBuildTask = tasks.register(adaptTaskName("dockerBuildNative", imageName), DockerBuildImage.class, task -> {
task.setGroup(BasePlugin.BUILD_GROUP);
task.setDescription("Builds a Native Docker Image using GraalVM (image " + imageName + ")");
task.getInputs().files(prepareContext);
if (f.exists()) {
task.getDockerFile().set(f);
} else {
task.getDockerFile().convention(dockerFileTask.flatMap(Dockerfile::getDestFile));
}
task.getImages().set(Collections.singletonList(project.getName()));
task.dependsOn(buildLayersTask);
task.getInputDir().set(dockerFileTask.flatMap(Dockerfile::getDestDir));
});
TaskProvider<DockerPushImage> pushDockerImage = tasks.register(adaptTaskName("dockerPushNative", imageName), DockerPushImage.class);
pushDockerImage.configure(task -> {
task.dependsOn(dockerBuildTask);
task.setGroup("upload");
task.setDescription("Pushes a Native Docker Image using GraalVM (image " + imageName + ")");
task.getImages().set(dockerBuildTask.flatMap(DockerBuildImage::getImages));
});
project.afterEvaluate(p -> {
MicronautRuntime mr = PluginsHelper.resolveRuntime(p);
if (mr.isLambdaProvided()) {
TaskContainer taskContainer = p.getTasks();
TaskProvider<DockerCreateContainer> createLambdaContainer = taskContainer.register(adaptTaskName("createLambdaContainer", imageName), DockerCreateContainer.class, task -> {
task.dependsOn(dockerBuildTask);
task.targetImageId(dockerBuildTask.flatMap(DockerBuildImage::getImageId));
});
TaskProvider<DockerCopyFileFromContainer> buildLambdaZip = taskContainer.register(adaptTaskName("buildNativeLambda", imageName), DockerCopyFileFromContainer.class);
Provider<String> lambdaZip = project.getLayout().getBuildDirectory().dir("libs").map(dir -> dir.file(project.getName() + "-" + project.getVersion() + "-" + simpleNameOf("lambda", imageName) + ".zip").getAsFile().getAbsolutePath());
TaskProvider<DockerRemoveContainer> removeContainer = taskContainer.register(adaptTaskName("destroyLambdaContainer", imageName), DockerRemoveContainer.class);
removeContainer.configure(task -> {
task.mustRunAfter(buildLambdaZip);
task.getContainerId().set(createLambdaContainer.flatMap(DockerCreateContainer::getContainerId));
});
buildLambdaZip.configure(task -> {
task.dependsOn(createLambdaContainer);
task.getContainerId().set(createLambdaContainer.flatMap(DockerCreateContainer::getContainerId));
task.getRemotePath().set("/function/function.zip");
task.getHostPath().set(lambdaZip);
task.doLast(new Action<Task>() {
@Override
public void execute(Task task1) {
System.out.println("AWS Lambda ZIP built: " + lambdaZip.get());
}
});
task.finalizedBy(removeContainer);
});
}
});
return dockerFileTask;
}
use of com.bmuschko.gradle.docker.tasks.image.DockerPushImage in project alfresco-docker-gradle-plugin by xenit-eu.
the class DockerPlugin method apply.
@Override
public void apply(Project project) {
dockerExtension = project.getExtensions().create("dockerBuild", DockerExtension.class);
project.getPluginManager().apply(DockerConfigPlugin.class);
project.getPluginManager().apply(DockerAutotagPlugin.class);
project.getPluginManager().apply(DockerLabelPlugin.class);
Deprecation.whileDisabled(() -> {
project.getPluginManager().apply(DockerLegacyPlugin.class);
});
// Configure labeling from git
dockerExtension.getExtensions().getByType(DockerLabelExtension.class).fromGit();
// Configure an empty createDockerFile task that can be configured by the user.
// If no Dockerfile is present in the project, the Dockerfile created by this task
// will be used by buildDockerImage
TaskProvider<? extends Dockerfile> dockerfileProvider = project.getTasks().register("createDockerFile", DockerfileWithCopyTask.class, dockerfile -> {
dockerfile.setDescription("Create a Dockerfile");
dockerfile.setGroup(TASK_GROUP);
if (readPropertyFlag(project, WorkaroundDockerdConsecutiveCopyBugAction.FEATURE_FLAG)) {
dockerfile.doFirst("Mitigate Docker COPY bug", new WorkaroundDockerdConsecutiveCopyBugAction());
}
dockerfile.doFirst("Consolidate COPY instructions", new ConsolidateFileCopyInstructionsAction());
});
dockerExtension.getDockerFile().convention(dockerfileProvider.flatMap(Dockerfile::getDestFile));
// Fallback to using the Dockerfile in the root of the project if it exists
RegularFile detectedDockerFile = project.getLayout().getProjectDirectory().file("Dockerfile");
if (detectedDockerFile.getAsFile().exists()) {
dockerExtension.getDockerFile().convention(detectedDockerFile);
}
TaskProvider<? extends DockerBuildImage> buildImageProvider = project.getTasks().register("buildDockerImage", DockerBuildImage.class, buildImage -> {
buildImage.setDescription("Build the docker image");
buildImage.setGroup(TASK_GROUP);
buildImage.getPull().set(true);
buildImage.getRemove().set(true);
buildImage.getImages().set(dockerExtension.getImages());
buildImage.getDockerFile().set(dockerExtension.getDockerFile());
buildImage.getInputDir().set(buildImage.getDockerFile().flatMap(dockerFile -> {
DirectoryProperty directoryProperty = project.getObjects().directoryProperty();
directoryProperty.set(dockerFile.getAsFile().getParentFile());
return directoryProperty;
}));
});
project.getTasks().register("pushDockerImage", DockerPushImage.class, dockerPushImage -> {
dockerPushImage.setDescription("Push all docker image tags");
dockerPushImage.setGroup(TASK_GROUP);
dockerPushImage.getImages().set(buildImageProvider.flatMap(DockerBuildImage::getImages));
dockerPushImage.dependsOn(buildImageProvider);
});
project.getPlugins().withType(DockerComposePlugin.class, dockerComposePlugin -> {
dockerComposePlugin.getDockerComposeConvention().fromBuildImage("DOCKER_IMAGE", buildImageProvider);
});
}
Aggregations