From 2f19df328abaa5c75b7931ddf2c899fd225de9b5 Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Mon, 7 Feb 2022 21:08:19 +0800 Subject: [PATCH] fix --- .../src/main/java/io/jpom/DockerBuild.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/sub-plugin/docker-cli/src/main/java/io/jpom/DockerBuild.java b/modules/sub-plugin/docker-cli/src/main/java/io/jpom/DockerBuild.java index f9ceffa53..a690a7593 100644 --- a/modules/sub-plugin/docker-cli/src/main/java/io/jpom/DockerBuild.java +++ b/modules/sub-plugin/docker-cli/src/main/java/io/jpom/DockerBuild.java @@ -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 replaceEnv(List list, Map 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 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);