Search in sources :

Example 1 with Builder

use of org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder in project linuxtools by eclipse.

the class ImageRun method getDockerContainerConfig.

public DockerContainerConfig getDockerContainerConfig() {
    final ImageRunSelectionModel selectionModel = this.imageRunSelectionPage.getModel();
    final ImageRunResourceVolumesVariablesModel resourcesModel = this.imageRunResourceVolumesPage.getModel();
    final Builder config = new DockerContainerConfig.Builder().cmd(selectionModel.getCommand()).entryPoint(selectionModel.getEntrypoint()).image(selectionModel.getSelectedImageName()).tty(selectionModel.isAllocatePseudoTTY()).openStdin(selectionModel.isInteractiveMode());
    if (resourcesModel.isEnableResourceLimitations()) {
        // memory limit must be converted from MB to bytes
        config.memory(resourcesModel.getMemoryLimit() * MB);
        config.cpuShares(resourcesModel.getCpuShareWeight());
    }
    // environment variables
    final List<String> environmentVariables = new ArrayList<>();
    for (Iterator<EnvironmentVariableModel> iterator = resourcesModel.getEnvironmentVariables().iterator(); iterator.hasNext(); ) {
        final EnvironmentVariableModel var = iterator.next();
        // $NON-NLS-1$
        environmentVariables.add(var.getName() + "=" + var.getValue());
    }
    config.env(environmentVariables);
    // container labels
    final Map<String, String> labelVariables = new HashMap<>();
    for (Iterator<LabelVariableModel> iterator = resourcesModel.getLabelVariables().iterator(); iterator.hasNext(); ) {
        final LabelVariableModel var = iterator.next();
        // $NON-NLS-1$
        labelVariables.put(var.getName(), var.getValue());
    }
    config.labels(labelVariables);
    if (!selectionModel.isPublishAllPorts()) {
        final Set<String> exposedPorts = new HashSet<>();
        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;
            }
            exposedPorts.add(exposedPort.getContainerPort() + exposedPort.getPortType());
        }
        config.exposedPorts(exposedPorts);
    }
    return config.build();
}
Also used : 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) Builder(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) HashSet(java.util.HashSet)

Example 2 with Builder

use of org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder in project linuxtools by eclipse.

the class RunDockerImageLaunchConfigurationDelegate method getDockerContainerConfig.

public IDockerContainerConfig getDockerContainerConfig(ILaunchConfiguration lconfig) throws CoreException {
    String command = lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.COMMAND, // $NON-NLS-1$
    "");
    String entrypoint = lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.ENTRYPOINT, // $NON-NLS-1$
    "");
    String imageName = lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.IMAGE_NAME, // $NON-NLS-1$
    "");
    boolean useTTY = lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.ALLOCATE_PSEUDO_CONSOLE, false);
    boolean interactive = lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.INTERACTIVE, false);
    final Builder config = new DockerContainerConfig.Builder().cmd(command).entryPoint(entrypoint).image(imageName).tty(useTTY).openStdin(interactive);
    boolean limits_enabled = lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.ENABLE_LIMITS, false);
    if (limits_enabled) {
        long memory = Long.parseLong(lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.MEMORY_LIMIT, "0"));
        config.memory(memory);
        long cpuShares = Long.parseLong(lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.CPU_PRIORITY, "0"));
        config.cpuShares(cpuShares);
    }
    // environment variables
    final List<String> environmentVariables = lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.ENV_VARIABLES, new ArrayList<String>());
    config.env(environmentVariables);
    // labels
    final Map<String, String> labelVariables = lconfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.LABELS, (Map<String, String>) null);
    if (labelVariables != null)
        config.labels(labelVariables);
    return config.build();
}
Also used : DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) Builder(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder) Builder(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder)

Aggregations

DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)2 Builder (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IDockerContainerConfig (org.eclipse.linuxtools.docker.core.IDockerContainerConfig)1 ExposedPortModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel)1