Search in sources :

Example 26 with Image

use of io.fabric8.docker.api.model.Image in project docker-maven-plugin by fabric8io.

the class PropertyConfigHandlerTest method testNoCleanup.

@Test
public void testNoCleanup() throws Exception {
    String[] testData = new String[] { k(ConfigKey.NAME), "image", k(ConfigKey.CLEANUP), "none", k(ConfigKey.FROM), "base" };
    ImageConfiguration config = resolveExternalImageConfig(testData);
    assertEquals(CleanupMode.NONE, config.getBuildConfiguration().cleanupMode());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Example 27 with Image

use of io.fabric8.docker.api.model.Image in project docker-maven-plugin by fabric8io.

the class PropertyConfigHandlerTest method testNoOptimise.

@Test
public void testNoOptimise() throws Exception {
    String[] testData = new String[] { k(ConfigKey.NAME), "image", k(ConfigKey.OPTIMISE), "false", k(ConfigKey.FROM), "base" };
    ImageConfiguration config = resolveExternalImageConfig(testData);
    assertEquals(false, config.getBuildConfiguration().optimise());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Example 28 with Image

use of io.fabric8.docker.api.model.Image in project kubernetes by ballerinax.

the class DockerHandler method pushImage.

/**
 * Push docker image.
 *
 * @param dockerModel DockerModel
 * @throws InterruptedException When error with docker build process
 * @throws IOException          When error with docker build process
 */
public void pushImage(DockerModel dockerModel) throws InterruptedException, IOException, KubernetesPluginException {
    AuthConfig authConfig = new AuthConfigBuilder().withUsername(dockerModel.getUsername()).withPassword(dockerModel.getPassword()).build();
    Config config = new ConfigBuilder().withDockerUrl(dockerModel.getDockerHost()).addToAuthConfigs(RegistryUtils.extractRegistry(dockerModel.getName()), authConfig).build();
    DockerClient client = new DefaultDockerClient(config);
    final DockerError dockerError = new DockerError();
    OutputHandle handle = client.image().withName(dockerModel.getName()).push().usingListener(new EventListener() {

        @Override
        public void onSuccess(String message) {
            pushDone.countDown();
        }

        @Override
        public void onError(String message) {
            pushDone.countDown();
            dockerError.setErrorMsg("error pushing docker image: " + message);
        }

        @Override
        public void onError(Throwable t) {
            pushDone.countDown();
            dockerError.setErrorMsg("error pushing docker image: " + t.getMessage());
        }

        @Override
        public void onEvent(String event) {
            printDebug(event);
        }
    }).toRegistry();
    pushDone.await();
    handle.close();
    client.close();
    handleError(dockerError);
}
Also used : AuthConfigBuilder(io.fabric8.docker.api.model.AuthConfigBuilder) DefaultDockerClient(io.fabric8.docker.client.DefaultDockerClient) DockerClient(io.fabric8.docker.client.DockerClient) Config(io.fabric8.docker.client.Config) AuthConfig(io.fabric8.docker.api.model.AuthConfig) DefaultDockerClient(io.fabric8.docker.client.DefaultDockerClient) AuthConfigBuilder(io.fabric8.docker.api.model.AuthConfigBuilder) ConfigBuilder(io.fabric8.docker.client.ConfigBuilder) OutputHandle(io.fabric8.docker.dsl.OutputHandle) AuthConfig(io.fabric8.docker.api.model.AuthConfig) EventListener(io.fabric8.docker.dsl.EventListener)

Example 29 with Image

use of io.fabric8.docker.api.model.Image in project ballerina by ballerina-lang.

the class DefaultBallerinaDockerClient method buildImage.

/*
    Execute a Docker image build using Fabric8 DSL.
     */
private void buildImage(String dockerEnv, String imageName, Path tmpDir, String buildArgs) throws InterruptedException, IOException {
    DockerClient client = getDockerClient(dockerEnv);
    OutputHandle buildHandle = client.image().build().withRepositoryName(imageName).withNoCache().alwaysRemovingIntermediate().withBuildArgs(buildArgs).usingListener(new DockerBuilderEventListener()).fromFolder(tmpDir.toString());
    buildDone.await();
    buildHandle.close();
    client.close();
}
Also used : DockerClient(io.fabric8.docker.client.DockerClient) BallerinaDockerClient(org.ballerinalang.containers.docker.BallerinaDockerClient) OutputHandle(io.fabric8.docker.dsl.OutputHandle)

Example 30 with Image

use of io.fabric8.docker.api.model.Image 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)

Aggregations

Test (org.junit.Test)35 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)28 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)20 IOException (java.io.IOException)16 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)15 File (java.io.File)13 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)12 ImageStream (io.fabric8.openshift.api.model.ImageStream)10 Arguments (io.fabric8.maven.docker.config.Arguments)8 Service (io.fabric8.kubernetes.api.model.Service)7 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)7 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)6 BuildService (io.fabric8.maven.core.service.BuildService)6 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)6 HashMap (java.util.HashMap)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)5 ImageName (io.fabric8.maven.docker.util.ImageName)5 ImageStreamTag (io.fabric8.openshift.api.model.ImageStreamTag)5