Skip to content

Commit 08929a3

Browse files
authored
Merge pull request #371 from FlowCI/feature/1501
Feature/1501
2 parents e5ac5d3 + 3fc72ef commit 08929a3

35 files changed

+194
-71
lines changed

.run/Application - 1.run.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Application - 1" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
3+
<module name="core" />
4+
<option name="SPRING_BOOT_MAIN_CLASS" value="com.flowci.core.Application" />
5+
<option name="VM_PARAMETERS" value="-Xms1g -Xmx1g -Xmn600m -XX:-UseAdaptiveSizePolicy -XX:SurvivorRatio=4 -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails" />
6+
<option name="ALTERNATIVE_JRE_PATH" />
7+
<envs>
8+
<env name="FLOWCI_LOG_LEVEL" value="DEBUG" />
9+
<env name="FLOWCI_PLUGIN_URL" value="https://raw.githubusercontent.com/FlowCI/plugins/develop/repository.json" />
10+
<env name="FLOWCI_RABBITMQ_URI" value="amqp://guest:[email protected]:5672" />
11+
<env name="FLOWCI_ZK_HOST" value="127.0.0.1" />
12+
<env name="FLOWCI_AUTO_AGENT" value="false" />
13+
<env name="FLOWCI_AGENT_VOLUMES" value="name=pyenv,dest=/ci/python,script=init.sh,image=flowci/pyenv:1.3,init=init-pyenv-volume.sh" />
14+
<env name="FLOWCI_SERVER_PORT" value="8080" />
15+
<env name="FLOWCI_TEMPLATES" value="https://raw.githubusercontent.com/FlowCI/templates/master/templates.json" />
16+
<env name="FLOWCI_AGENT_IMAGE" value="flowci/agent:dev" />
17+
</envs>
18+
<method v="2">
19+
<option name="Make" enabled="true" />
20+
</method>
21+
</configuration>
22+
</component>

.run/Application - 2.run.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Application - 2" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
3+
<module name="core" />
4+
<option name="SPRING_BOOT_MAIN_CLASS" value="com.flowci.core.Application" />
5+
<option name="VM_PARAMETERS" value="-Xms1g -Xmx1g -Xmn600m -XX:-UseAdaptiveSizePolicy -XX:SurvivorRatio=4 -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails" />
6+
<option name="ALTERNATIVE_JRE_PATH" />
7+
<envs>
8+
<env name="FLOWCI_LOG_LEVEL" value="DEBUG" />
9+
<env name="FLOWCI_SERVER_URL" value="http://192.168.0.104:8081" />
10+
<env name="FLOWCI_DEFAULT_ADMIN_EMAIL" value="[email protected]" />
11+
<env name="FLOWCI_DEFAULT_ADMIN_PASSWORD" value="12345" />
12+
<env name="FLOWCI_PLUGIN_URL" value="https://raw.githubusercontent.com/FlowCI/plugins/develop/repository.json" />
13+
<env name="FLOWCI_RABBITMQ_URI" value="amqp://guest:[email protected]:5672" />
14+
<env name="FLOWCI_ZK_HOST" value="192.168.0.104" />
15+
<env name="FLOWCI_AUTO_AGENT" value="false" />
16+
<env name="FLOWCI_AGENT_VOLUMES" value="name=pyenv,dest=/ci/python,script=init.sh" />
17+
<env name="FLOWCI_SERVER_PORT" value="8081" />
18+
</envs>
19+
<method v="2">
20+
<option name="Make" enabled="true" />
21+
</method>
22+
</configuration>
23+
</component>

core/src/main/java/com/flowci/core/agent/domain/ShellIn.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import lombok.Setter;
1111
import lombok.experimental.Accessors;
1212

13-
import java.util.LinkedHashSet;
14-
import java.util.LinkedList;
1513
import java.util.List;
1614
import java.util.Set;
1715

