Search in sources :

Example 1 with BuildContext

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

the class OpenshiftBuildServiceTest method testDockerBuildNoS2iSuffix.

@Test
public void testDockerBuildNoS2iSuffix() throws Exception {
    retryInMockServer(() -> {
        final BuildContext context = new BuildContext.Builder().registryConfig(new RegistryService.RegistryConfig.Builder().build()).build();
        final BuildService.BuildServiceConfig.Builder dockerConfig = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).dockerBuildContext(context).buildRecreateMode(BuildRecreateMode.none).openshiftBuildStrategy(OpenShiftBuildStrategy.docker).dockerMojoParameters(dockerMojoParameters);
        final BuildService.BuildServiceConfig config = dockerConfig.build();
        WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, false, false);
        OpenShiftMockServer mockServer = collector.getMockServer();
        DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.createOpenShiftClient();
        OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
        service.build(image);
        assertTrue(mockServer.getRequestCount() > 8);
        collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
        assertEquals("{\"apiVersion\":\"build.openshift.io/v1\",\"kind\":\"BuildConfig\",\"metadata\":{\"name\":\"myapp\"},\"spec\":{\"output\":{\"to\":{\"kind\":\"ImageStreamTag\",\"name\":\"myapp:latest\"}},\"source\":{\"type\":\"Binary\"},\"strategy\":{\"dockerStrategy\":{\"from\":{\"kind\":\"DockerImage\",\"name\":\"myapp\"}},\"type\":\"Docker\"}}}", collector.getBodies().get(1));
        collector.assertEventsNotRecorded("patch-build-config");
    });
}
Also used : OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) BuildContext(io.fabric8.maven.docker.service.BuildService.BuildContext) BuildService(io.fabric8.maven.core.service.BuildService) BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) Test(org.junit.Test)

Example 2 with BuildContext

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

the class WatchMojo method getWatcherContext.

