Search in sources :

Example 11 with ImageName

use of io.fabric8.maven.docker.util.ImageName 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 12 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.

the class KubernetesClientUtil method deleteEntities.

public static void deleteEntities(KubernetesClient kubernetes, String namespace, Set<HasMetadata> entities, String s2iBuildNameSuffix, Logger log) {
    List<HasMetadata> list = new ArrayList<>(entities);
    // For OpenShift cluster, also delete s2i buildconfig
    OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
    if (openshiftClient != null) {
        for (HasMetadata entity : list) {
            if ("ImageStream".equals(getKind(entity))) {
                ImageName imageName = new ImageName(entity.getMetadata().getName());
                String buildName = getS2IBuildName(imageName, s2iBuildNameSuffix);
                log.info("Deleting resource BuildConfig " + namespace + "/" + buildName);
                openshiftClient.buildConfigs().inNamespace(namespace).withName(buildName).delete();
            }
        }
    }
    // lets delete in reverse order
    Collections.reverse(list);
    for (HasMetadata entity : list) {
        log.info("Deleting resource " + getKind(entity) + " " + namespace + "/" + getName(entity));
        kubernetes.resource(entity).inNamespace(namespace).cascading(true).delete();
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) Controller(io.fabric8.kubernetes.api.Controller) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController)

Example 13 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.

the class KubernetesResourceUtil method extractImageUser.

private static String extractImageUser(String image, MavenProject project) {
    ImageName name = new ImageName(image);
    String imageUser = name.getUser();
    return imageUser != null ? imageUser : project.getGroupId();
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName)

Example 14 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildService method updateOrCreateBuildConfig.

private String updateOrCreateBuildConfig(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, ImageConfiguration imageConfig) {
    ImageName imageName = new ImageName(imageConfig.getName());
    String buildName = getS2IBuildName(config, imageName);
    String imageStreamName = getImageStreamName(imageName);
    String outputImageStreamTag = imageStreamName + ":" + (imageName.getTag() != null ? imageName.getTag() : "latest");
    BuildStrategy buildStrategyResource = createBuildStrategy(imageConfig, config.getOpenshiftBuildStrategy());
    BuildOutput buildOutput = new BuildOutputBuilder().withNewTo().withKind("ImageStreamTag").withName(outputImageStreamTag).endTo().build();
    // Fetch exsting build config
    BuildConfig buildConfig = client.buildConfigs().withName(buildName).get();
    if (buildConfig != null) {
        // lets verify the BC
        BuildConfigSpec spec = getBuildConfigSpec(buildConfig);
        validateSourceType(buildName, spec);
        if (config.getBuildRecreateMode().isBuildConfig()) {
            // Delete and recreate afresh
            client.buildConfigs().withName(buildName).delete();
            return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput);
        } else {
            // Update & return
            return updateBuildConfig(client, buildName, buildStrategyResource, buildOutput, spec);
        }
    } else {
        // Create afresh
        return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) BuildOutput(io.fabric8.openshift.api.model.BuildOutput) BuildStrategy(io.fabric8.openshift.api.model.BuildStrategy) OpenShiftBuildStrategy(io.fabric8.maven.core.config.OpenShiftBuildStrategy) BuildOutputBuilder(io.fabric8.openshift.api.model.BuildOutputBuilder) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) BuildConfigSpec(io.fabric8.openshift.api.model.BuildConfigSpec)

Example 15 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildService method build.

@Override
public void build(ImageConfiguration imageConfig) throws Fabric8ServiceException {
    try {
        ImageName imageName = new ImageName(imageConfig.getName());
        File dockerTar = createBuildArchive(imageConfig);
        KubernetesListBuilder builder = new KubernetesListBuilder();
        // Check for buildconfig / imagestream and create them if necessary
        String buildName = updateOrCreateBuildConfig(config, client, builder, imageConfig);
        checkOrCreateImageStream(config, client, builder, getImageStreamName(imageName));
        applyResourceObjects(config, client, builder);
        // Start the actual build
        Build build = startBuild(client, dockerTar, buildName);
        // Wait until the build finishes
        waitForOpenShiftBuildToComplete(client, build);
        // Create a file with generated image streams
        addImageStreamToFile(getImageStreamFile(config), imageName, client);
    } catch (Fabric8ServiceException e) {
        throw e;
    } catch (Exception ex) {
        throw new Fabric8ServiceException("Unable to build the image using the OpenShift build service", ex);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) Build(io.fabric8.openshift.api.model.Build) File(java.io.File) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

ImageName (io.fabric8.maven.docker.util.ImageName)13 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 Test (org.junit.Test)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)4 File (java.io.File)4 DockerClient (io.fabric8.docker.client.DockerClient)3 Container (io.fabric8.kubernetes.api.model.Container)3 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)3 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)3 UrlBuilder (io.fabric8.maven.docker.access.UrlBuilder)3 IOException (java.io.IOException)3 Controller (io.fabric8.kubernetes.api.Controller)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)2 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2