Skip to content

Commit

Permalink
Add devices flag support (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisoz authored and pjdarton committed Sep 17, 2018
1 parent 7d45cf0 commit 15b66d7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Volume;
import com.github.dockerjava.api.model.VolumesFrom;
import com.github.dockerjava.api.model.Device;
import com.github.dockerjava.core.NameParser;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
Expand Down Expand Up @@ -87,6 +88,11 @@ public class DockerTemplateBase implements Describable<DockerTemplateBase>, Seri
*/
public String[] volumesFrom2;

/**
* Every String is a device to be mapped
*/
public String[] devices;

@CheckForNull
public String[] environment;

Expand Down Expand Up @@ -287,6 +293,21 @@ public void setVolumesFromString(String volumesFromString) {
setVolumesFrom2(splitAndFilterEmpty(volumesFromString, "\n"));
}

@CheckForNull
public String[] getDevices() {
return filterStringArray(devices);
}

public String getDevicesString() {
if (devices == null) return null;
return Joiner.on("\n").join(devices);
}

@DataBoundSetter
public void setDevicesString(String devicesString) {
this.devices = splitAndFilterEmpty(devicesString, "\n");
}

public String getEnvironmentsString() {
if (environment == null) return null;
return Joiner.on("\n").join(environment);
Expand Down Expand Up @@ -546,6 +567,15 @@ public CreateContainerCmd fillContainerConfig(CreateContainerCmd containerConfig
containerConfig.withVolumesFrom(volFrom.toArray(new VolumesFrom[volFrom.size()]));
}

if (getDevices().length > 0) {
ArrayList<Device> devices = new ArrayList<>();
for (String deviceStr : getDevices()) {
devices.add(Device.parse(deviceStr));
}

containerConfig.withDevices(devices);
}

containerConfig.withTty(tty);

if (environment != null && environment.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<f:expandableTextbox />
</f:entry>

<f:entry title="${%Devices}" field="devicesString">
<f:expandableTextbox />
</f:entry>

<f:entry title="${%Environment}" field="environmentsString">
<f:expandableTextbox />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
New line separated list of devices to be mapped (e.g: /dev/fuse). The full scheme is origin:destination:permissions, although just specifying the origin is enough.

<a href="https://docs.docker.com/engine/reference/commandline/run/#add-host-device-to-container---device">Docker documentation</a>
</div>

0 comments on commit 15b66d7

Please sign in to comment.