Search in sources :

Example 1 with IDockerImageInfo

use of org.eclipse.linuxtools.docker.core.IDockerImageInfo in project linuxtools by eclipse.

the class LaunchConfigurationUtils method createRunImageLaunchConfiguration.

/**
 * Creates a new {@link ILaunchConfiguration} for the given
 * {@link IDockerContainer}.
 *
 * @param baseConfigurationName
 *            the base configuration name to use when creating the
 *            {@link ILaunchConfiguration}.
 * @param image
 *            the {@link IDockerImage} used to create the container
 * @param containerName
 *            the actual container name (given by the user or generated by
 *            the Docker daemon)
 * @param containerConfig
 * @param hostConfig
 *            the user-provided {@link IDockerHostConfig} (created
 *            container's one)
 * @param removeWhenExits
 *            flag to indicate if container should be removed when exited
 * @return the generated {@link ILaunchConfiguration}
 */
public static ILaunchConfiguration createRunImageLaunchConfiguration(final IDockerImage image, final IDockerContainerConfig containerConfig, final IDockerHostConfig hostConfig, final String containerName, final boolean removeWhenExits) {
    try {
        final ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
        final ILaunchConfigurationType type = manager.getLaunchConfigurationType(IRunDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID);
        final String imageName = createRunImageLaunchConfigurationName(image);
        // using the image repo + first tag
        final ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigurationWorkingCopy(type, imageName);
        workingCopy.setAttribute(CREATION_DATE, DATE_FORMAT.format(new Date()));
        workingCopy.setAttribute(CONNECTION_NAME, image.getConnection().getName());
        workingCopy.setAttribute(IMAGE_ID, image.id());
        workingCopy.setAttribute(IMAGE_NAME, createRunImageLaunchConfigurationName(image));
        if (containerName != null && !containerName.isEmpty()) {
            workingCopy.setAttribute(CONTAINER_NAME, containerName);
        }
        // if we know the raw command string, use it since the container
        // config will remove quotes to split up command properly
        DockerContainerConfig config = (DockerContainerConfig) containerConfig;
        if (config.rawcmd() != null) {
            workingCopy.setAttribute(COMMAND, config.rawcmd());
        } else {
            workingCopy.setAttribute(COMMAND, toString(containerConfig.cmd()));
        }
        workingCopy.setAttribute(ENTRYPOINT, toString(containerConfig.entrypoint()));
        // selected ports
        workingCopy.setAttribute(PUBLISH_ALL_PORTS, hostConfig.publishAllPorts());
        // format: <containerPort><type>:<hostIP>:<hostPort>
        if (hostConfig.publishAllPorts()) {
            final IDockerImageInfo imageInfo = image.getConnection().getImageInfo(image.id());
            if (imageInfo != null) {
                workingCopy.setAttribute(PUBLISHED_PORTS, serializePortBindings(imageInfo.containerConfig().exposedPorts()));
            }
        } else {
            workingCopy.setAttribute(PUBLISHED_PORTS, serializePortBindings(hostConfig.portBindings()));
        }
        // links (with format being: "<containerName>:<containerAlias>")
        workingCopy.setAttribute(LINKS, hostConfig.links());
        // env variables
        workingCopy.setAttribute(ENV_VARIABLES, containerConfig.env());
        // labels
        workingCopy.setAttribute(LABELS, containerConfig.labels());
        // volumes
        final List<String> volumes = new ArrayList<>();
        // volumes from other containers
        for (String volumeFrom : hostConfig.volumesFrom()) {
            final DataVolumeModel volume = DataVolumeModel.parseVolumeFrom(volumeFrom);
            if (volume != null) {
                volumes.add(volume.toString());
            }
        }
        // bindings to host directory or file
        for (String bind : hostConfig.binds()) {
            final DataVolumeModel volume = DataVolumeModel.parseHostBinding(bind);
            if (volume != null) {
                volumes.add(volume.toString());
            }
        }
        // TODO: container path declaration
        workingCopy.setAttribute(DATA_VOLUMES, volumes);
        // options
        workingCopy.setAttribute(AUTO_REMOVE, removeWhenExits);
        workingCopy.setAttribute(ALLOCATE_PSEUDO_CONSOLE, containerConfig.tty());
        workingCopy.setAttribute(INTERACTIVE, containerConfig.openStdin());
        workingCopy.setAttribute(PRIVILEGED, hostConfig.privileged());
        workingCopy.setAttribute(READONLY, ((DockerHostConfig) hostConfig).readonlyRootfs());
        if (hostConfig.networkMode() != null)
            workingCopy.setAttribute(NETWORK_MODE, hostConfig.networkMode());
        // resources limitations
        if (containerConfig.memory() != null) {
            workingCopy.setAttribute(ENABLE_LIMITS, true);
            // memory in containerConfig is expressed in bytes
            workingCopy.setAttribute(MEMORY_LIMIT, Long.toString(containerConfig.memory().longValue() / MB));
        }
        if (containerConfig.cpuShares() != null) {
            workingCopy.setAttribute(ENABLE_LIMITS, true);
            workingCopy.setAttribute(CPU_PRIORITY, containerConfig.cpuShares().toString());
        }
        return workingCopy.doSave();
    } catch (CoreException e) {
        Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, LaunchMessages.getString(// $NON-NLS-1$
        "RunDockerImageLaunchConfiguration.creation.failure"), e));
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DataVolumeModel(org.eclipse.linuxtools.internal.docker.ui.wizards.DataVolumeModel) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Date(java.util.Date)

