Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java')
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java83
1 files changed, 59 insertions, 24 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
index 6bb55fa1b9..fe8058b0f1 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
@@ -17,12 +17,13 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.linuxtools.docker.core.AbstractRegistry;
import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerImage;
-import org.eclipse.linuxtools.docker.core.IRegistry;
import org.eclipse.linuxtools.docker.core.IRegistryAccount;
import org.eclipse.linuxtools.internal.docker.core.DefaultImagePushProgressHandler;
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.ui.views.DVMessages;
import org.eclipse.linuxtools.internal.docker.ui.wizards.ImagePush;
import org.eclipse.swt.widgets.Display;
@@ -39,63 +40,80 @@ public class PushImageCommandHandler extends AbstractHandler {
private final static String PUSH_IMAGE_JOB_TASK = "ImagePush.msg"; //$NON-NLS-1$
private static final String ERROR_PUSHING_IMAGE = "ImagePushError.msg"; //$NON-NLS-1$
private static final String NO_CONNECTION = "NoConnection.error"; //$NON-NLS-1$
-
+
@Override
public Object execute(final ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final IDockerImage selectedImage = RunImageCommandHandler
.getSelectedImage(activePart);
- final ImagePush wizard = new ImagePush(selectedImage);
+ final ImagePush wizard = new ImagePush(selectedImage,
+ selectedImage.repo() + ":" + selectedImage.tags().get(0));
final boolean pushImage = CommandUtils.openWizard(wizard,
HandlerUtil.getActiveShell(event));
if (pushImage) {
final IDockerConnection connection = CommandUtils
.getCurrentConnection(activePart);
- IRegistry info = wizard.getRegistry();
- performPushImage(wizard, connection, info);
+ performPushImage(wizard, connection);
}
return null;
}
-
+
private void performPushImage(final ImagePush wizard,
- final IDockerConnection connection, final IRegistry info) {
+ final IDockerConnection connection) {
if (connection == null) {
Display.getDefault()
.syncExec(() -> MessageDialog.openError(
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell(),
DVMessages.getFormattedString(ERROR_PUSHING_IMAGE,
- wizard.getImageTag()),
+ wizard.getSelectedImageTag()),
DVMessages.getFormattedString(NO_CONNECTION)));
return;
}
final Job pushImageJob = new Job(DVMessages.getFormattedString(
- PUSH_IMAGE_JOB_TITLE, wizard.getImageTag())) {
+ PUSH_IMAGE_JOB_TITLE, wizard.getSelectedImageTag())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
- final String tag = wizard.getImageTag();
+ final IDockerImage image = wizard.getImage();
+ final String defaultImageNameTag = wizard.getDefaultImageName();
+ final String selectedImageNameTag = wizard
+ .getSelectedImageTag();
+ // TODO: remove cast once AbstractRegistry methods are
+ // part of the IRegistry interface
+ final AbstractRegistry registry = (AbstractRegistry) wizard
+ .getRegistry();
+ final boolean forceTagging = wizard.isForceTagging();
+ final boolean keepTaggedImage = wizard.isKeepTaggedImage();
+
monitor.beginTask(DVMessages.getString(PUSH_IMAGE_JOB_TASK),
IProgressMonitor.UNKNOWN);
+
// push the image and let the progress
// handler refresh the images when done
- String tmpRegistryTag = null;
- boolean createdTag = false;
+ final String tmpRegistryTag = getNameToTag(
+ selectedImageNameTag, registry);
+ boolean tagCreated = false;
try {
- String repo = info.getServerAddress();
- tmpRegistryTag = repo + '/' + tag;
- if (!connection.hasImage(repo, tag)) {
- connection.tagImage(tag, tmpRegistryTag);
- createdTag = true;
+ // tag image (if necessary or if '--force' option was
+ // selected)
+ if (!image.repoTags().contains(tmpRegistryTag)
+ || forceTagging) {
+ // TODO: remove cast to DockerConnection once the
+ // 'tagImage' is added in the public API
+ ((DockerConnection) connection).tagImage(
+ defaultImageNameTag, tmpRegistryTag,
+ forceTagging);
+ tagCreated = true;
}
-
- if (info instanceof IRegistryAccount) {
- IRegistryAccount acc = (IRegistryAccount) info;
- connection.pushImage(tmpRegistryTag, acc,
+ // push image
+ if (!registry.isAuthProvided()) {
+ connection.pushImage(tmpRegistryTag,
new DefaultImagePushProgressHandler(connection,
tmpRegistryTag));
} else {
- connection.pushImage(tmpRegistryTag,
+ final IRegistryAccount registryAccount = (IRegistryAccount) registry;
+ connection.pushImage(tmpRegistryTag, registryAccount,
new DefaultImagePushProgressHandler(connection,
tmpRegistryTag));
}
@@ -104,13 +122,13 @@ public class PushImageCommandHandler extends AbstractHandler {
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell(),
DVMessages.getFormattedString(ERROR_PUSHING_IMAGE,
- tag),
+ defaultImageNameTag),
e.getMessage()));
// for now
} catch (InterruptedException e) {
// do nothing
} finally {
- if (tmpRegistryTag != null && createdTag) {
+ if (tagCreated && !keepTaggedImage) {
try {
connection.removeTag(tmpRegistryTag);
connection.getImages(true);
@@ -127,5 +145,22 @@ public class PushImageCommandHandler extends AbstractHandler {
pushImageJob.schedule();
}
+ /**
+ * Computes the full repo/name/tag to apply on the given image
+ *
+ * @param repoTag
+ * the repo/tag that could be added
+ * @param registry
+ * the target registry where the image will be pushed
+ * @return the full image name to tag the image with, or <code>null</code>
+ * if the image already has this tag.
+ */
+ private static String getNameToTag(final String repoTag,
+ final AbstractRegistry registry) {
+ if (registry.isDockerHubRegistry()) {
+ return repoTag;
+ }
+ return registry.getServerHost() + '/' + repoTag;
+ }
}

Back to the top