Skip to content

Commit 4fb7653

Browse files
committed
run in docker directly build not start docker
1 parent f7b57d3 commit 4fb7653

File tree

7 files changed

+42
-11
lines changed

7 files changed

+42
-11
lines changed

docker/app-api.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jfiglet.message = FlowCi Started Success
3838
## plugin repos url
3939
plugins.repository = https://raw.githubusercontent.com/flowci/plugins/master/repository.json
4040

41+
api.run.indocker = false
42+
4143
task.job.toggle.execution_timeout = true
4244
## 6s expire job
4345
task.job.toggle.execution_create_session_duration = 1800

platform-api/src/main/resources/app-default.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ api.user.expire = 604800
2525
## plugin setting
2626
plugins.repository = https://raw.githubusercontent.com/flowci/plugins/master/repository.json
2727

28+
api.run.indocker = false
29+
2830
### domain ###
2931
domain.api = http://localhost:8088
3032
domain.web = http://localhost:3000

platform-api/src/test/resources/app-test.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ api.user.expire = 60000
2424

2525
## plugin setting
2626
plugins.repository = https://raw.githubusercontent.com/yunheli/plugins/master/repository.json
27+
api.run.indocker = false
2728

2829
### domain ###
2930
domain.api = http://localhost:8080

platform-plugin/src/main/java/com/flow/platform/plugin/service/PluginServiceImpl.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
import com.flow.platform.plugin.event.PluginRefreshEvent.Status;
3131
import com.flow.platform.plugin.event.PluginStatusChangeEvent;
3232
import com.flow.platform.plugin.exception.PluginException;
33+
import com.flow.platform.plugin.util.CmdUtil;
3334
import com.flow.platform.plugin.util.YmlUtil;
3435
import com.flow.platform.plugin.util.docker.Docker;
36+
import com.flow.platform.util.CommandUtil.Unix;
3537
import com.flow.platform.util.ExceptionUtil;
3638
import com.flow.platform.util.Logger;
3739
import com.flow.platform.util.git.GitException;
@@ -55,6 +57,7 @@
5557
import org.eclipse.jgit.api.Git;
5658
import org.eclipse.jgit.revwalk.RevCommit;
5759
import org.springframework.beans.factory.annotation.Autowired;
60+
import org.springframework.beans.factory.annotation.Value;
5861
import org.springframework.scheduling.annotation.Scheduled;
5962
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
6063
import org.springframework.stereotype.Service;
@@ -83,6 +86,9 @@ public class PluginServiceImpl extends ApplicationEventService implements Plugin
8386

8487
private final static String TMP = "tmp";
8588

89+
@Value("${api.run.indocker}")
90+
private boolean runInDocker;
91+
8692
// git clone folder
8793
@Autowired
8894
private Path gitWorkspace;
@@ -447,7 +453,8 @@ public void exec(Plugin plugin) {
447453
try {
448454

449455
// only build and image all in value to pull image
450-
if (!Strings.isBlank(plugin.getPluginDetail().getBuild()) && !Strings.isBlank(plugin.getPluginDetail().getImage())) {
456+
if (!Strings.isBlank(plugin.getPluginDetail().getBuild()) && !Strings
457+
.isBlank(plugin.getPluginDetail().getImage())) {
451458

452459
LOGGER.traceMarker("BuildProcessor", "Start build code");
453460

@@ -457,7 +464,12 @@ public void exec(Plugin plugin) {
457464
JGitUtil.checkout(cachePath, latestGitTag);
458465

459466
// first pull image and build
460-
dockerPullAndBuild(plugin);
467+
if (!runInDocker) {
468+
dockerPullAndBuild(plugin);
469+
} else {
470+
// if run in docker only build
471+
build(plugin);
472+
}
461473

462474
// second detect outputs
463475
detectBuildArtifacts(plugin);
@@ -475,6 +487,12 @@ public void exec(Plugin plugin) {
475487
}
476488
}
477489

490+
private void build(Plugin plugin) {
491+
Path cachePath = gitCachePath(plugin);
492+
String cmd = "cd " + cachePath.toString() + Unix.LINE_SEPARATOR + plugin.getPluginDetail().getBuild();
493+
CmdUtil.exeCmd(cmd);
494+
}
495+
478496
private void dockerPullAndBuild(Plugin plugin) {
479497
Path cachePath = gitCachePath(plugin);
480498
Docker docker = new Docker();
@@ -565,7 +583,8 @@ private class PushProcessor implements Processor {
565583
public void exec(Plugin plugin) {
566584
LOGGER.traceMarker("PushProcessor", "Push tags to local");
567585

568-
if (!Strings.isBlank(plugin.getPluginDetail().getImage()) && !Strings.isBlank(plugin.getPluginDetail().getBuild())) {
586+
if (!Strings.isBlank(plugin.getPluginDetail().getImage()) && !Strings
587+
.isBlank(plugin.getPluginDetail().getBuild())) {
569588
return;
570589
}
571590

platform-plugin/src/main/java/com/flow/platform/plugin/util/ShellUtil.java renamed to platform-plugin/src/main/java/com/flow/platform/plugin/util/CmdUtil.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@
1717
package com.flow.platform.plugin.util;
1818

1919
import com.flow.platform.plugin.exception.PluginException;
20+
import com.flow.platform.util.CommandUtil.Unix;
2021
import com.flow.platform.util.Logger;
2122
import java.io.BufferedReader;
2223
import java.io.InputStreamReader;
2324

2425
/**
2526
* @author yh@firim
2627
*/
27-
public class ShellUtil {
28+
public class CmdUtil {
2829

29-
private final static Logger LOGGER = new Logger(ShellUtil.class);
30+
private final static Logger LOGGER = new Logger(CmdUtil.class);
3031

3132
public static void exeCmd(String shell) {
3233
BufferedReader br;
3334
try {
3435
Process process;
35-
ProcessBuilder pb = new ProcessBuilder("/bin/bash", "-c", shell);
36+
ProcessBuilder pb = new ProcessBuilder(Unix.CMD_EXECUTOR, "-c", shell);
3637
pb.environment();
3738
pb.redirectErrorStream(true); // merge error stream into standard stream
3839
process = pb.start();
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package com.flow.platform.plugin.test.util;
22

33
import com.flow.platform.plugin.test.TestBase;
4-
import com.flow.platform.plugin.util.ShellUtil;
4+
import com.flow.platform.plugin.util.CmdUtil;
55
import org.junit.Test;
6+
import org.springframework.beans.factory.annotation.Value;
67

78
/**
89
* @author yh@firim
910
*/
1011
public class ShellUtilTest extends TestBase{
1112

13+
@Value("${api.run.indocker}")
14+
private boolean runInDocker;
15+
16+
1217
@Test
1318
public void should_exec_cmd_success() {
14-
ShellUtil.exeCmd("echo helloworld");
15-
ShellUtil.exeCmd("pwd");
16-
ShellUtil.exeCmd("mvn");
19+
CmdUtil.exeCmd("echo helloworld");
20+
CmdUtil.exeCmd("pwd");
21+
CmdUtil.exeCmd("mvn");
1722
}
1823
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
api.git.cache = /tmp/flow-ci-ut/git-cache
22
api.git.workspace = /tmp/flow-ci-ut/git-clone
3-
plugins.repository = http://localhost:8080/repos/plugin.json
3+
plugins.repository = http://localhost:8080/repos/plugin.json
4+
api.run.indocker = false

0 commit comments

Comments
 (0)