Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add devices flag support #685

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>