Search in sources :

Example 1 with JibHelper

use of org.talend.sdk.component.maven.docker.JibHelper in project component-runtime by Talend.

the class ImageM2Mojo method doExecute.

@Override
public void doExecute() throws MojoExecutionException {
    try (final JibHelper jibHelper = new JibHelper(getLog(), project.getBuild().getDirectory(), layersCacheDirectory, repository, dockerEnvironment, dockerExecutable, laggyPushWorkaround)) {
        jibHelper.prepare(project.getArtifactId(), project.getVersion(), project.getProperties(), fromImage, toImage, creationTime, workingDirectory, this::createWorkingDirectory, environment, labels);
        addLayers(jibHelper.getBuilder());
        if (ports != null) {
            ports.stream().map(Port::tcp).forEach(jibHelper.getBuilder()::addExposedPort);
        }
        getLog().info("Creating the image (can be long)");
        jibHelper.build("Talend Image Maven Plugin", () -> ofNullable(session.getSettings().getServer(repository)).map(it -> settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(it))).map(SettingsDecryptionResult::getServer).orElse(null));
        if (versionProperty != null) {
            jibHelper.setProperties(project, versionProperty);
        }
    } catch (final Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        if (m2Root.exists()) {
            try {
                Files.walkFileTree(m2Root.toPath(), new SimpleFileVisitor<Path>() {

                    @Override
                    public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
                        file.toFile().delete();
                        return super.visitFile(file, attrs);
                    }

                    @Override
                    public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
                        dir.toFile().delete();
                        return super.postVisitDirectory(dir, exc);
                    }
                });
            } catch (final IOException e) {
                getLog().warn(e.getMessage(), e);
            }
        }
    }
}
Also used : TEST(org.apache.maven.plugins.annotations.ResolutionScope.TEST) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Date(java.util.Date) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) MAX_VALUE(java.lang.Long.MAX_VALUE) Component(org.apache.maven.plugins.annotations.Component) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) Parameter(org.apache.maven.plugins.annotations.Parameter) Port(com.google.cloud.tools.jib.api.buildplan.Port) Mojo(org.apache.maven.plugins.annotations.Mojo) LayerConfiguration(com.google.cloud.tools.jib.api.LayerConfiguration) TALEND_INTERNAL(org.talend.sdk.component.maven.api.Audience.Type.TALEND_INTERNAL) Map(java.util.Map) Comparator.comparing(java.util.Comparator.comparing) ENGLISH(java.util.Locale.ENGLISH) Path(java.nio.file.Path) JibHelper(org.talend.sdk.component.maven.docker.JibHelper) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) MavenSession(org.apache.maven.execution.MavenSession) Audience(org.talend.sdk.component.maven.api.Audience) Files(java.nio.file.Files) Optional.ofNullable(java.util.Optional.ofNullable) SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) Set(java.util.Set) Artifact(org.eclipse.aether.artifact.Artifact) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Instant(java.time.Instant) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) Objects(java.util.Objects) PACKAGE(org.apache.maven.plugins.annotations.LifecyclePhase.PACKAGE) FileVisitResult(java.nio.file.FileVisitResult) AtomicLong(java.util.concurrent.atomic.AtomicLong) Collectors.toList(java.util.stream.Collectors.toList) AbstractMap(java.util.AbstractMap) List(java.util.List) Stream(java.util.stream.Stream) Data(lombok.Data) Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) JibHelper(org.talend.sdk.component.maven.docker.JibHelper) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) FileVisitResult(java.nio.file.FileVisitResult) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) IOException(java.io.IOException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 2 with JibHelper

use of org.talend.sdk.component.maven.docker.JibHelper in project component-runtime by Talend.

the class SingerMojo method doExecute.

private void doExecute() throws MojoExecutionException {
    try (final JibHelper jibHelper = new JibHelper(getLog(), project.getBuild().getDirectory(), layersCacheDirectory, repository, dockerEnvironment, dockerExecutable, laggyPushWorkaround)) {
        jibHelper.prepare(project.getArtifactId(), project.getVersion(), project.getProperties(), fromImage, toImage, creationTime, workingDirectory, () -> "/opt/talend/singer/component/" + project.getArtifactId(), environment, labels);
        configure(jibHelper);
        getLog().info("Creating the image (can be long)");
        jibHelper.build("Talend Singer Maven Plugin", () -> ofNullable(session.getSettings().getServer(repository)).map(it -> settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(it))).map(SettingsDecryptionResult::getServer).orElse(null));
        if (versionProperty != null) {
            jibHelper.setProperties(project, versionProperty);
        }
    } catch (final Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) Component(org.apache.maven.plugins.annotations.Component) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) Parameter(org.apache.maven.plugins.annotations.Parameter) DEFAULT_FILE_PERMISSIONS(com.google.cloud.tools.jib.api.buildplan.FilePermissions.DEFAULT_FILE_PERMISSIONS) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) Mojo(org.apache.maven.plugins.annotations.Mojo) LayerConfiguration(com.google.cloud.tools.jib.api.LayerConfiguration) DEFAULT_FOLDER_PERMISSIONS(com.google.cloud.tools.jib.api.buildplan.FilePermissions.DEFAULT_FOLDER_PERMISSIONS) MavenProject(org.apache.maven.project.MavenProject) TALEND_INTERNAL(org.talend.sdk.component.maven.api.Audience.Type.TALEND_INTERNAL) Map(java.util.Map) COMPILE_PLUS_RUNTIME(org.apache.maven.plugins.annotations.ResolutionScope.COMPILE_PLUS_RUNTIME) Path(java.nio.file.Path) JibHelper(org.talend.sdk.component.maven.docker.JibHelper) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) PathFactory(org.talend.sdk.component.path.PathFactory) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) MavenSession(org.apache.maven.execution.MavenSession) Audience(org.talend.sdk.component.maven.api.Audience) Files(java.nio.file.Files) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Optional.ofNullable(java.util.Optional.ofNullable) SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) Artifact(org.eclipse.aether.artifact.Artifact) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) PACKAGE(org.apache.maven.plugins.annotations.LifecyclePhase.PACKAGE) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) List(java.util.List) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) RepositorySystem(org.eclipse.aether.RepositorySystem) JibHelper(org.talend.sdk.component.maven.docker.JibHelper) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)2 LayerConfiguration (com.google.cloud.tools.jib.api.LayerConfiguration)2 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)2 File (java.io.File)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 List (java.util.List)2 Map (java.util.Map)2 Optional.ofNullable (java.util.Optional.ofNullable)2 MavenSession (org.apache.maven.execution.MavenSession)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 Component (org.apache.maven.plugins.annotations.Component)2 PACKAGE (org.apache.maven.plugins.annotations.LifecyclePhase.PACKAGE)2 Mojo (org.apache.maven.plugins.annotations.Mojo)2 Parameter (org.apache.maven.plugins.annotations.Parameter)2 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)2 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)2 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)2 Artifact (org.eclipse.aether.artifact.Artifact)2