mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 11:58:01 +08:00
fix 容器构建 cache 插件支持使用环境变量替换值
This commit is contained in:
parent
f26e49f6fe
commit
9e6edb150e
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,5 +1,15 @@
|
||||
# 🚀 版本日志
|
||||
|
||||
## 2.9.9
|
||||
|
||||
### 🐣 新增功能
|
||||
|
||||
### 🐞 解决BUG、优化功能
|
||||
|
||||
1. 【server】容器构建 cache 插件支持使用环境变量替换值
|
||||
|
||||
------
|
||||
|
||||
## 2.9.8 (2022-08-10)
|
||||
|
||||
### 🐣 新增功能
|
||||
|
@ -26,6 +26,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@ -56,10 +57,12 @@ public class DockerBuild implements AutoCloseable {
|
||||
|
||||
private final Map<String, Object> parameter;
|
||||
private final DockerClient dockerClient;
|
||||
private final Map<String, String> env;
|
||||
|
||||
public DockerBuild(Map<String, Object> parameter) {
|
||||
this.parameter = parameter;
|
||||
this.dockerClient = DockerUtil.get(parameter);
|
||||
this.env = (Map<String, String>) parameter.get("env");
|
||||
}
|
||||
|
||||
public void build() {
|
||||
@ -73,7 +76,7 @@ public class DockerBuild implements AutoCloseable {
|
||||
String resultFile = (String) parameter.get("resultFile");
|
||||
String resultFileOut = (String) parameter.get("resultFileOut");
|
||||
List<Map<String, Object>> steps = (List<Map<String, Object>>) parameter.get("steps");
|
||||
Map<String, String> env = (Map<String, String>) parameter.get("env");
|
||||
|
||||
String buildId = env.get("JPOM_BUILD_ID");
|
||||
String runsOn = (String) parameter.get("runsOn");
|
||||
|
||||
@ -98,7 +101,7 @@ public class DockerBuild implements AutoCloseable {
|
||||
.withRemotePath("/tmp/")
|
||||
.exec();
|
||||
//
|
||||
copy = this.replaceEnv(copy, env);
|
||||
copy = this.replaceEnv(copy);
|
||||
this.copyArchiveToContainerCmd(dockerClient, containerId, copy, logRecorder);
|
||||
// 启动容器
|
||||
try {
|
||||
@ -120,18 +123,27 @@ public class DockerBuild implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> replaceEnv(List<String> list, Map<String, String> env) {
|
||||
return list.stream().map(s -> {
|
||||
// 处理变量
|
||||
for (Map.Entry<?, ?> envEntry : env.entrySet()) {
|
||||
String envValue = StrUtil.utf8Str(envEntry.getValue());
|
||||
if (null == envValue) {
|
||||
continue;
|
||||
}
|
||||
s = StrUtil.replace(s, "${" + envEntry.getKey() + "}", envValue);
|
||||
private List<String> replaceEnv(List<String> list) {
|
||||
if (env == null) {
|
||||
return list;
|
||||
}
|
||||
// 处理变量
|
||||
return list.stream().map(this::replaceEnv).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String replaceEnv(String value) {
|
||||
if (env == null) {
|
||||
return value;
|
||||
}
|
||||
// 处理变量
|
||||
for (Map.Entry<?, ?> envEntry : env.entrySet()) {
|
||||
String envValue = StrUtil.utf8Str(envEntry.getValue());
|
||||
if (null == envValue) {
|
||||
continue;
|
||||
}
|
||||
return s;
|
||||
}).collect(Collectors.toList());
|
||||
value = StrUtil.replace(value, "${" + envEntry.getKey() + "}", envValue);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@ -155,7 +167,7 @@ public class DockerBuild implements AutoCloseable {
|
||||
//
|
||||
List<Bind> bindList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(binds)) {
|
||||
bindList = this.replaceEnv(binds, env).stream()
|
||||
bindList = this.replaceEnv(binds).stream()
|
||||
.map(Bind::parse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@ -354,6 +366,7 @@ public class DockerBuild implements AutoCloseable {
|
||||
})
|
||||
.map(stringObjectMap -> {
|
||||
String path = (String) stringObjectMap.get("path");
|
||||
path = this.replaceEnv(path);
|
||||
String name = String.format("jpom_cache_%s_%s", buildId, SecureUtil.md5(path));
|
||||
try {
|
||||
dockerClient.inspectVolumeCmd(name).exec();
|
||||
|
@ -16,7 +16,19 @@
|
||||
<a-tooltip slot="CreatedAt" slot-scope="text" placement="topLeft" :title="text['CreatedAt']">
|
||||
<span>{{ parseTime(text["CreatedAt"]) }}</span>
|
||||
</a-tooltip>
|
||||
<!-- <a-tooltip slot="size" slot-scope="text, record" placement="topLeft" :title="renderSize(text) + ' ' + renderSize(record.virtualSize)">
|
||||
<template slot="name" slot-scope="text, record">
|
||||
<a-popover title="卷标签" v-if="record.labels">
|
||||
<template slot="content">
|
||||
<p v-for="(value, key) in record.labels" :key="key">{{ key }}<a-icon type="arrow-right" />{{ value }}</p>
|
||||
</template>
|
||||
<a-icon type="pushpin" />
|
||||
</a-popover>
|
||||
|
||||
<a-tooltip :title="text">
|
||||
{{ text }}
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<!-- <a-tooltip slot="name" slot-scope="text, record" placement="topLeft" :title="renderSize(text) + ' ' + renderSize(record.virtualSize)">
|
||||
<span>{{ renderSize(text) }}</span>
|
||||
</a-tooltip> -->
|
||||
|
||||
@ -29,15 +41,6 @@
|
||||
</a-tooltip>
|
||||
<template slot="operation" slot-scope="text, record">
|
||||
<a-space>
|
||||
<!-- <a-tooltip title="停止" v-if="record.state === 'running'">
|
||||
<a-button size="small" type="link" @click="doAction(record, 'stop')"><a-icon type="stop" /></a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip title="启动" v-else>
|
||||
<a-button size="small" type="link" @click="doAction(record, 'start')"> <a-icon type="play-circle" /></a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip title="重启">
|
||||
<a-button size="small" type="link" :disabled="record.state !== 'running'" @click="doAction(record, 'restart')"><a-icon type="reload" /></a-button>
|
||||
</a-tooltip> -->
|
||||
<a-tooltip title="删除">
|
||||
<a-button size="small" type="link" @click="doAction(record, 'remove')"><a-icon type="delete" /></a-button>
|
||||
</a-tooltip>
|
||||
@ -64,7 +67,7 @@ export default {
|
||||
renderSize,
|
||||
columns: [
|
||||
{ title: "序号", width: 80, ellipsis: true, align: "center", customRender: (text, record, index) => `${index + 1}` },
|
||||
{ title: "名称", dataIndex: "name", ellipsis: true, scopedSlots: { customRender: "tooltip" } },
|
||||
{ title: "名称", dataIndex: "name", ellipsis: true, scopedSlots: { customRender: "name" } },
|
||||
{ title: "挂载点", dataIndex: "mountpoint", ellipsis: true, scopedSlots: { customRender: "tooltip" } },
|
||||
{ title: "类型", dataIndex: "driver", ellipsis: true, width: 80, scopedSlots: { customRender: "tooltip" } },
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user