Kaynağa Gözat

格式化 PipelineContext 中的 dockerRegistry 字段

reghao 1 gün önce
ebeveyn
işleme
93148acc8d

+ 9 - 2
mgr/src/main/java/cn/reghao/devops/mgr/ops/builder/service/PipelineContext.java

@@ -37,6 +37,7 @@ public class PipelineContext implements AutoCloseable {
     private String compileDir;
     private String dockerfile;
     private CommitInfo commitInfo;
+    // 格式为 registry.cn-chengdu.aliyuncs.com/reghao
     private String dockerRegistry;
     private String buildTargetPath;
 
@@ -79,8 +80,7 @@ public class PipelineContext implements AutoCloseable {
     public String getRepoTag() {
         String repoTag = String.format("%s:%s", appId, commitInfo.getCommitId());
         if (dockerRegistry != null) {
-            repoTag = String.format("%s:%s", dockerRegistry, repoTag);
-            repoTag = simplifyPath(repoTag);
+            repoTag = String.format("%s/%s", dockerRegistry, repoTag);
         }
         return repoTag;
     }
@@ -92,6 +92,13 @@ public class PipelineContext implements AutoCloseable {
         return path.replaceAll("(?<!:)/{2,}", "/");
     }
 
+    public void setDockerRegistry(String dockerRegistry) {
+        this.dockerRegistry= simplifyPath(dockerRegistry);
+        if (this.dockerRegistry.endsWith("/")) {
+            this.dockerRegistry = this.dockerRegistry.substring(0, this.dockerRegistry.length() - 1);
+        }
+    }
+
     /**
      * 更新或创建阶段状态
      */