@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; }
private String name(PushImageCmd command) { String name = command.getName(); AuthConfig authConfig = command.getAuthConfig(); return (name.contains("/") || authConfig == null) ? name : authConfig.getUsername(); }
@Override protected AbstractCallbackNotifier<PushResponseItem> callbackNotifier(PushImageCmd command, ResultCallback<PushResponseItem> resultCallback) { WebTarget webResource = getBaseResource().path("/images/" + name(command) + "/push").queryParam("tag", command.getTag()); LOGGER.trace("POST: {}", webResource); Builder builder = resourceWithAuthConfig(command.getAuthConfig(), webResource.request()) .accept(MediaType.APPLICATION_JSON); return new POSTCallbackNotifier<PushResponseItem>(new JsonStreamProcessor<PushResponseItem>( PushResponseItem.class), resultCallback, builder, entity(null, MediaType.APPLICATION_JSON)); } }
private void push(Id id) { for (final Identifier identifier : identifiers(id)) { try { final PushImageCmd pushImageCmd = docker.pushImageCmd(identifier.repository.name); if (identifier.tag.isPresent()) { pushImageCmd.withTag(identifier.tag.get()); } logger.info("Pushing " + id + " (" + asString(identifier) + ")"); final PushImageResultCallback callback = new PushImageResultCallback() { public void onNext(final PushResponseItem item) { super.onNext(item); logger.info(buildResponseItemToString(item).replaceAll("\\r?\\n$", "")); } }; pushImageCmd.exec(callback).awaitSuccess(); } catch (DockerException | DockerClientException e) { throw new OrchestrationException(e); } } }
private void putImageInRegistry() throws InterruptedException { // It doesn't matter which image we use for this test, but use one that's likely to have been pulled already final String dummySourceImage = TestcontainersConfiguration.getInstance().getRyukImage(); client.pullImageCmd(dummySourceImage) .exec(new PullImageResultCallback()) .awaitCompletion(1, TimeUnit.MINUTES); final String id = client.inspectImageCmd(dummySourceImage) .exec() .getId(); // push the image to the registry client.tagImageCmd(id, testImageName, "latest").exec(); client.pushImageCmd(testImageNameWithTag) .exec(new PushImageResultCallback()) .awaitCompletion(1, TimeUnit.MINUTES); // remove the image tag from local docker so that it must be pulled before use client.removeImageCmd(testImageNameWithTag).withForce(true).exec(); } }
/** * Push docker image using the docker java client. * * @param imageTag * @param username * @param password * @param host */ public static void pushImage(String imageTag, String username, String password, String host) throws IOException { final AuthConfig authConfig = new AuthConfig(); authConfig.withUsername(username); authConfig.withPassword(password); DockerClient dockerClient = null; try { dockerClient = getDockerClient(host); dockerClient.pushImageCmd(imageTag).withAuthConfig(authConfig).exec(new PushImageResultCallback()).awaitSuccess(); } finally { closeQuietly(dockerClient); } }
@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); } }
public Void call() throws Exception { final ConsoleLogger console = new ConsoleLogger(listener); DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, authConfig); PushImageCmd pushImageCmd = client.pushImageCmd(imageRes).withTag(tagRes); PushImageResultCallback callback = new PushImageResultCallback() { @Override public void onNext(PushResponseItem item) { console.logInfo(item.toString()); super.onNext(item); } @Override public void onError(Throwable throwable) { console.logError("Failed to exec start:" + throwable.getMessage()); super.onError(throwable); } }; pushImageCmd.exec(callback).awaitSuccess(); return null; }
new DockerRegistryEndpoint(registry, pushCredentialsId), run.getParent().getParent()); cmd.exec(resultCallback).awaitSuccess(); } catch (DockerException ex) {
@Override protected Void execute0(PushImageCmd command, ResultCallback<PushResponseItem> resultCallback) { WebTarget webResource = getBaseResource().path("/images/" + name(command) + "/push").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; } }
@TaskAction public void runTask() { String dockerUser = getProperty("DOCKER_USER", "docker.user"); String dockerPassword = getProperty("DOCKER_PASSWORD", "docker.password"); String dockerEmail = getProperty("DOCKER_EMAIL", "docker.email"); DockerClient dockerClient = DockerClientBuilder .getInstance(DefaultDockerClientConfig.createDefaultConfigBuilder() .withRegistryUsername(dockerUser) .withRegistryPassword(dockerPassword) .withRegistryEmail(dockerEmail)) .build(); for (String tag : tags) { PushImageCmd pushImageCmd = dockerClient.pushImageCmd(repository); pushImageCmd.withTag(tag).exec(new PushImageResultCallback()).awaitSuccess(); } }
@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; }
cmd.exec(resultCallback).awaitSuccess();
private String name(PushImageCmd command) { String name = command.getName(); AuthConfig authConfig = command.getAuthConfig(); return (name.contains("/") || authConfig == null) ? name : authConfig.getUsername(); }
@Override protected AbstractCallbackNotifier<PushResponseItem> callbackNotifier(PushImageCmd command, ResultCallback<PushResponseItem> resultCallback) { WebTarget webResource = getBaseResource().path("/images/" + name(command) + "/push").queryParam("tag", command.getTag()); LOGGER.trace("POST: {}", webResource); Builder builder = resourceWithAuthConfig(command.getAuthConfig(), webResource.request()) .accept(MediaType.APPLICATION_JSON); return new POSTCallbackNotifier<PushResponseItem>(new JsonStreamProcessor<PushResponseItem>( PushResponseItem.class), resultCallback, builder, entity(null, MediaType.APPLICATION_JSON)); } }
/** * Produces a push image request * * @param client * @param message * @return */ private PushImageCmd executePushImageRequest(DockerClient client, Message message) { LOGGER.debug("Executing Docker Push Image Request"); String name = DockerHelper.getProperty(DockerConstants.DOCKER_NAME, configuration, message, String.class); ObjectHelper.notNull(name, "Image name must be specified"); PushImageCmd pushImageCmd = client.pushImageCmd(name); String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class); if (tag != null) { pushImageCmd.withTag(tag); } AuthConfig authConfig = client.authConfig(); if (authConfig != null) { pushImageCmd.withAuthConfig(authConfig); } return pushImageCmd; }
result = executePushImageRequest(client, message).exec(new PushImageResultCallback() { @Override public void onNext(PushResponseItem item) {
private String name(PushImageCmd command) { String name = command.getName(); AuthConfig authConfig = command.getAuthConfig(); return (name.contains("/") || authConfig == null) ? name : authConfig.getUsername(); }
@Override protected Void execute0(PushImageCmd command, ResultCallback<PushResponseItem> resultCallback) { WebTarget webResource = getBaseResource().path("/images/" + name(command) + "/push").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; } }
private String name(PushImageCmd command) { String name = command.getName(); AuthConfig authConfig = command.getAuthConfig(); return (name.contains("/") || authConfig == null) ? name : authConfig.getUsername(); }