Skip to content

Commit

Permalink
Added support for new app setting: docker-env-file
Browse files Browse the repository at this point in the history
  • Loading branch information
fmichielssen committed Dec 15, 2016
1 parent 4b37173 commit b87dfb1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/eu/openanalytics/services/AppService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/eu/openanalytics/services/DockerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@
*/
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;
import java.util.HashMap;
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -308,6 +312,22 @@ private boolean testContainer(Proxy proxy, int maxTries, int waitMs, int timeout
return false;
}

private List<String> buildEnv(String userName, ShinyApp app) throws IOException {
List<String> 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;
Expand Down

0 comments on commit b87dfb1

Please sign in to comment.