public WatcherContext getWatcherContext() throws MojoExecutionException {
    try {
        BuildService.BuildContext buildContext = getBuildContext();
        WatchService.WatchContext watchContext = hub != null ? getWatchContext(hub) : null;
        return new WatcherContext.Builder().serviceHub(hub).buildContext(buildContext).watchContext(watchContext).config(extractWatcherConfig()).logger(log).newPodLogger(createLogger("[[C]][NEW][[C]] ")).oldPodLogger(createLogger("[[R]][OLD][[R]] ")).mode(mode).project(project).useProjectClasspath(useProjectClasspath).clusterConfiguration(getClusterConfiguration()).kubernetesClient(kubernetes).fabric8ServiceHub(getFabric8ServiceHub()).build();
    } catch (IOException exception) {
        throw new MojoExecutionException(exception.getMessage());
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BuildService(io.fabric8.maven.docker.service.BuildService) IOException(java.io.IOException) WatchService(io.fabric8.maven.docker.service.WatchService)

Example 3 with BuildContext

use of io.fabric8.maven.docker.service.BuildService.BuildContext in project jkube by eclipse.

the class DefaultMetadataEnricherTest method setUp.

@Before
public void setUp() throws Exception {
    Configuration configuration = Configuration.builder().resource(ResourceConfig.builder().annotations(MetaDataConfig.builder().all(properties("all-annotation", 1)).deployment(properties("deployment", "Deployment")).ingress(properties("ingress", "Ingress")).serviceAccount(properties("service-account", "ServiceAccount")).build()).labels(MetaDataConfig.builder().all(properties("all-label", 10L)).deployment(properties("deployment-label", "Deployment")).ingress(properties("ingress-label", "Ingress")).serviceAccount(properties("service-account-label", "ServiceAccount")).build()).build()).build();
    // @formatter:off
    new Expectations() {

        {
            buildContext.getConfiguration();
            result = configuration;
        }
    };
    // @formatter:on
    defaultMetadataEnricher = new DefaultMetadataEnricher(buildContext);
    configMap = new ConfigMapBuilder().withNewMetadata().endMetadata();
    deployment = new DeploymentBuilder();
    genericResource = new GenericKubernetesResourceBuilder().withNewMetadata().endMetadata();
    ingressV1 = new io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder();
    ingressV1beta1 = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder();
    serviceAccount = new ServiceAccountBuilder();
    klb = new KubernetesListBuilder().addToItems(configMap).addToItems(deployment).addToItems(genericResource).addToItems(ingressV1).addToItems(ingressV1beta1).addToItems(serviceAccount);
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Configuration(org.eclipse.jkube.kit.enricher.api.model.Configuration) ServiceAccountBuilder(io.fabric8.kubernetes.api.model.ServiceAccountBuilder) GenericKubernetesResourceBuilder(io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) Before(org.junit.Before)

Example 4 with BuildContext

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

the class WatchService method createBuildWatchTask.

private Runnable createBuildWatchTask(final ImageWatcher watcher, final MojoParameters mojoParameters, final boolean doRestart, final BuildService.BuildContext buildContext) throws MojoExecutionException {
    final ImageConfiguration imageConfig = watcher.getImageConfiguration();
    final AssemblyFiles files = archiveService.getAssemblyFiles(imageConfig, mojoParameters);
    if (files.isEmpty()) {
        log.error("No assembly files for %s. Are you sure you invoked together with the `package` goal?", imageConfig.getDescription());
        throw new MojoExecutionException("No files to watch found for " + imageConfig);
    }
    return new Runnable() {

        @Override
        public void run() {
            List<AssemblyFiles.Entry> entries = files.getUpdatedEntriesAndRefresh();
            if (entries != null && entries.size() > 0) {
                try {
                    log.info("%s: Assembly changed. Rebuild ...", imageConfig.getDescription());
                    if (watcher.getWatchContext().getImageCustomizer() != null) {
                        log.info("%s: Customizing the image ...", imageConfig.getDescription());
                        watcher.getWatchContext().getImageCustomizer().execute(imageConfig);
                    }
                    buildService.buildImage(imageConfig, null, buildContext);
                    String name = imageConfig.getName();
                    watcher.setImageId(queryService.getImageId(name));
                    if (doRestart) {
                        restartContainer(watcher);
                    }
                    callPostGoal(watcher);
                } catch (Exception e) {
                    log.error("%s: Error when rebuilding - %s", imageConfig.getDescription(), e);
                }
            }
        }
    };
}
Also used : AssemblyFiles(io.fabric8.maven.docker.assembly.AssemblyFiles) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) WatchImageConfiguration(io.fabric8.maven.docker.config.WatchImageConfiguration) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException) ExecException(io.fabric8.maven.docker.access.ExecException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 5 with BuildContext

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

the class BuildMojo method proceedWithJibBuild.

private void proceedWithJibBuild(ServiceHub hub, BuildService.BuildContext buildContext, ImageConfiguration imageConfig) throws MojoExecutionException {
    log.info("Building Container image with [[B]]JIB(Java Image Builder)[[B]] mode");
    new JibBuildService(hub, createMojoParameters(), log).build(jibImageFormat, imageConfig, buildContext.getRegistryConfig());
}
Also used : JibBuildService(io.fabric8.maven.docker.service.JibBuildService)

Aggregations

ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)6 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)5 File (java.io.File)5 Test (org.junit.Test)5 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)4 DockerFileUtilTest (io.fabric8.maven.docker.util.DockerFileUtilTest)4 IOException (java.io.IOException)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)3 WatchImageConfiguration (io.fabric8.maven.docker.config.WatchImageConfiguration)3 BuildService (io.fabric8.maven.docker.service.BuildService)3 Properties (java.util.Properties)3 ExecException (io.fabric8.maven.docker.access.ExecException)2 AssemblyFiles (io.fabric8.maven.docker.assembly.AssemblyFiles)2 CleanupMode (io.fabric8.maven.docker.config.CleanupMode)2 JibBuildService (io.fabric8.maven.docker.service.JibBuildService)2 WatchService (io.fabric8.maven.docker.service.WatchService)2 Expectations (mockit.Expectations)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1