use of dev.snowdrop.buildpack.Buildpack in project quarkus by quarkusio.
the class BuildpackProcessor method runBuildpackBuild.
private String runBuildpackBuild(BuildpackConfig buildpackConfig, ContainerImageInfoBuildItem containerImage, ContainerImageConfig containerImageConfig, Optional<ContainerImagePushRequestBuildItem> pushRequest, OutputTargetBuildItem outputTarget, boolean isNativeBuild) {
Map<ProjectDirs, Path> dirs = getPaths(outputTarget);
log.debug("Using target dir of " + dirs.get(ProjectDirs.TARGET));
log.debug("Using source root of " + dirs.get(ProjectDirs.SOURCE));
log.debug("Using project root of " + dirs.get(ProjectDirs.ROOT));
String targetImageName = containerImage.getImage().toString();
log.debug("Using Destination image of " + targetImageName);
Map<String, String> envMap = new HashMap<>(buildpackConfig.builderEnv);
if (!envMap.isEmpty()) {
log.info("Using builder environment of " + envMap);
}
// Let's explicitly disable build and push during the build to avoid inception style builds
envMap.put(QUARKUS_CONTAINER_IMAGE_BUILD, "false");
envMap.put(QUARKUS_CONTAINER_IMAGE_PUSH, "false");
log.info("Initiating Buildpack build");
Buildpack buildpack = Buildpack.builder().addNewFileContent(dirs.get(ProjectDirs.ROOT).toFile()).withFinalImage(targetImageName).withEnvironment(envMap).withLogLevel(buildpackConfig.logLevel).withPullTimeoutSeconds(buildpackConfig.pullTimeoutSeconds).withLogger(new BuildpackLogger()).accept(BuildpackBuilder.class, b -> {
if (isNativeBuild) {
buildpackConfig.nativeBuilderImage.ifPresent(i -> b.withBuilderImage(i));
} else {
buildpackConfig.jvmBuilderImage.ifPresent(i -> b.withBuilderImage(i));
}
if (buildpackConfig.runImage.isPresent()) {
log.info("Using Run image of " + buildpackConfig.runImage.get());
b.withRunImage(buildpackConfig.runImage.get());
}
if (buildpackConfig.dockerHost.isPresent()) {
log.info("Using DockerHost of " + buildpackConfig.dockerHost.get());
b.withDockerHost(buildpackConfig.dockerHost.get());
}
}).build();
if (buildpack.getExitCode() != 0) {
throw new IllegalStateException("Buildpack build failed");
}
log.info("Buildpack build complete");
if (containerImageConfig.isPushExplicitlyEnabled() || pushRequest.isPresent()) {
if (!containerImageConfig.registry.isPresent()) {
log.info("No container image registry was set, so 'docker.io' will be used");
}
AuthConfig authConfig = new AuthConfig();
authConfig.withRegistryAddress(containerImageConfig.registry.orElse("docker.io"));
containerImageConfig.username.ifPresent(u -> authConfig.withUsername(u));
containerImageConfig.password.ifPresent(p -> authConfig.withPassword(p));
log.info("Pushing image to " + authConfig.getRegistryAddress());
Stream.concat(Stream.of(containerImage.getImage()), containerImage.getAdditionalImageTags().stream()).forEach(i -> {
ResultCallback.Adapter<PushResponseItem> callback = buildpack.getDockerClient().pushImageCmd(i).start();
try {
callback.awaitCompletion();
log.info("Push complete");
} catch (Exception e) {
throw new IllegalStateException(e);
}
});
}
return targetImageName;
}
Aggregations