Search in sources :

Example 61 with DockerClient

use of com.spotify.docker.client.DockerClient in project linuxtools by eclipse.

the class DockerComposeSWTBotTest method shouldValidateLaunchConfiguration.

@Test
@RunWithProject("foo")
// ignored for now because the "Run" menu from the toolbar remains
@Ignore
public // found.
void shouldValidateLaunchConfiguration() throws CoreException {
    // given
    final DockerClient client = MockDockerClientFactory.build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    final IFile dockerComposeScript = projectInit.getProject().getFile("docker-compose.yml");
    LaunchConfigurationUtils.createDockerComposeUpLaunchConfiguration(dockerConnection, dockerComposeScript);
    // when
    bot.toolbarDropDownButtonWithTooltip("Run").menuItem("Run Configurations...").click();
    final SWTBotTreeItem dockerComposeTreeItem = SWTUtils.expand(bot.tree(), "Docker Compose");
    SWTUtils.select(dockerComposeTreeItem, "Docker Compose [foo]");
    // verify that the config is set and the form can be closed with the
    // "OK" button
    ComboAssertions.assertThat(bot.comboBox(0)).isEnabled().itemSelected("Test");
    TextAssertions.assertThat(bot.text(2)).isEnabled().textEquals("/foo");
    ButtonAssertions.assertThat(bot.button("Run")).isEnabled();
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) IFile(org.eclipse.core.resources.IFile) DockerClient(com.spotify.docker.client.DockerClient) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Ignore(org.junit.Ignore) Test(org.junit.Test) RunWithProject(org.eclipse.linuxtools.internal.docker.ui.testutils.RunWithProject)

Example 62 with DockerClient

use of com.spotify.docker.client.DockerClient in project linuxtools by eclipse.

the class NewDockerConnectionSWTBotTest method configureTCPConnection.

