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);
}
}
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);
}
}
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();
});
}
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();
}
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);
}
});
}
Aggregations