Search in sources :

Example 1 with DockerBuildService

use of io.fabric8.maven.core.service.kubernetes.DockerBuildService in project fabric8-maven-plugin by fabric8io.

the class DockerBuildServiceTest method testSuccessfulBuild.

@Test
public void testSuccessfulBuild() throws Exception {
    new Expectations() {

        {
            hub.getBuildService();
            result = buildService;
        }
    };
    final BuildService.BuildContext context = new BuildService.BuildContext.Builder().build();
    final io.fabric8.maven.core.service.BuildService.BuildServiceConfig config = new io.fabric8.maven.core.service.BuildService.BuildServiceConfig.Builder().dockerBuildContext(context).build();
    final String imageName = "image-name";
    final ImageConfiguration image = new ImageConfiguration.Builder().name(imageName).buildConfig(new BuildImageConfiguration.Builder().from("from").build()).build();
    DockerBuildService service = new DockerBuildService(hub, config);
    service.build(image);
    new FullVerificationsInOrder() {

        {
            buildService.buildImage(image, context);
            buildService.tagImage(imageName, image);
        }
    };
}
Also used : Expectations(mockit.Expectations) BuildService(io.fabric8.maven.docker.service.BuildService) FullVerificationsInOrder(mockit.FullVerificationsInOrder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Example 2 with DockerBuildService

use of io.fabric8.maven.core.service.kubernetes.DockerBuildService in project fabric8-maven-plugin by fabric8io.

the class Fabric8ServiceHub method init.

private void init() {
    Objects.requireNonNull(clusterAccess, "clusterAccess");
    Objects.requireNonNull(log, "log");
    this.resolvedMode = clusterAccess.resolvePlatformMode(platformMode, log);
    if (resolvedMode != PlatformMode.kubernetes && resolvedMode != PlatformMode.openshift) {
        throw new IllegalArgumentException("Unknown platform mode " + platformMode + " resolved as " + resolvedMode);
    }
    this.client = clusterAccess.createDefaultClient(log);
    if (this.controller == null) {
        this.controller = new Controller(this.client);
        this.controller.setThrowExceptionOnError(true);
    }
    // Lazily building services
    this.services.putIfAbsent(ClientToolsService.class, new LazyBuilder<ClientToolsService>() {

        @Override
        protected ClientToolsService build() {
            return new ClientToolsService(controller, log);
        }
    });
    this.services.putIfAbsent(PortForwardService.class, new LazyBuilder<PortForwardService>() {

        @Override
        protected PortForwardService build() {
            return new PortForwardService(getClientToolsService(), log, client);
        }
    });
    this.services.putIfAbsent(BuildService.class, new LazyBuilder<BuildService>() {

        @Override
        protected BuildService build() {
            BuildService buildService;
            // Creating platform-dependent services
            if (resolvedMode == PlatformMode.openshift) {
                // Openshift services
                buildService = new OpenshiftBuildService((OpenShiftClient) client, log, dockerServiceHub, buildServiceConfig);
            } else {
                // Kubernetes services
                buildService = new DockerBuildService(dockerServiceHub, buildServiceConfig);
            }
            return buildService;
        }
    });
    this.services.putIfAbsent(ArtifactResolverService.class, new LazyBuilder<ArtifactResolverService>() {

        @Override
        protected ArtifactResolverService build() {
            return new ArtifactResolverServiceMavenImpl(repositorySystem, mavenProject);
        }
    });
}
Also used : OpenshiftBuildService(io.fabric8.maven.core.service.openshift.OpenshiftBuildService) DockerBuildService(io.fabric8.maven.core.service.kubernetes.DockerBuildService) DockerBuildService(io.fabric8.maven.core.service.kubernetes.DockerBuildService) OpenshiftBuildService(io.fabric8.maven.core.service.openshift.OpenshiftBuildService) Controller(io.fabric8.kubernetes.api.Controller)

Example 3 with DockerBuildService

use of io.fabric8.maven.core.service.kubernetes.DockerBuildService in project fabric8-maven-plugin by fabric8io.

the class DockerBuildService method build.

@Override
public void build(ImageConfiguration imageConfig) throws Fabric8ServiceException {
    io.fabric8.maven.docker.service.BuildService dockerBuildService = dockerServiceHub.getBuildService();
    io.fabric8.maven.docker.service.BuildService.BuildContext dockerBuildContext = config.getDockerBuildContext();
    try {
        dockerBuildService.buildImage(imageConfig, dockerBuildContext);
        // Assume we always want to tag
        dockerBuildService.tagImage(imageConfig.getName(), imageConfig);
    } catch (Exception ex) {
        throw new Fabric8ServiceException("Error while trying to build the image", ex);
    }
}
Also used : Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) BuildService(io.fabric8.maven.core.service.BuildService) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException)

Example 4 with DockerBuildService

use of io.fabric8.maven.core.service.kubernetes.DockerBuildService in project fabric8-maven-plugin by fabric8io.

the class Fabric8ServiceHubTest method testObtainBuildService.

@Test
public void testObtainBuildService() {
    Fabric8ServiceHub hub = new Fabric8ServiceHub.Builder().clusterAccess(clusterAccess).log(logger).platformMode(PlatformMode.kubernetes).dockerServiceHub(dockerServiceHub).buildServiceConfig(buildServiceConfig).build();
    BuildService buildService = hub.getBuildService();
    assertNotNull(buildService);
    assertTrue(buildService instanceof DockerBuildService);
}
Also used : OpenshiftBuildService(io.fabric8.maven.core.service.openshift.OpenshiftBuildService) DockerBuildService(io.fabric8.maven.core.service.kubernetes.DockerBuildService) DockerBuildService(io.fabric8.maven.core.service.kubernetes.DockerBuildService) Test(org.junit.Test)

Aggregations

DockerBuildService (io.fabric8.maven.core.service.kubernetes.DockerBuildService)2 OpenshiftBuildService (io.fabric8.maven.core.service.openshift.OpenshiftBuildService)2 Test (org.junit.Test)2 Controller (io.fabric8.kubernetes.api.Controller)1 BuildService (io.fabric8.maven.core.service.BuildService)1 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1 BuildService (io.fabric8.maven.docker.service.BuildService)1 Expectations (mockit.Expectations)1 FullVerificationsInOrder (mockit.FullVerificationsInOrder)1