Skip to content

Commit

Permalink
added env filter
Browse files Browse the repository at this point in the history
  • Loading branch information
interair committed Oct 5, 2017
1 parent 4475a89 commit 9bb6bc5
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import com.codeabovelab.dm.cluman.cluster.docker.management.DockerServiceImpl;
import com.codeabovelab.dm.cluman.cluster.docker.management.DockerUtils;
import com.codeabovelab.dm.cluman.cluster.docker.management.argument.CalcNameArg;
import com.codeabovelab.dm.cluman.cluster.docker.management.result.CreateAndStartContainerResult;
import com.codeabovelab.dm.cluman.cluster.docker.management.result.ProcessEvent;
import com.codeabovelab.dm.cluman.cluster.docker.management.result.*;
import com.codeabovelab.dm.cluman.cluster.docker.management.result.ResultCode;
import com.codeabovelab.dm.cluman.cluster.docker.management.result.ServiceCallResult;
import com.codeabovelab.dm.cluman.cluster.docker.model.*;
import com.codeabovelab.dm.cluman.configs.container.ConfigProvider;
import com.codeabovelab.dm.cluman.ds.SwarmUtils;
Expand All @@ -49,6 +47,7 @@

import static com.codeabovelab.dm.cluman.cluster.docker.management.DockerUtils.SCALABLE;
import static com.codeabovelab.dm.cluman.cluster.docker.model.RestartPolicy.parse;
import static com.codeabovelab.dm.common.utils.StringUtils.before;
import static com.google.common.base.MoreObjects.firstNonNull;

/**
Expand Down Expand Up @@ -222,7 +221,7 @@ protected CreateContainerCmd buildCreateContainer(CreateContainerContext cc) {
cmd.setName(name);
cmd.setHostName(MoreObjects.firstNonNull(nc.getHostname(), name));
cmd.setDomainName(nc.getDomainname());
cmd.setEnv(env.toArray(new String[env.size()]));
cmd.setEnv(filterEnv(result.getEnvironment()));
cmd.setImage(imageName);
cmd.setLabels(result.getLabels());
cmd.getLabels().put(ContainerUtils.LABEL_IMAGE_NAME, imageName);
Expand All @@ -239,6 +238,11 @@ protected CreateContainerCmd buildCreateContainer(CreateContainerContext cc) {
return cmd;
}

private String[] filterEnv(Collection<String> env) {
Set<String> filter = new HashSet<>();
return env.stream().filter(e -> filter.add(before(e, '='))).toArray(String[]::new);
}

private ImageDescriptor getImage(CreateContainerContext cc) {
DockerService dockerService = cc.dockerService;
ContainerSource nc = cc.arg.getContainer();
Expand Down

0 comments on commit 9bb6bc5

Please sign in to comment.