Skip to content

Commit

Permalink
CHE-1039: add ability to bind additional folder to docker dev machine (
Browse files Browse the repository at this point in the history
…#1105)

Signed-off-by: Alexander Garagatyi <agaragatyi@codenvy.com>
  • Loading branch information
Alexander Garagatyi committed Apr 21, 2016
1 parent 17a5b55 commit fd8c5f8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ public DockerInstanceProvider(DockerConnector docker,
this.supportedRecipeTypes = Collections.singleton("dockerfile");
this.projectFolderPath = projectFolderPath;

allMachinesSystemVolumes = removeEmptyAndNullValues(allMachinesSystemVolumes);
devMachineSystemVolumes = removeEmptyAndNullValues(devMachineSystemVolumes);
if (SystemInfo.isWindows()) {
allMachinesSystemVolumes = escapePaths(allMachinesSystemVolumes);
devMachineSystemVolumes = escapePaths(devMachineSystemVolumes);
}
this.commonMachineSystemVolumes = allMachinesSystemVolumes.toArray(new String[allMachinesEnvVariables.size()]);
this.commonMachineSystemVolumes = allMachinesSystemVolumes.toArray(new String[allMachinesSystemVolumes.size()]);
final Set<String> devMachineVolumes = Sets.newHashSetWithExpectedSize(allMachinesSystemVolumes.size()
+ devMachineSystemVolumes.size());
devMachineVolumes.addAll(allMachinesSystemVolumes);
Expand All @@ -142,8 +144,8 @@ public DockerInstanceProvider(DockerConnector docker,
devMachinePortsToExpose.put(serverConf.getPort(), Collections.emptyMap());
}

allMachinesEnvVariables = filterEmptyAndNullValues(allMachinesEnvVariables);
devMachineEnvVariables = filterEmptyAndNullValues(devMachineEnvVariables);
allMachinesEnvVariables = removeEmptyAndNullValues(allMachinesEnvVariables);
devMachineEnvVariables = removeEmptyAndNullValues(devMachineEnvVariables);
this.commonMachineEnvVariables = allMachinesEnvVariables;
final HashSet<String> envVariablesForDevMachine = Sets.newHashSetWithExpectedSize(allMachinesEnvVariables.size() +
devMachineEnvVariables.size());
Expand Down Expand Up @@ -467,7 +469,7 @@ String generateContainerName(String workspaceId, String displayName) {
/**
* Returns set that contains all non empty and non nullable values from specified set
*/
protected Set<String> filterEmptyAndNullValues(Set<String> paths) {
protected Set<String> removeEmptyAndNullValues(Set<String> paths) {
return paths.stream()
.filter(path -> !Strings.isNullOrEmpty(path))
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ protected void configure() {

Multibinder<String> devMachineVolumes = Multibinder.newSetBinder(binder(),
String.class,
Names.named("machine.docker.dev_machine.machine_volumes"));
Names.named("machine.docker.dev_machine.machine_volumes"))
.permitDuplicates();

Multibinder<String> machineVolumes = Multibinder.newSetBinder(binder(),
String.class,
Names.named("machine.docker.machine_volumes"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.che.plugin.docker.machine.DockerInstanceProvider;
import org.eclipse.che.plugin.docker.machine.DockerInstanceRuntimeInfo;
import org.eclipse.che.plugin.docker.machine.local.provider.CheHostVfsRootDirProvider;
import org.eclipse.che.plugin.docker.machine.local.provider.ExtraVolumeProvider;
import org.eclipse.che.plugin.docker.machine.node.DockerNode;
import org.eclipse.che.plugin.docker.machine.DockerProcess;

Expand Down Expand Up @@ -72,5 +73,10 @@ protected void configure() {
new org.eclipse.che.plugin.docker.machine.local.interceptor.EnableOfflineDockerMachineBuildInterceptor();
requestInjection(offlineMachineBuildInterceptor);
bindInterceptor(Matchers.subclassesOf(DockerInstanceProvider.class), names("buildImage"), offlineMachineBuildInterceptor);

Multibinder<String> devMachineVolumes = Multibinder.newSetBinder(binder(),
String.class,
Names.named("machine.docker.dev_machine.machine_volumes"));
devMachineVolumes.addBinding().toProvider(org.eclipse.che.plugin.docker.machine.local.provider.ExtraVolumeProvider.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.docker.machine.local.provider;

import com.google.inject.Inject;

import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

/**
* Provides volume configuration of machine for any local directories
* that a user may want to mount into a dev machine.
* <br/>machine.server.extra.volume property is optional and provided as
* /path/on/host:/path/in/container
*
* @author Alexander Garagatyi
*/
@Singleton
public class ExtraVolumeProvider implements Provider<String> {
@Inject(optional = true)
@Named("machine.server.extra.volume")
private String volume;

@Override
public String get() {
return volume == null ? "" : volume;
}
}

0 comments on commit fd8c5f8

Please sign in to comment.