Search in sources :

Example 6 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class RunImageMainTab method findImageInfo.

private void findImageInfo(final IDockerImage selectedImage) {
    try {
        final FindImageInfoRunnable findImageInfoRunnable = new FindImageInfoRunnable(selectedImage);
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(this.getShell());
        dialog.run(true, true, findImageInfoRunnable);
        final IDockerImageInfo selectedImageInfo = findImageInfoRunnable.getResult();
        final Set<String> exposedPortInfos = selectedImageInfo.config().exposedPorts();
        final List<ExposedPortModel> availablePorts = new ArrayList<>();
        if (exposedPortInfos != null) {
            for (String exposedPortInfo : exposedPortInfos) {
                final String privatePort = exposedPortInfo.substring(0, exposedPortInfo.indexOf('/'));
                final String type = exposedPortInfo.substring(// $NON-NLS-1$
                exposedPortInfo.indexOf('/'));
                final ExposedPortModel exposedPort = new ExposedPortModel(privatePort, type, "", privatePort);
                // $NON-NLS-1$
                availablePorts.add(exposedPort);
            }
        }
        model.setExposedPorts(availablePorts);
        model.setEntrypoint(selectedImageInfo.config().entrypoint());
        model.setCommand(selectedImageInfo.config().cmd());
    } catch (InvocationTargetException | InterruptedException e) {
        Activator.log(e);
    }
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class RunImagePortsTab method initializeFrom.

@Override
public void initializeFrom(ILaunchConfiguration configuration) {
    if (model == null)
        return;
    try {
        // recycle the model
        model.removeExposedPorts();
        final boolean publishAllPorts = configuration.getAttribute(IRunDockerImageLaunchConfigurationConstants.PUBLISH_ALL_PORTS, true);
        model.setPublishAllPorts(publishAllPorts);
        final List<String> publishedPorts = configuration.getAttribute(IRunDockerImageLaunchConfigurationConstants.PUBLISHED_PORTS, new ArrayList<String>());
        final Set<ExposedPortModel> selectedPorts = new HashSet<>();
        for (String port : publishedPorts) {
            final ImageRunSelectionModel.ExposedPortModel exposedPort = ImageRunSelectionModel.ExposedPortModel.createPortModel(port);
            model.addExposedPort(exposedPort);
            if (exposedPort.getSelected()) {
                selectedPorts.add(exposedPort);
            }
        }
        // select ports
        model.setSelectedPorts(selectedPorts);
        // update the underlying launch config working copy on model
        // changes.
        model.addPropertyChangeListener(new LaunchConfigurationChangeListener());
    } catch (CoreException e) {
        Activator.logErrorMessage(LaunchMessages.getString(// $NON-NLS-1$
        "RunDockerImageLaunchConfiguration.load.failure"), e);
    }
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) CoreException(org.eclipse.core.runtime.CoreException) ImageRunSelectionModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel) HashSet(java.util.HashSet)

Example 8 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class RunImagePortsTab method onRemovePorts.

private SelectionListener onRemovePorts(final TableViewer portsTableViewer) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final IStructuredSelection selection = portsTableViewer.getStructuredSelection();
        for (@SuppressWarnings("unchecked") Iterator<ExposedPortModel> iterator = selection.iterator(); iterator.hasNext(); ) {
            final ExposedPortModel port = iterator.next();
            model.removeAvailablePort(port);
            model.getSelectedPorts().remove(port);
        }
        updateLaunchConfigurationDialog();
    });
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 9 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class ImageRun method getDockerHostConfig.

