private static void setAuthFromFile(final PullImageCmd pullImageCmd, final DefaultDockerClientConfig dockerClientConfig, final String imageName) { final AuthConfig authConfig = dockerClientConfig.effectiveAuthConfig(imageName); if (authConfig != null) { pullImageCmd.withAuthConfig(authConfig); } }
@Restricted(NoExternalUse.class) public static void setRegistryAuthentication(PullImageCmd cmd, DockerRegistryEndpoint registry, ItemGroup context) { if (registry != null && registry.getCredentialsId() != null) { AuthConfig auth = getAuthConfig(registry, context); cmd.withAuthConfig(auth); } }
/** * Produces a pull image request * * @param client * @param message * @return */ private PullImageCmd executePullImageRequest(DockerClient client, Message message) { LOGGER.debug("Executing Docker Pull Image Request"); String repository = DockerHelper.getProperty(DockerConstants.DOCKER_REPOSITORY, configuration, message, String.class); ObjectHelper.notNull(repository, "Repository must be specified"); PullImageCmd pullImageCmd = client.pullImageCmd(repository); String registry = DockerHelper.getProperty(DockerConstants.DOCKER_REGISTRY, configuration, message, String.class); if (registry != null) { pullImageCmd.withRegistry(registry); } String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class); if (tag != null) { pullImageCmd.withTag(tag); } AuthConfig authConfig = client.authConfig(); if (authConfig != null) { pullImageCmd.withAuthConfig(authConfig); } return pullImageCmd; }
/** * Pull docker image using the docker java client. * * @param imageTag * @param username * @param password * @param host */ public static void pullImage(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.pullImageCmd(imageTag).withAuthConfig(authConfig).exec(new PullImageResultCallback()).awaitSuccess(); } finally { closeQuietly(dockerClient); } }
registry.getIsPublic() ? dockerClient.pullImageCmd(image).withRegistry(registry.getUrl()) : dockerClient.pullImageCmd(image).withAuthConfig( new AuthConfig() .withRegistryAddress(registry.getUrl())
pullImageCmd.withAuthConfig(authConfig);