|
|
@@ -19,14 +19,7 @@ import java.io.IOException;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
-public class StaticPack implements CodePacker {
|
|
|
- // TODO 必须指定构建存在的目录
|
|
|
- private String artifactPath;
|
|
|
-
|
|
|
- /*public StaticPack(String artifactPath) {
|
|
|
- this.artifactPath = artifactPath;
|
|
|
- }*/
|
|
|
-
|
|
|
+public class OssStaticPack implements CodePacker {
|
|
|
private void createTargetDir(String targetPath) throws IOException {
|
|
|
File dir = new File(targetPath);
|
|
|
if (!dir.exists()) {
|
|
|
@@ -34,30 +27,32 @@ public class StaticPack implements CodePacker {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //@Override
|
|
|
- public String pack(String appId, String commitId, String appRootPath, String dockerfile) throws Exception {
|
|
|
- if (artifactPath == null) {
|
|
|
- throw new Exception("存放编译产物的路径 artifactPath 不能是 null");
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void pack(PipelineContext ctx, PackerConfig packerConfig) {
|
|
|
+ String appId = ctx.getAppId();
|
|
|
+ String commitId = ctx.getCommitInfo().getCommitId();
|
|
|
+ String artifactPath = packerConfig.getArtifactPath();
|
|
|
|
|
|
- String sourceDirPath = appRootPath + File.separator + artifactPath;
|
|
|
+ String sourceCodeDir = ctx.getCompileDir();
|
|
|
+ String sourceDirPath = sourceCodeDir + File.separator + artifactPath;
|
|
|
File srcDir = new File(sourceDirPath);
|
|
|
String targetDirPath = LocalBuildDir.packDir + File.separator + appId;
|
|
|
- createTargetDir(targetDirPath);
|
|
|
-
|
|
|
- String dirname = String.format("%s_%s", appId, commitId);
|
|
|
- String destDirPath = targetDirPath + File.separator + dirname;
|
|
|
- File destDir = new File(destDirPath);
|
|
|
- if (destDir.exists()) {
|
|
|
- FileUtils.deleteDirectory(destDir);
|
|
|
- log.info("delete exist dir {}", destDirPath);
|
|
|
+ try {
|
|
|
+ createTargetDir(targetDirPath);
|
|
|
+
|
|
|
+ String dirname = String.format("%s_%s", appId, commitId);
|
|
|
+ String destDirPath = targetDirPath + File.separator + dirname;
|
|
|
+ File destDir = new File(destDirPath);
|
|
|
+ if (destDir.exists()) {
|
|
|
+ FileUtils.deleteDirectory(destDir);
|
|
|
+ log.info("delete exist dir {}", destDirPath);
|
|
|
+ }
|
|
|
+ FileUtils.copyDirectory(srcDir, destDir);
|
|
|
+ ctx.setBuildTargetPath(destDirPath);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- FileUtils.copyDirectory(srcDir, destDir);
|
|
|
- return "";
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void pack(PipelineContext ctx, PackerConfig packerConfig) {
|
|
|
}
|
|
|
|
|
|
@Override
|