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(); } }
@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(); } }
/** * 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); } }