This commit is contained in:
bwcx_jzy 2022-02-07 21:08:19 +08:00
parent 14cbae90ab
commit 2f19df328a
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5

View File

@ -98,6 +98,8 @@ public class DockerBuild implements AutoCloseable {
.withHostResource(tempFile.getAbsolutePath())
.withRemotePath("/tmp/")
.exec();
//
copy = this.replaceEnv(copy, env);
this.copyArchiveToContainerCmd(dockerClient, containerId, copy, logRecorder);
// 启动容器
try {
@ -119,6 +121,20 @@ 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);
}
return s;
}).collect(Collectors.toList());
}
/**
* 构建一个执行 镜像
@ -140,8 +156,11 @@ public class DockerBuild implements AutoCloseable {
//
List<Bind> bindList = new ArrayList<>();
if (CollUtil.isNotEmpty(binds)) {
bindList = binds.stream().map(Bind::parse).collect(Collectors.toList());
bindList = this.replaceEnv(binds, env).stream()
.map(Bind::parse)
.collect(Collectors.toList());
}
HostConfig hostConfig = HostConfig.newHostConfig()
.withMounts(mounts).withBinds(bindList);
containerCmd.withHostConfig(hostConfig);