Browse Source

优化git

master
educoder 3 years ago
parent
commit
556724c135
4 changed files with 33 additions and 10 deletions
  1. +23
    -0
      common/src/main/java/com/imitate/common/util/StringUtil.java
  2. +5
    -5
      common/src/main/resources/common.properties
  3. +4
    -4
      web/src/main/java/com/imitate/web/module/game/controller/VscodeController.java
  4. +1
    -1
      web/src/main/java/com/imitate/web/module/game/service/GitAccountService.java

+ 23
- 0
common/src/main/java/com/imitate/common/util/StringUtil.java View File

@@ -14,4 +14,27 @@ public class StringUtil {
public static String replaceLineSeparator(String source) {
return source.replace("\r\n", "\n").replace("\r", "\n");
}

/**
* 字符串若超出长度截取部分
* @param source
* @return
*/
public static String substring(String source){
if (source.length() > 10) {
return source.substring(0,5);
}
return source;
}


/**
* 根据项目id 和userid 生成pod名称
* @param projectId
* @param userId
* @return
*/
public static String getPodName(String projectId,String userId){
return substring(projectId) + "-" + substring(userId);
}
}

+ 5
- 5
common/src/main/resources/common.properties View File

@@ -26,14 +26,14 @@ registry=BRI_DOCKER_REGISTRY


#GIT_IP
gitIP=172.16.94.154
gitBackUpIP=172.16.94.154
gitPort=30122
gitIP=118.31.13.117
gitBackUpIP=118.31.13.117
gitPort=64300
gitBackupDirs=/opt/repositories/2018,/opt/repositories/2018-2
gitRepoDir=/opt/repositories
#git\u7528\u6237\u540d\u53ca\u5bc6\u7801
gitUsername=edugit
gitPassword=xinedugit#
gitUsername=wangwei10061
gitPassword=wang199637

workspace=/opt/workspace
secretWorkspace=/opt/workspace/secret


+ 4
- 4
web/src/main/java/com/imitate/web/module/game/controller/VscodeController.java View File

@@ -81,7 +81,7 @@ public class VscodeController extends BasicController {
if(bindingResult.hasErrors()){
return actionResultWithBindingResult(ErrorCodeEnum.BIND_EXCEPTION,bindingResult);
}
vsCodeParam.setTpiID(vsCodeParam.getProjectId() + "-" + vsCodeParam.getUserId());
vsCodeParam.setTpiID(StringUtil.getPodName(vsCodeParam.getProjectId(),vsCodeParam.getUserId()));
logger.info("[start]获取vscode连接信息 {}", JSONObject.toJSONString(vsCodeParam));
JSONObject resp = new JSONObject();

@@ -157,7 +157,7 @@ public class VscodeController extends BasicController {
if(bindingResult.hasErrors()){
return actionResultWithBindingResult(ErrorCodeEnum.BIND_EXCEPTION,bindingResult);
}
String tpiID = vsCodeDeleteParam.getProjectId() + "-" + vsCodeDeleteParam.getUserID();
String tpiID = StringUtil.getPodName(vsCodeDeleteParam.getProjectId(), vsCodeDeleteParam.getUserID());
logger.info("[start]前端主动调用vscode删除命令,tpiID: {}", tpiID);

String tpiRepoName = TpCsts.TP_UNIFY_REPO_NAME;
@@ -187,7 +187,7 @@ public class VscodeController extends BasicController {
@RequestMapping(path = "/active", method = RequestMethod.POST)
public R active(@RequestParam String projectId, @RequestParam String userId) {
logger.info("[start]激活vscode pod projectId:{},延长到期时间 userId:{}", projectId,userId);
String tpiID = projectId + "-" + userId;
String tpiID = StringUtil.getPodName(projectId ,userId);
vscodeService.active(tpiID);
logger.info("[end]激活vscode pod {},延长到期时间", tpiID);
return R.ok();
@@ -197,7 +197,7 @@ public class VscodeController extends BasicController {

@RequestMapping(path = "/getPort",method = RequestMethod.POST)
public R getPort(@RequestParam String projectId, @RequestParam String userId, @RequestParam Integer type, @RequestParam Integer port) {
String tpiID = projectId + "-" + userId;
String tpiID = StringUtil.getPodName(projectId, userId);
int proxyPort = proxyService.getContainerExternalMappingPort(tpiID, type, port);
return R.ok().setData(MapUtil.builder("port", proxyPort).build());
}


+ 1
- 1
web/src/main/java/com/imitate/web/module/game/service/GitAccountService.java View File

@@ -36,7 +36,7 @@ public class GitAccountService {
logger.debug("获取git凭证信息: {}", out);
if (StringUtils.isEmpty(out) || !out.contains(username) || !out.contains(password)) {
String setCmd = "git config --global user.email educoder@163.com"
+ " && git config --global user.name educoder" + " && git config --global credential.helper store"
+ " && git config --global user.name wangwei10061\n" + " && git config --global credential.helper store"
+ " && echo -e 'protocol=" + protocol + "\nhost=" + gitIP + "\nusername=" + username + "\npassword="
+ password + "' | git credential approve";
setGitCredential(setCmd, gitIP);


Loading…
Cancel
Save