Example 2 with IDockerImageInfo

use of org.eclipse.linuxtools.docker.core.IDockerImageInfo in project linuxtools by eclipse.

the class ImageRunResourceVolumesVariablesPage method findImageInfo.

private IDockerImageInfo findImageInfo(final IDockerImage selectedImage) throws InvocationTargetException, InterruptedException {
    final FindImageInfoRunnable findImageInfoRunnable = new FindImageInfoRunnable(selectedImage);
    getContainer().run(true, true, findImageInfoRunnable);
    final IDockerImageInfo selectedImageInfo = findImageInfoRunnable.getResult();
    return selectedImageInfo;
}
Also used : FindImageInfoRunnable(org.eclipse.linuxtools.internal.docker.ui.jobs.FindImageInfoRunnable) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo)

Example 3 with IDockerImageInfo

use of org.eclipse.linuxtools.docker.core.IDockerImageInfo in project linuxtools by eclipse.

the class ImageRunSelectionPage method setDefaultValues.

/**
 * Sets the default values from the optional given {@link IDockerImage} and
 * {@link ILaunchConfiguration} elements
 */
private void setDefaultValues() {
    final IDockerImage selectedImage = model.getSelectedImage();
    if (selectedImage == null) {
        return;
    }
    final IDockerImageInfo selectedImageInfo = getImageInfo(selectedImage);
    // skip if a previous launch configuration was provided
    if (this.lastLaunchConfiguration != null) {
        try {
            this.model.setContainerName(lastLaunchConfiguration.getAttribute(CONTAINER_NAME, ""));
            this.model.setEntrypoint(lastLaunchConfiguration.getAttribute(ENTRYPOINT, ""));
            this.model.setCommand(lastLaunchConfiguration.getAttribute(COMMAND, ""));
            this.model.setPublishAllPorts(lastLaunchConfiguration.getAttribute(PUBLISH_ALL_PORTS, false));
            final List<String> exposedPortInfos = lastLaunchConfiguration.getAttribute(PUBLISHED_PORTS, Collections.<String>emptyList());
            // by the user.
            if (selectedImageInfo != null) {
                final List<ExposedPortModel> exposedPorts = ExposedPortModel.fromStrings(selectedImageInfo.config().exposedPorts());
                model.setExposedPorts(exposedPorts);
                final List<ExposedPortModel> selectedExposedPorts = ExposedPortModel.fromStrings(exposedPortInfos);
                this.model.setSelectedPorts(new HashSet<>(selectedExposedPorts));
            }
            // links
            this.model.setLinks(lastLaunchConfiguration.getAttribute(LINKS, Collections.<String>emptyList()));
            // other options
            this.model.setRemoveWhenExits(lastLaunchConfiguration.getAttribute(AUTO_REMOVE, false));
            this.model.setInteractiveMode(lastLaunchConfiguration.getAttribute(INTERACTIVE, false));
            this.model.setAllocatePseudoTTY(lastLaunchConfiguration.getAttribute(ALLOCATE_PSEUDO_CONSOLE, false));
            this.model.setPrivileged(lastLaunchConfiguration.getAttribute(PRIVILEGED, false));
            this.model.setBasicSecurity(lastLaunchConfiguration.getAttribute(READONLY, false));
        } catch (CoreException e) {
            Activator.log(e);
        }
    } else {
        applyImageInfo(selectedImageInfo);
    }
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) CoreException(org.eclipse.core.runtime.CoreException) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 4 with IDockerImageInfo

