diff --git a/src/main/java/eu/openanalytics/services/AppService.java b/src/main/java/eu/openanalytics/services/AppService.java index 893b2d4d..774ae3e1 100644 --- a/src/main/java/eu/openanalytics/services/AppService.java +++ b/src/main/java/eu/openanalytics/services/AppService.java @@ -54,6 +54,7 @@ public static class ShinyApp { private String dockerImage; private String[] dockerDns; private String dockerMemory; + private String dockerEnvFile; private String[] groups; public String getName() { @@ -112,6 +113,13 @@ public void setDockerMemory(String dockerMemory) { this.dockerMemory = dockerMemory; } + public String getDockerEnvFile() { + return dockerEnvFile; + } + public void setDockerEnvFile(String dockerEnvFile) { + this.dockerEnvFile = dockerEnvFile; + } + public String[] getGroups() { return groups; } diff --git a/src/main/java/eu/openanalytics/services/DockerService.java b/src/main/java/eu/openanalytics/services/DockerService.java index 8c6000c0..f9ac360a 100644 --- a/src/main/java/eu/openanalytics/services/DockerService.java +++ b/src/main/java/eu/openanalytics/services/DockerService.java @@ -15,10 +15,13 @@ */ package eu.openanalytics.services; +import java.io.FileInputStream; +import java.io.IOException; import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; @@ -26,6 +29,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -246,7 +250,7 @@ private Proxy startProxy(String userName, String appName) { .image(app.getDockerImage()) .exposedPorts("3838") .cmd(app.getDockerCmd()) - .env(String.format("SHINYPROXY_USERNAME=%s", userName)) + .env(buildEnv(userName, app)) .build(); ContainerCreation container = dockerClient.createContainer(containerConfig); @@ -308,6 +312,22 @@ private boolean testContainer(Proxy proxy, int maxTries, int waitMs, int timeout return false; } + private List buildEnv(String userName, ShinyApp app) throws IOException { + List env = new ArrayList<>(); + env.add(String.format("SHINYPROXY_USERNAME=%s", userName)); + + String envFile = app.getDockerEnvFile(); + if (envFile != null && Files.isRegularFile(Paths.get(envFile))) { + Properties envProps = new Properties(); + envProps.load(new FileInputStream(envFile)); + for (Object key: envProps.keySet()) { + env.add(String.format("%s=%s", key, envProps.get(key))); + } + } + + return env; + } + private int getFreePort() { int startPort = Integer.valueOf(environment.getProperty("shiny.proxy.docker.port-range-start")); int nextPort = startPort;