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