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");
});
}
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());
}
}
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);
}
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);
}
}
}
};
}
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());
}
Aggregations