use of org.eclipse.linuxtools.docker.core.IDockerImageInfo in project linuxtools by eclipse.

the class ImageInspectPropertySection method setInput.

@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
    super.setInput(part, selection);
    final Object input = getSelection(selection);
    final IDockerConnection parentConnection = getConnection(part, selection);
    final IDockerImageInfo imageInfo = getImageInfo(parentConnection, input);
    if (getTreeViewer() != null && imageInfo != null) {
        getTreeViewer().setInput(imageInfo);
        getTreeViewer().expandAll();
    }
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo)

Example 5 with IDockerImageInfo

use of org.eclipse.linuxtools.docker.core.IDockerImageInfo in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModel method lookupImageMetadata.

protected IDockerImageMetadata lookupImageMetadata() {
    if (StringUtils.isBlank(this.imageName)) {
        return null;
    }
    final DockerImageURI imageURI = new DockerImageURI(this.imageName);
    final String repo = imageURI.getUriWithoutTag();
    final String tag = StringUtils.defaultIfBlank(imageURI.getTag(), "latest");
    if (dockerConnection != null && DockerImageUtils.hasImage(dockerConnection, repo, tag)) {
        final IDockerImageInfo info = dockerConnection.getImageInfo(this.imageName);
        if (info == null) {
            return null;
        }
        return new DockerConfigMetaData(info);
    } else if (this.project != null) {
        return DockerImageUtils.lookupImageMetadata(project, imageURI);
    }
    return null;
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) DockerConfigMetaData(org.jboss.tools.openshift.internal.core.docker.DockerConfigMetaData)

Aggregations

IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)17 Test (org.junit.Test)7 PortSpecAdapter (org.jboss.tools.openshift.internal.core.models.PortSpecAdapter)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ArrayList (java.util.ArrayList)3 CoreException (org.eclipse.core.runtime.CoreException)3 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)3 EnvironmentVariable (org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable)3 ServicePortAdapter (org.jboss.tools.openshift.internal.ui.wizard.deployimage.ServicePortAdapter)3 HashMap (java.util.HashMap)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)2 IDockerContainerConfig (org.eclipse.linuxtools.docker.core.IDockerContainerConfig)2 DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)2 FindImageInfoRunnable (org.eclipse.linuxtools.internal.docker.ui.jobs.FindImageInfoRunnable)2 DataVolumeModel (org.eclipse.linuxtools.internal.docker.ui.wizards.DataVolumeModel)2 ExposedPortModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel)2 DockerImageURI (com.openshift.restclient.images.DockerImageURI)1 IServicePort (com.openshift.restclient.model.IServicePort)1