use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel in project linuxtools by eclipse.
the class RunImageLinksTab method onRemoveLinks.
private SelectionListener onRemoveLinks(final TableViewer linksTableViewer) {
return SelectionListener.widgetSelectedAdapter(e -> {
final IStructuredSelection selection = linksTableViewer.getStructuredSelection();
for (@SuppressWarnings("unchecked") Iterator<ContainerLinkModel> iterator = selection.iterator(); iterator.hasNext(); ) {
model.removeLink(iterator.next());
}
updateLaunchConfigurationDialog();
});
}
use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel in project linuxtools by eclipse.
the class RunImageLinksTab method onEditLink.
private SelectionListener onEditLink(final TableViewer linksTableViewer) {
return SelectionListener.widgetSelectedAdapter(e -> {
final IStructuredSelection selection = linksTableViewer.getStructuredSelection();
final ContainerLinkModel selectedContainerLink = (ContainerLinkModel) selection.getFirstElement();
final ContainerLinkDialog dialog = new ContainerLinkDialog(getShell(), model.getSelectedConnection(), selectedContainerLink);
dialog.create();
if (dialog.open() == IDialogConstants.OK_ID) {
selectedContainerLink.setContainerName(dialog.getContainerName());
selectedContainerLink.setContainerAlias(dialog.getContainerAlias());
linksTableViewer.refresh();
updateLaunchConfigurationDialog();
}
});
}
use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel 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();
}
use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel in project linuxtools by eclipse.
the class ImageRunSelectionPage method onEditLink.
private SelectionListener onEditLink(final TableViewer linksTableViewer) {
return SelectionListener.widgetSelectedAdapter(e -> {
final IStructuredSelection selection = linksTableViewer.getStructuredSelection();
final ContainerLinkModel selectedContainerLink = (ContainerLinkModel) selection.getFirstElement();
final ContainerLinkDialog dialog = new ContainerLinkDialog(getShell(), model.getSelectedConnection(), selectedContainerLink);
dialog.create();
if (dialog.open() == IDialogConstants.OK_ID) {
selectedContainerLink.setContainerName(dialog.getContainerName());
selectedContainerLink.setContainerAlias(dialog.getContainerAlias());
linksTableViewer.refresh();
}
});
}
Aggregations