private IDockerConnection configureTCPConnection(final String connectionName, final String host) {
    final DockerClient client = MockDockerClientFactory.build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from(connectionName, client).withTCPConnectionSettings(host, null);
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    return dockerConnection;
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerClient(com.spotify.docker.client.DockerClient)

Example 63 with DockerClient

use of com.spotify.docker.client.DockerClient in project jointware by isdream.

the class DockerMain method main.

public static void main(String[] args) throws Exception {
    DockerClient docker = DefaultDockerClient.fromEnv().uri(URL).build();
    ServiceSpec spec = null;
    docker.createService(spec);
    System.out.println(docker.listContainers());
    docker.close();
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) ServiceSpec(com.spotify.docker.client.messages.swarm.ServiceSpec)

Example 64 with DockerClient

use of com.spotify.docker.client.DockerClient in project azure-tools-for-java by Microsoft.

the class DockerRuntime method cleanRuningContainer.

/**
 * clean running container.
 */
public synchronized void cleanRuningContainer(String key) throws DockerCertificateException, DockerException, InterruptedException {
    if (containerSettingMap.containsKey(key)) {
        String runningContainerId = (String) containerSettingMap.get(key).get(CONTAINER_ID_KEY);
        DockerHostRunSetting dataModel = (DockerHostRunSetting) containerSettingMap.get(key).get(DOCKER_HOST_RUN_SETTING_KEY);
        DockerClient docker = DockerUtil.getDockerClient(dataModel.getDockerHost(), dataModel.isTlsEnabled(), dataModel.getDockerCertPath());
        docker.stopContainer(runningContainerId, Constant.TIMEOUT_STOP_CONTAINER);
        docker.removeContainer(runningContainerId);
    }
    containerSettingMap.remove(key);
}
Also used : DockerHostRunSetting(com.microsoft.azuretools.core.mvp.model.container.pojo.DockerHostRunSetting) DockerClient(com.spotify.docker.client.DockerClient)

Example 65 with DockerClient

use of com.spotify.docker.client.DockerClient in project azure-tools-for-java by Microsoft.

the class DockerRunDialog method execute.

private void execute() {
    Operation operation = TelemetryManager.createOperation(WEBAPP, DEPLOY_WEBAPP_DOCKERLOCAL);
    Observable.fromCallable(() -> {
        operation.start();
        ConsoleLogger.info("Starting job ...  ");
        if (basePath == null) {
            ConsoleLogger.error("Project base path is null.");
            throw new FileNotFoundException("Project base path is null.");
        }
        // locate artifact to specified location
        String targetFilePath = dataModel.getTargetPath();
        ConsoleLogger.info(String.format("Locating artifact ... [%s]", targetFilePath));
        // validate dockerfile
        Path targetDockerfile = Paths.get(dataModel.getDockerFilePath());
        ConsoleLogger.info(String.format("Validating dockerfile ... [%s]", targetDockerfile));
        if (!targetDockerfile.toFile().exists()) {
            throw new FileNotFoundException("Dockerfile not found.");
        }
        // replace placeholder if exists
        String content = new String(Files.readAllBytes(targetDockerfile));
        content = content.replaceAll(Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER, Paths.get(basePath).toUri().relativize(Paths.get(targetFilePath).toUri()).getPath());
        Files.write(targetDockerfile, content.getBytes());
        // build image
        String imageNameWithTag = String.format("%s:%s", dataModel.getImageName(), dataModel.getTagName());
        ConsoleLogger.info(String.format("Building image ...  [%s]", imageNameWithTag));
        DockerClient docker = DockerUtil.getDockerClient(dataModel.getDockerHost(), dataModel.isTlsEnabled(), dataModel.getDockerCertPath());
        DockerUtil.ping(docker);
        DockerUtil.buildImage(docker, imageNameWithTag, targetDockerfile.getParent(), targetDockerfile.getFileName().toString(), new DockerProgressHandler());
        // create a container
        final String containerServerPort = StringUtils.firstNonEmpty(getPortFromDockerfile(content), getPortByArtifact(targetFilePath));
        ConsoleLogger.info(Constant.MESSAGE_CREATING_CONTAINER);
        String containerId = DockerUtil.createContainer(docker, String.format("%s:%s", dataModel.getImageName(), dataModel.getTagName()), containerServerPort);
        ConsoleLogger.info(String.format(Constant.MESSAGE_CONTAINER_INFO, containerId));
        // start container
        ConsoleLogger.info(Constant.MESSAGE_STARTING_CONTAINER);
        Container container = DockerUtil.runContainer(docker, containerId);
        DockerRuntime.getInstance().setRunningContainerId(basePath, container.id(), dataModel);
        // props
        String hostname = new URI(dataModel.getDockerHost()).getHost();
        ImmutableList<PortMapping> ports = container.ports();
        String publicPort = null;
        if (ports != null) {
            for (Container.PortMapping portMapping : ports) {
                if (StringUtils.equalsIgnoreCase(containerServerPort, String.valueOf(portMapping.privatePort()))) {
                    publicPort = String.valueOf(portMapping.publicPort());
                }
            }
        }
        ConsoleLogger.info(String.format(Constant.MESSAGE_CONTAINER_STARTED, (hostname != null ? hostname : "localhost") + (publicPort != null ? ":" + publicPort : "")));
        return null;
    }).subscribeOn(SchedulerProviderFactory.getInstance().getSchedulerProvider().io()).subscribe(ret -> {
        ConsoleLogger.info("Container started.");
        sendTelemetry(true, null);
        operation.complete();
    }, e -> {
        e.printStackTrace();
        ConsoleLogger.error(e.getMessage());
        sendTelemetry(false, e.getMessage());
        EventUtil.logError(operation, ErrorType.systemError, new Exception(e), null, null);
        operation.complete();
    });
}
Also used : Path(java.nio.file.Path) DockerProgressHandler(com.microsoft.azuretools.container.DockerProgressHandler) Container(com.spotify.docker.client.messages.Container) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FileNotFoundException(java.io.FileNotFoundException) PortMapping(com.spotify.docker.client.messages.Container.PortMapping) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) PortMapping(com.spotify.docker.client.messages.Container.PortMapping) URI(java.net.URI) InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) FileNotFoundException(java.io.FileNotFoundException) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException)

Aggregations

DockerClient (com.spotify.docker.client.DockerClient)185 Test (org.junit.Test)102 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)75 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)38 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)20 JobId (com.spotify.helios.common.descriptors.JobId)19 DockerException (com.spotify.docker.client.exceptions.DockerException)18 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)18 LogStream (com.spotify.docker.client.LogStream)17 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)15 Container (com.spotify.docker.client.messages.Container)14 Path (java.nio.file.Path)12 DockerException (org.eclipse.linuxtools.docker.core.DockerException)12 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)12 Matchers.containsString (org.hamcrest.Matchers.containsString)11 HostConfig (com.spotify.docker.client.messages.HostConfig)10 HeliosClient (com.spotify.helios.client.HeliosClient)10 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)9 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)9 RunWithProject (org.eclipse.linuxtools.internal.docker.ui.testutils.RunWithProject)9