Skip to content

Commit

Permalink
CHE-2874 Let users configure the 'Z' flag when mouting a volume
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza authored and l0rd committed Nov 17, 2016
1 parent a7ef358 commit b7682dd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ che.docker.privilege=false
# Limits the number of processes that can be forked inside a cgroup. Set -1 for unlimited.
# Since 4.3 kernel.
che.docker.pids_limit=-1
# Adds options when mounting the /projects volume.
che.docker.volumes_projects_options=Z

# Adds options when mounting the /mnt/che/terminal, /mnt/che/ws-agent.tar.gz, /mnt/che/conf volume
che.docker.volumes_agent_options=ro,Z

# If the browser clients that are accessing Che are remote AND the configuration of Docker is an
# internal IP address or using Unix sockets, then remote browser clients will not be able to connect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import java.io.File;
Expand All @@ -37,9 +39,13 @@ public class DockerExtConfBindingProvider implements Provider<String> {
public static final String EXT_CHE_LOCAL_CONF_DIR = "/mnt/che/conf";

private static final String PLUGIN_CONF = "plugin-conf";
private static final String CONTAINER_TARGET = ":" + EXT_CHE_LOCAL_CONF_DIR + ":ro,Z";
private static final String CONTAINER_TARGET = ":" + EXT_CHE_LOCAL_CONF_DIR;
private static final Logger LOG = LoggerFactory.getLogger(DockerExtConfBindingProvider.class);

@Inject
@Named("che.docker.volumes_agent_options")
private String volumeOptions;

@Override
public String get() {
String localConfDir = System.getenv(CheBootstrap.CHE_LOCAL_CONF_DIR);
Expand All @@ -54,19 +60,23 @@ public String get() {
}
return null;
}

if (SystemInfo.isWindows()) {
try {
final Path cheHome = WindowsHostUtils.ensureCheHomeExist();
final Path plgConfDir = cheHome.resolve(PLUGIN_CONF);
IoUtil.copy(extConfDir, plgConfDir.toFile(), null, true);
return plgConfDir.toString() + CONTAINER_TARGET;
return getTargetOptions(plgConfDir.toString());
} catch (IOException e) {
LOG.warn(e.getMessage());
throw new RuntimeException(e);
}
} else {
return extConfDir.getAbsolutePath() + CONTAINER_TARGET;
return getTargetOptions(extConfDir.getAbsolutePath());
}
}

private String getTargetOptions(final String path) {
return path + CONTAINER_TARGET + ":" + volumeOptions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,37 @@
@Singleton
public class TerminalVolumeProvider implements Provider<String> {

private static final String CONTAINER_TARGET = ":/mnt/che/terminal:ro,Z";
private static final String CONTAINER_TARGET = ":/mnt/che/terminal";
private static final String TERMINAL = "terminal";
private static final Logger LOG = LoggerFactory.getLogger(TerminalVolumeProvider.class);

@Inject
@Named("che.workspace.terminal_linux_amd64")
private String terminalArchivePath;

@Inject
@Named("che.docker.volumes_agent_options")
private String volumeOptions;

@Override
public String get() {
if (SystemInfo.isWindows()) {
try {
final Path cheHome = WindowsHostUtils.ensureCheHomeExist();
final Path terminalPath = cheHome.resolve(TERMINAL);
IoUtil.copy(Paths.get(terminalArchivePath).toFile(), terminalPath.toFile(), null, true);
return terminalPath.toString() + CONTAINER_TARGET;
return getTargetOptions(terminalPath.toString());
} catch (IOException e) {
LOG.warn(e.getMessage());
throw new RuntimeException(e);
}
} else {
return terminalArchivePath + CONTAINER_TARGET;
return getTargetOptions(terminalArchivePath);
}
}

private String getTargetOptions(final String path) {
return path + CONTAINER_TARGET + ":" + volumeOptions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@Singleton
public class WsAgentVolumeProvider implements Provider<String> {

private static final String CONTAINER_TARGET = ":/mnt/che/ws-agent.tar.gz:ro,Z";
private static final String CONTAINER_TARGET = ":/mnt/che/ws-agent.tar.gz";
private static final String WS_AGENT = "ws-agent.tar.gz";

private static final Logger LOG = LoggerFactory.getLogger(WsAgentVolumeProvider.class);
Expand All @@ -46,19 +46,28 @@ public class WsAgentVolumeProvider implements Provider<String> {
@Named("che.workspace.agent.dev")
private String wsAgentArchivePath;

@Inject
@Named("che.docker.volumes_agent_options")
private String volumeOptions;

@Override
public String get() {

if (SystemInfo.isWindows()) {
try {
final Path cheHome = WindowsHostUtils.ensureCheHomeExist();
final Path path = Files.copy(Paths.get(wsAgentArchivePath), cheHome.resolve(WS_AGENT), REPLACE_EXISTING);
return path.toString() + CONTAINER_TARGET;
return getTargetOptions(path.toString());
} catch (IOException e) {
LOG.warn(e.getMessage());
throw new RuntimeException(e);
}
} else {
return wsAgentArchivePath + CONTAINER_TARGET;
return getTargetOptions(wsAgentArchivePath);
}
}

private String getTargetOptions(final String path) {
return path + CONTAINER_TARGET + ":" + volumeOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ public class LocalCheInfrastructureProvisioner extends DefaultInfrastructureProv
private final WorkspaceFolderPathProvider workspaceFolderPathProvider;
private final WindowsPathEscaper pathEscaper;
private final String projectFolderPath;
private final String volumesOptions;

@Inject
public LocalCheInfrastructureProvisioner(AgentConfigApplier agentConfigApplier,
WorkspaceFolderPathProvider workspaceFolderPathProvider,
WindowsPathEscaper pathEscaper,
@Named("che.workspace.projects.storage") String projectFolderPath) {
@Named("che.workspace.projects.storage") String projectFolderPath,
@Named("che.docker.volumes_agent_options") String volumeOptions) {
super(agentConfigApplier);
this.workspaceFolderPathProvider = workspaceFolderPathProvider;
this.pathEscaper = pathEscaper;
this.projectFolderPath = projectFolderPath;
this.volumesOptions = volumeOptions;
}

@Override
Expand All @@ -66,9 +69,9 @@ public void provision(Environment envConfig, CheServicesEnvironmentImpl internal
// add bind-mount volume for projects in a workspace
String projectFolderVolume;
try {
projectFolderVolume = format("%s:%s:Z",
projectFolderVolume = format("%s:%s:%s",
workspaceFolderPathProvider.getPath(internalEnv.getWorkspaceId()),
projectFolderPath);
projectFolderPath, volumesOptions);
} catch (IOException e) {
throw new EnvironmentException("Error occurred on resolving path to files of workspace " +
internalEnv.getWorkspaceId());
Expand Down

0 comments on commit b7682dd

Please sign in to comment.