Authored by xutao.liu

Merge branch 'feature/docker-api-20220816' into 'master'

修复项目发布docker无法获取镜像

修复项目发布docker无法获取镜像

See merge request !2
... ... @@ -15,6 +15,12 @@
<dependencies>
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java-tcr</artifactId>
<version>3.1.572</version>
</dependency>
<dependency>
<groupId>com.offbytwo.jenkins</groupId>
<artifactId>jenkins-client</artifactId>
<version>0.3.7</version>
... ...
... ... @@ -3,6 +3,7 @@ package com.monitor.other.worksystem.dock.qq;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.slf4j.Logger;
... ... @@ -107,12 +108,17 @@ public class DockerServerDeployService {
public List<String> queryImageList(String reponame,int offset,boolean includeLatest) {
List<String> stores=new ArrayList<>();
JSONObject searchResult = txServer.describeImageList(reponame,offset );
if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){
JSONArray ja=searchResult.getJSONObject("data").getJSONArray("tagInfo");
// JSONObject searchResult = txServer.describeImageList(reponame,offset );
JSONObject searchResult = TrcClientUtil.getImageTagList(reponame, offset);
if (searchResult == null) {
logger.warn("queryImageList searchResult is null param reponame:{} offset:{}", reponame, offset);
return Lists.newArrayListWithCapacity(0);
}
if(searchResult.getJSONObject("Data") != null){
JSONArray ja=searchResult.getJSONObject("Data").getJSONArray("TagInfo");
if(ja!=null&&ja.size()>0){
for(int i=0;i<ja.size();i++){
String tagName=ja.getJSONObject(i).getString("tagName");
String tagName=ja.getJSONObject(i).getString("TagName");
if(!"latest".equals(tagName)){
stores.add(tagName);
}else{
... ...
package com.monitor.other.worksystem.dock.qq;
import com.alibaba.fastjson.JSONObject;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.tcr.v20190924.TcrClient;
import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalRequest;
import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author xutao.liu@yoho.cn 2022/8/17 17:19
*/
public class TrcClientUtil {
private static final Logger logger = LoggerFactory.getLogger(TrcClientUtil.class);
private static final String SECRET_ID = "AKIDIMBl59hWpsgFYel7YljRu89wUmpchUYO";
private static final String SECRET_KEY = "kGXYKq8evxkI0VmpfGcjbEckdHgqlRr3";
private static final String REGION = "ap-guangzhou";
private static final String ENDPOINT = "tcr.tencentcloudapi.com";
private static TcrClient tcrClient = null;
private TrcClientUtil() {
}
/**
* 获取个人版镜像仓库tag列表
*
* @author xutao.liu@yoho.cn
* 2022/8/17 18:26
*/
static JSONObject getImageTagList(String repoName, long offset) {
if (StringUtils.isBlank(repoName)) {
logger.warn("getImageTagList param repoName is blank");
return null;
}
// 实例化一个请求对象,每个接口都会对应一个request对象
DescribeImagePersonalRequest req = new DescribeImagePersonalRequest();
req.setRepoName(repoName);
req.setOffset(offset);
// 返回的resp是一个DescribeImagePersonalResponse的实例,与请求对象对应
DescribeImagePersonalResponse resp;
try {
resp = getTcrClient().DescribeImagePersonal(req);
} catch (TencentCloudSDKException e) {
logger.error("getImageTagList cause exception repoName:{}", repoName, e);
return null;
}
// 输出json格式的字符串回包
String resultStr = DescribeImagePersonalResponse.toJsonString(resp);
logger.info("DescribeImagePersonalResponse result:{}", resultStr);
return JSONObject.parseObject(resultStr);
}
private static TcrClient getTcrClient() {
if (tcrClient == null) {
synchronized (TrcClientUtil.class) {
if (tcrClient == null) {
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = new Credential(SECRET_ID, SECRET_KEY);
// 实例化一个http选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = new HttpProfile();
httpProfile.setConnTimeout(2); // 请求连接超时时间,单位为秒(默认60秒)
httpProfile.setReadTimeout(1); // 设置读取超时时间,单位为秒(默认0秒)
httpProfile.setEndpoint(ENDPOINT);
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
tcrClient = new TcrClient(cred, REGION, clientProfile);
}
}
}
return tcrClient;
}
public static void main(String[] args) {
JSONObject resultStr = getImageTagList("yoho-online/yohobuywap-node-activity", 0);
System.out.println(resultStr);
}
}
... ...