@@ -20,6 +18,12 @@
2018
@Accessors(chain = true)
2119
public final class ShellIn extends CmdIn {
2220

21+
public enum ShellType {
22+
Bash,
23+
24+
PowerShell;
25+
}
26+
2327
// from ExecutedCmd id
2428
private String id;
2529

@@ -36,7 +40,9 @@ public final class ShellIn extends CmdIn {
3640
@JsonIgnore
3741
private String condition;
3842

39-
private List<String> scripts;
43+
private List<String> bash;
44+
45+
private List<String> pwsh;
4046

4147
private int timeout = 1800;
4248

@@ -48,11 +54,18 @@ public ShellIn() {
4854
super(Type.SHELL);
4955
}
5056

51-
public void addScript(String script) {
57+
public void addScript(String script, ShellType type) {
5258
if (Strings.isNullOrEmpty(script)) {
5359
return;
5460
}
55-
scripts.add(script);
61+
62+
if (type == ShellType.Bash) {
63+
bash.add(script);
64+
}
65+
66+
if (type == ShellType.PowerShell) {
67+
pwsh.add(script);
68+
}
5669
}
5770

5871
public void addEnvFilters(Set<String> exports) {

core/src/main/java/com/flowci/core/agent/manager/AgentEventManager.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus status)
120120
agentSessionStore.remove(token, session);
121121
}
122122

123+
private <T> void writeMessage(WebSocketSession session, ResponseMessage<T> msg) {
124+
try {
125+
byte[] bytes = objectMapper.writeValueAsBytes(msg);
126+
session.sendMessage(new BinaryMessage(bytes));
127+
} catch (IOException e) {
128+
log.warn(e);
129+
}
130+
}
131+
123132
private void onConnected(WebSocketSession session, String token, byte[] body) {
124133
try {
125134
AgentInit init = objectMapper.readValue(body, AgentInit.class);
@@ -134,7 +143,7 @@ private void onConnected(WebSocketSession session, String token, byte[] body) {
134143
log.debug("Agent {} is connected with status {}", token, init.getStatus());
135144
} catch (Exception e) {
136145
log.warn(e);
137-
writeMessage(token, new ResponseMessage<Void>(StatusCode.FATAL, e.getMessage(), null));
146+
writeMessage(session, new ResponseMessage<Void>(StatusCode.FATAL, e.getMessage(), null));
138147
}
139148
}
140149

core/src/main/java/com/flowci/core/agent/service/AgentServiceImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,13 @@ public void onConnected(OnConnectedEvent event) {
354354

355355
@EventListener
356356
public void onDisconnected(OnDisconnectedEvent event) {
357-
Agent target = getByToken(event.getToken());
357+
try {
358+
Agent target = getByToken(event.getToken());
359+
update(target, OFFLINE);
360+
syncLockNode(target, false);
361+
} catch (NotFoundException ignore) {
358362

359-
update(target, OFFLINE);
360-
syncLockNode(target, false);
363+
}
361364
}
362365

363366
@EventListener

core/src/main/java/com/flowci/core/job/manager/CmdManagerImpl.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public CmdIn createShellCmd(Job job, Step step, NodeTree tree) {
6060
.setCondition(node.getCondition())
6161
.setAllowFailure(node.isAllowFailure())
6262
.setDockers(findDockerOptions(node))
63-
.setScripts(linkScript(node))
63+
.setBash(linkScript(node, ShellIn.ShellType.Bash))
64+
.setPwsh(linkScript(node, ShellIn.ShellType.PowerShell))
6465
.setEnvFilters(linkFilters(node))
6566
.setInputs(linkInputs(node).merge(job.getContext(), false))
6667
.setTimeout(job.getTimeout());
@@ -125,17 +126,24 @@ private Set<String> linkFilters(StepNode current) {
125126
return output;
126127
}
127128

128-
private List<String> linkScript(StepNode current) {
129+
private List<String> linkScript(StepNode current, ShellIn.ShellType shellType) {
129130
List<String> output = new LinkedList<>();
130131

131132
if (current.hasParent()) {
132133
Node parent = current.getParent();
133134
if (parent instanceof StepNode) {
134-
output.addAll(linkScript((StepNode) parent));
135+
output.addAll(linkScript((StepNode) parent, shellType));
135136
}
136137
}
137138

138-
output.add(current.getScript());
139+
if (shellType == ShellIn.ShellType.Bash) {
140+
output.add(current.getBash());
141+
}
142+
143+
if (shellType == ShellIn.ShellType.PowerShell) {
144+
output.add(current.getPwsh());
145+
}
146+
139147
return output;
140148
}
141149

@@ -161,7 +169,8 @@ private void setPlugin(String name, ShellIn cmd) {
161169
cmd.setPlugin(name);
162170
cmd.setAllowFailure(plugin.isAllowFailure());
163171
cmd.addEnvFilters(plugin.getExports());
164-
cmd.addScript(plugin.getScript());
172+
cmd.addScript(plugin.getBash(), ShellIn.ShellType.Bash);
173+
cmd.addScript(plugin.getPwsh(), ShellIn.ShellType.PowerShell);
165174

166175
// apply docker from plugin as run time if it's specified
167176
ObjectsHelper.ifNotNull(plugin.getDocker(), (docker) -> {

core/src/main/java/com/flowci/core/job/service/LocalTaskServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public ExecutedLocalTask execute(Job job, LocalTask task) {
140140
}
141141

142142
Plugin plugin = event.getFetched();
143-
option.addEntryPoint(plugin.getScript());
143+
option.addEntryPoint(plugin.getBash());
144144
option.addBind(event.getDir().toString(), "/ws/.plugins/" + plugin.getName());
145145
ObjectsHelper.ifNotNull(plugin.getDocker(), (docker) -> option.setImage(docker.getImage()));
146146
}

core/src/main/java/com/flowci/core/plugin/domain/Plugin.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public class Plugin extends PluginRepoInfo {
5757

5858
private DockerOption docker;
5959

60-
private String script;
60+
private String bash;
61+
62+
private String pwsh;
6163

6264
private String icon;
6365

@@ -72,7 +74,8 @@ public void update(Plugin src) {
7274
this.setInputs(src.inputs);
7375
this.setStatsTypes(src.statsTypes);
7476
this.setAllowFailure(src.allowFailure);
75-
this.setScript(src.script);
77+
this.setBash(src.bash);
78+
this.setPwsh(src.pwsh);
7679
this.setDocker(src.docker);
7780
}
7881
}

core/src/main/java/com/flowci/core/plugin/domain/PluginParser.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import com.flowci.domain.Version;
2323
import com.flowci.tree.yml.DockerYml;
2424
import com.flowci.util.ObjectsHelper;
25+
import com.flowci.util.StringHelper;
2526
import com.flowci.util.YamlHelper;
2627
import lombok.NoArgsConstructor;
2728
import lombok.NonNull;
2829
import org.yaml.snakeyaml.Yaml;
30+
import sun.jvm.hotspot.oops.ObjectHeap;
2931

3032
import java.io.InputStream;
3133
import java.util.LinkedList;
@@ -62,14 +64,19 @@ private static class PluginWrapper {
6264

6365
public Boolean allow_failure;
6466

67+
public String bash;
68+
69+
public String pwsh;
70+
6571
public String script;
6672

6773
public DockerYml docker;
6874

6975
public Plugin toPlugin() {
7076
Plugin plugin = new Plugin(name, Version.parse(version));
7177
plugin.setIcon(icon);
72-
plugin.setScript(script);
78+
plugin.setBash(bash);
79+
plugin.setPwsh(pwsh);
7380

7481
ObjectsHelper.ifNotNull(docker, val -> plugin.setDocker(val.toDockerOption()));
7582
ObjectsHelper.ifNotNull(exports, plugin::setExports);
@@ -85,6 +92,13 @@ public Plugin toPlugin() {
8592
}
8693
});
8794

95+
// backward compatible, set script to bash
96+
if (StringHelper.hasValue(script)) {
97+
if (!StringHelper.hasValue(bash)) {
98+
plugin.setBash(script);
99+
}
100+
}
101+
88102
return plugin;
89103
}
90104
}

core/src/main/resources/flow.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
app.workspace=${FLOWCI_WORKSPACE:${HOME}/.flow.ci}
1+
app.workspace=${FLOWCI_WORKSPACE:${user.home}/.flow.ci}
22
app.flow-dir=${app.workspace}/flows
33
app.site-dir=${app.workspace}/sites-static-resources
44
app.secret=${FLOWCI_SECRET:qazWSXedcRFV12#$}

0 commit comments

Comments
 (0)