Search in sources :

Example 21 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class SourceMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
    MojoParameters params = createMojoParameters();
    List<ImageConfiguration> imageConfigs = new ArrayList<>();
    for (ImageConfiguration imageConfig : getResolvedImages()) {
        BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
        if (buildConfig != null) {
            if (buildConfig.skip()) {
                log.info("%s: Skipped creating source", imageConfig.getDescription());
            } else {
                imageConfigs.add(imageConfig);
            }
        }
    }
    if (sourceMode == BuildImageSelectMode.first && imageConfigs.size() > 0) {
        ImageConfiguration imageConfig = imageConfigs.get(0);
        File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
        projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(null), dockerTar);
    } else {
        for (ImageConfiguration imageConfig : imageConfigs) {
            File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
            String alias = imageConfig.getAlias();
            if (alias == null) {
                throw new IllegalArgumentException("Image " + imageConfig.getDescription() + " must have an 'alias' configured to be " + "used as a classifier for attaching a docker build tar as source to the maven build");
            }
            projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(alias), dockerTar);
        }
    }
}
Also used : MojoParameters(io.fabric8.maven.docker.util.MojoParameters) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 22 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class BuildMojo method buildAndTag.

protected void buildAndTag(ServiceHub hub, ImageConfiguration imageConfig) throws MojoExecutionException, IOException {
    EnvUtil.storeTimestamp(getBuildTimestampFile(), getBuildTimestamp());
    BuildService.BuildContext buildContext = getBuildContext();
    ImagePullManager pullManager = getImagePullManager(determinePullPolicy(imageConfig.getBuildConfiguration()), autoPull);
    proceedWithBuildProcess(hub, buildContext, imageConfig, pullManager);
}
Also used : JibBuildService(io.fabric8.maven.docker.service.JibBuildService) BuildService(io.fabric8.maven.docker.service.BuildService) ImagePullManager(io.fabric8.maven.docker.service.ImagePullManager)

Example 23 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class LogsMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, DockerAccessException {
    QueryService queryService = hub.getQueryService();
    LogDispatcher logDispatcher = getLogDispatcher(hub);
    for (ImageConfiguration image : getResolvedImages()) {
        String imageName = image.getName();
        if (logAll) {
            for (Container container : queryService.getContainersForImage(imageName, false)) {
                doLogging(logDispatcher, image, container.getId());
            }
        } else {
            Container container = queryService.getLatestContainerForImage(imageName, false);
            if (container != null) {
                doLogging(logDispatcher, image, container.getId());
            }
        }
    }
    if (follow) {
        // Block forever ....
        waitForEver();
    }
}
Also used : Container(io.fabric8.maven.docker.model.Container) QueryService(io.fabric8.maven.docker.service.QueryService) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher)

Example 24 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class VolumeCreateMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub serviceHub) throws DockerAccessException, MojoExecutionException {
    if (getVolumes() == null) {
        log.info("No volume configuration found.");
        return;
    }
    VolumeService volService = serviceHub.getVolumeService();
    for (VolumeConfiguration volume : getVolumes()) {
        log.info("Creating volume '%s'", volume.getName());
        volService.createVolume(volume);
    }
}
Also used : VolumeService(io.fabric8.maven.docker.service.VolumeService) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration)

Example 25 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class JibBuildServiceTest method testPushWithConfiguration.

@Test
public void testPushWithConfiguration(@Mocked JibServiceUtil jibServiceUtil) throws Exception {
    // Given
    File projectBaseDir = Files.createTempDirectory("test").toFile();
    setupServiceHubExpectations(projectBaseDir);
    final ImageConfiguration imageConfiguration = getImageConfiguration();
    final RegistryService.RegistryConfig registryConfig = new RegistryService.RegistryConfig.Builder().authConfigFactory(authConfigFactory).build();
    mockAuthConfigFactory(true, registryConfig);
    // When
    new JibBuildService(serviceHub, params, logger).push(Collections.singletonList(imageConfiguration), 1, registryConfig, false);
    // Then
    // @formatter:off
    new Verifications() {

        {
            JibServiceUtil.jibPush(imageConfiguration, Credential.from("testuserpush", "testpass"), (File) any, logger);
            times = 1;
        }
    };
// @formatter:on
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Verifications(mockit.Verifications) File(java.io.File) Test(org.junit.Test)

Aggregations

ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 File (java.io.File)8 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)5 VolumeConfiguration (io.fabric8.maven.docker.config.VolumeConfiguration)5 QueryService (io.fabric8.maven.docker.service.QueryService)5 RunService (io.fabric8.maven.docker.service.RunService)5 IOException (java.io.IOException)5 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)4 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)4 Test (org.junit.Test)4 PortMapping (io.fabric8.maven.docker.access.PortMapping)3 RunVolumeConfiguration (io.fabric8.maven.docker.config.RunVolumeConfiguration)3 LogOutputSpecFactory (io.fabric8.maven.docker.log.LogOutputSpecFactory)3 BuildService (io.fabric8.maven.docker.service.BuildService)3 JibBuildService (io.fabric8.maven.docker.service.JibBuildService)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 Fabric8ServiceHub (io.fabric8.maven.core.service.Fabric8ServiceHub)2 DockerAccess (io.fabric8.maven.docker.access.DockerAccess)2