com.github.dockerjava.core.command.PushImageResultCallback Java Examples

The following examples show how to use com.github.dockerjava.core.command.PushImageResultCallback. 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: DockerOpt.java    From dew with Apache License 2.0 6 votes vote down vote up
/**
 * Push.
 *
 * @param imageName the image name
 * @param auth      the auth
 * @param awaitSec  the await sec
 */
public void push(String imageName, boolean auth, long awaitSec) {
    PushImageCmd pushImageCmd = docker.pushImageCmd(imageName);
    if (auth) {
        pushImageCmd.withAuthConfig(defaultAuthConfig);
    }
    try {
        pushImageCmd.exec(new PushImageResultCallback() {
            @Override
            public void onNext(PushResponseItem item) {
                super.onNext(item);
                log.debug(item.toString());
            }
        }).awaitCompletion(awaitSec, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        log.error("Push image error.", e);
    }
}
 
Example #3
Source File: DockerServiceImpl.java    From Dolphin with Apache License 2.0 6 votes vote down vote up
private void pushImage(DockerfileRequest request, DockerfileResponse response) {
    logger.info(String.format("begin pushImage: %s", request));

    try {
        String repositoryName = buildRepositoryName(request);
        Repository repository = new Repository(repositoryName);
        Identifier identifier = new Identifier(repository, request.getAppTag());
        dockerClient.pushImageCmd(identifier).exec(new PushImageResultCallback() {
            @Override
            public void onNext(PushResponseItem item) {
                super.onNext(item);
                if (logger.isDebugEnabled()) {
                    logger.debug(item);
                }
            }
        }).awaitSuccess();

        response.setRepository(String.format("%s:%s", repositoryName, request.getAppTag()));
    } catch (Exception e) {
        response.fail(e.toString());
        logger.error(String.format("error pushImage: %s", request), e);
    }

    logger.info(String.format("end pushImage: %s", response));
}
 
Example #4
Source File: ImagePullPolicyTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
    String testRegistryAddress = registry.getHost() + ":" + registry.getFirstMappedPort();
    String testImageName = testRegistryAddress + "/image-pull-policy-test";
    String tag = UUID.randomUUID().toString();
    imageName = testImageName + ":" + tag;

    DockerClient client = DockerClientFactory.instance().client();
    String dummySourceImage = "hello-world:latest";
    client.pullImageCmd(dummySourceImage).exec(new PullImageResultCallback()).awaitCompletion();

    String dummyImageId = client.inspectImageCmd(dummySourceImage).exec().getId();

    // push the image to the registry
    client.tagImageCmd(dummyImageId, testImageName, tag).exec();

    client.pushImageCmd(imageName)
        .exec(new PushImageResultCallback())
        .awaitCompletion(1, TimeUnit.MINUTES);
}
 
Example #5
Source File: DockerJavaUtil.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
public static void pushImage(DockerClient client,String pushTag, String registryAddress,String username, String password) throws InterruptedException {
    AuthConfig authConfig = new AuthConfig()
            .withRegistryAddress(registryAddress)
            .withUsername(username)
            .withPassword(password);

    PushImageResultCallback pushImageResultCallback = new PushImageResultCallback();
    client.pushImageCmd(pushTag).withAuthConfig(authConfig).exec(pushImageResultCallback).awaitCompletion(600, TimeUnit.SECONDS);;

}
 
Example #6
Source File: DockerJavaTest.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Test
public void test_7_push_image() throws Exception {

    PushImageResultCallback pushImageResultCallback = new PushImageResultCallback();

    AuthConfig authConfig = new AuthConfig()
            .withRegistryAddress("wl4g.harbor")
            .withUsername("admin")
            .withPassword("Shangmai7782");

    dockerClient.pushImageCmd("wl4g.harbor/my_first_project/trends:0.1.1-beta1").withAuthConfig(authConfig).exec(pushImageResultCallback)
            .awaitCompletion(300, TimeUnit.SECONDS);
    System.out.println("finish");
}
 
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: ImageLiveTest.java    From tutorials with MIT License 2 votes vote down vote up
public void pushingAnImage() throws InterruptedException {

        dockerClient.pushImageCmd("baeldung/alpine").withTag("3.6.v2").exec(new PushImageResultCallback()).awaitCompletion(90, TimeUnit.SECONDS);
    }