com.github.dockerjava.api.command.PushImageCmd Java Examples

The following examples show how to use com.github.dockerjava.api.command.PushImageCmd. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PushImageCommand.java    From cubeai with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() throws DockerException {
	if (!StringUtils.isNotBlank(image)) {
		throw new IllegalArgumentException("Image name must be provided");
	}
	// Don't include tag in the image name. Docker daemon can't handle it.
	// put tag in query string parameter.
	String imageFullName = CommandUtils.imageFullNameFrom(registry, image, tag);
	final DockerClient client = getClient();
	PushImageCmd pushImageCmd = client.pushImageCmd(imageFullName).withTag(tag);
	PushImageResultCallback callback = new PushImageResultCallback() {
		@Override
		public void onNext(PushResponseItem item) {
			super.onNext(item);
		}

		@Override
		public void onError(Throwable throwable) {
			logger.error("Failed to push image:" + throwable.getMessage());
			super.onError(throwable);
		}
	};
	pushImageCmd.exec(callback).awaitSuccess();
}
 
Example #2
Source File: PushImageCmdExec.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Override
protected Void execute0(PushImageCmd command, ResultCallback<PushResponseItem> resultCallback) {
    WebTarget webResource = getBaseResource().path("/images/{imageName}/push")
        .resolveTemplate("imageName", command.getName())
        .queryParam("tag", command.getTag());

    LOGGER.trace("POST: {}", webResource);

    InvocationBuilder builder = resourceWithAuthConfig(command.getAuthConfig(), webResource.request())
            .accept(MediaType.APPLICATION_JSON);

    builder.post(null, new TypeReference<PushResponseItem>() {
    }, resultCallback);

    return null;
}
 
Example #3
Source File: DockerClientImpl.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Override
public PushImageCmd pushImageCmd(Identifier identifier) {
    PushImageCmd cmd = pushImageCmd(identifier.repository.name);
    if (identifier.tag.isPresent()) {
        cmd.withTag(identifier.tag.get());
    }

    AuthConfig cfg = dockerClientConfig.effectiveAuthConfig(identifier.repository.name);
    if (cfg != null) {
        cmd.withAuthConfig(cfg);
    }

    return cmd;
}
 
Example #4
Source File: PushImageCmdImpl.java    From docker-java with Apache License 2.0 5 votes vote down vote up
/**
 * @param name
 *            The name, e.g. "alexec/busybox" or just "busybox" if you want to default. Not null.
 */
@Override
public PushImageCmd withName(String name) {
    checkNotNull(name, "name was not specified");
    this.name = name;
    return this;
}
 
Example #5
Source File: PushImageCmdImpl.java    From docker-java with Apache License 2.0 5 votes vote down vote up
/**
 * @param tag
 *            The image's tag. Can be null or empty.
 */
@Override
public PushImageCmd withTag(String tag) {
    checkNotNull(tag, "tag was not specified");
    this.tag = tag;
    return this;
}
 
Example #6
Source File: DockerCloud.java    From docker-plugin with MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class)
public static void setRegistryAuthentication(PushImageCmd cmd, DockerRegistryEndpoint registry, ItemGroup context) {
    if (registry != null && registry.getCredentialsId() != null) {
        AuthConfig auth = getAuthConfig(registry, context);
        cmd.withAuthConfig(auth);
    }
}
 
Example #7
Source File: DockerBuilderPublisher.java    From docker-plugin with MIT License 5 votes vote down vote up
private void pushImages() throws IOException {
    for (String tagToUse : tagsToUse) {
        Identifier identifier = Identifier.fromCompoundString(tagToUse);
        PushImageResultCallback resultCallback = new PushImageResultCallback() {
            @Override
            public void onNext(PushResponseItem item) {
                if (item == null) {
                    // docker-java not happy if you pass it nulls.
                    log("Received NULL Push Response. Ignoring");
                    return;
                }
                printResponseItemToListener(listener, item);
                super.onNext(item);
            }
        };
        try(final DockerClient client = getClientWithNoTimeout()) {
            PushImageCmd cmd = client.pushImageCmd(identifier);

            int i = identifier.repository.name.indexOf('/');
            String regName = i >= 0 ?
                    identifier.repository.name.substring(0,i) : null;

            DockerCloud.setRegistryAuthentication(cmd,
                    new DockerRegistryEndpoint(regName, getPushCredentialsId()),
                    run.getParent().getParent());
            cmd.exec(resultCallback).awaitSuccess();
        } catch (DockerException ex) {
            // Private Docker registries fall over regularly. Tell the user so they
            // have some clue as to what to do as the exception gives no hint.
            log("Exception pushing docker image. Check that the destination registry is running.");
            throw ex;
        }
    }
}
 
Example #8
Source File: DockerClientImpl.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@Override
public PushImageCmd pushImageCmd(String name) {
    PushImageCmd cmd = new PushImageCmdImpl(getDockerCmdExecFactory().createPushImageCmdExec(),
            dockerClientConfig.effectiveAuthConfig(name), name);
    return cmd;
}
 
Example #9
Source File: AbstractDockerCmdExecFactory.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@Override
public PushImageCmd.Exec createPushImageCmdExec() {
    return new PushImageCmdExec(getBaseResource(), getDockerClientConfig());
}
 
Example #10
Source File: PushImageCmdImpl.java    From docker-java with Apache License 2.0 4 votes vote down vote up
public PushImageCmdImpl(PushImageCmd.Exec exec, AuthConfig authConfig, String name) {
    super(exec);
    withName(name);
    withAuthConfig(authConfig);
}
 
Example #11
Source File: PushImageCmdImpl.java    From docker-java with Apache License 2.0 4 votes vote down vote up
public PushImageCmd withAuthConfig(AuthConfig authConfig) {
    this.authConfig = authConfig;
    return this;
}
 
Example #12
Source File: DelegatingDockerClient.java    From docker-plugin with MIT License 4 votes vote down vote up
@Override
public PushImageCmd pushImageCmd(String arg0) {
    return getDelegate().pushImageCmd(arg0);
}
 
Example #13
Source File: DelegatingDockerClient.java    From docker-plugin with MIT License 4 votes vote down vote up
@Override
public PushImageCmd pushImageCmd(Identifier arg0) {
    return getDelegate().pushImageCmd(arg0);
}
 
Example #14
Source File: DockerClient.java    From docker-java with Apache License 2.0 votes vote down vote up
PushImageCmd pushImageCmd(@Nonnull String name); 
Example #15
Source File: DockerClient.java    From docker-java with Apache License 2.0 votes vote down vote up
PushImageCmd pushImageCmd(@Nonnull Identifier identifier);