public IDockerHostConfig getDockerHostConfig() {
    final ImageRunSelectionModel selectionModel = this.imageRunSelectionPage.getModel();
    final ImageRunResourceVolumesVariablesModel resourcesModel = this.imageRunResourceVolumesPage.getModel();
    final ImageRunNetworkModel networkModel = this.imageRunNetworkPage.getModel();
    final DockerHostConfig.Builder hostConfigBuilder = new DockerHostConfig.Builder();
    if (selectionModel.isPublishAllPorts()) {
        hostConfigBuilder.publishAllPorts(true);
    } else {
        final Map<String, List<IDockerPortBinding>> portBindings = new HashMap<>();
        for (Iterator<ExposedPortModel> iterator = selectionModel.getExposedPorts().iterator(); iterator.hasNext(); ) {
            final ExposedPortModel exposedPort = iterator.next();
            // only selected Ports in the CheckboxTableViewer are exposed.
            if (!selectionModel.getSelectedPorts().contains(exposedPort)) {
                continue;
            }
            final DockerPortBinding portBinding = new DockerPortBinding(exposedPort.getHostAddress(), exposedPort.getHostPort());
            portBindings.put(exposedPort.getContainerPort() + exposedPort.getPortType(), Arrays.<IDockerPortBinding>asList(portBinding));
        }
        hostConfigBuilder.portBindings(portBindings);
    }
    // container links
    final List<String> links = new ArrayList<>();
    for (Iterator<ContainerLinkModel> iterator = selectionModel.getLinks().iterator(); iterator.hasNext(); ) {
        final ContainerLinkModel link = iterator.next();
        links.add(link.getContainerName() + ':' + link.getContainerAlias());
    }
    hostConfigBuilder.links(links);
    // data volumes
    final List<String> volumesFrom = new ArrayList<>();
    final List<String> binds = new ArrayList<>();
    for (Iterator<DataVolumeModel> iterator = resourcesModel.getDataVolumes().iterator(); iterator.hasNext(); ) {
        final DataVolumeModel dataVolume = iterator.next();
        // included.
        if (!resourcesModel.getSelectedDataVolumes().contains(dataVolume)) {
            continue;
        }
        switch(dataVolume.getMountType()) {
            case HOST_FILE_SYSTEM:
                String bind = LaunchConfigurationUtils.convertToUnixPath(dataVolume.getHostPathMount()) + ':' + dataVolume.getContainerPath() + // $NON-NLS-1$ //$NON-NLS-2$
                ":Z";
                if (dataVolume.isReadOnly()) {
                    // $NON-NLS-1$
                    bind += ",ro";
                }
                binds.add(bind);
                break;
            case CONTAINER:
                volumesFrom.add(dataVolume.getContainerMount());
                break;
            default:
                break;
        }
    }
    hostConfigBuilder.binds(binds);
    hostConfigBuilder.volumesFrom(volumesFrom);
    hostConfigBuilder.privileged(selectionModel.isPrivileged());
    // make /tmp and /run use tmpfs, and drop all capabilities
    if (selectionModel.isBasicSecurity()) {
        hostConfigBuilder.readonlyRootfs(true);
        Map<String, String> tmpfsValues = new HashMap<>();
        // $NON-NLS-1$ //$NON-NLS-2$
        tmpfsValues.put("/run", "rw,exec");
        // $NON-NLS-1$ //$NON-NLS-2$
        tmpfsValues.put("/tmp", "rw,exec");
        hostConfigBuilder.tmpfs(tmpfsValues);
        List<String> capDropList = new ArrayList<>();
        // $NON-NLS-1$
        capDropList.add("all");
        hostConfigBuilder.capDrop(capDropList);
    }
    if (selectionModel.isUnconfined()) {
        List<String> seccomp = new ArrayList<>();
        // $NON-NLS-1$
        seccomp.add("seccomp:unconfined");
        hostConfigBuilder.securityOpt(seccomp);
    }
    String networkMode = networkModel.getNetworkModeString();
    // if network mode is not default, set it in host config
    if (networkMode != null && !networkMode.equals(ImageRunNetworkModel.DEFAULT_MODE))
        hostConfigBuilder.networkMode(networkMode);
    // memory constraints (in bytes)
    if (resourcesModel.isEnableResourceLimitations()) {
        hostConfigBuilder.memory(resourcesModel.getMemoryLimit() * MB);
        hostConfigBuilder.cpuShares(resourcesModel.getCpuShareWeight());
    }
    return hostConfigBuilder.build();
}
Also used : IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) DockerHostConfig(org.eclipse.linuxtools.internal.docker.core.DockerHostConfig) ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) HashMap(java.util.HashMap) Builder(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder) ArrayList(java.util.ArrayList) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) DockerPortBinding(org.eclipse.linuxtools.internal.docker.core.DockerPortBinding) ContainerLinkModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class ImageRunSelectionPage method onAddPort.

private SelectionListener onAddPort(final CheckboxTableViewer exposedPortsTableViewer) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final ContainerPortDialog dialog = new ContainerPortDialog(getShell());
        dialog.create();
        if (dialog.open() == IDialogConstants.OK_ID) {
            final ExposedPortModel port = dialog.getPort();
            port.setSelected(true);
            model.addAvailablePort(port);
            model.getSelectedPorts().add(port);
            exposedPortsTableViewer.setChecked(port, true);
        }
    });
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel)

Aggregations

ExposedPortModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 CoreException (org.eclipse.core.runtime.CoreException)2 IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)2 Builder (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder)2 ContainerPortDialog (org.eclipse.linuxtools.internal.docker.ui.wizards.ContainerPortDialog)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)1 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)1 IDockerPortBinding (org.eclipse.linuxtools.docker.core.IDockerPortBinding)1 DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)1 DockerHostConfig (org.eclipse.linuxtools.internal.docker.core.DockerHostConfig)1 DockerPortBinding (org.eclipse.linuxtools.internal.docker.core.DockerPortBinding)1 ImageRunSelectionModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel)1 ContainerLinkModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel)1