1818package org .openqa .selenium .docker ;
1919
2020import com .google .common .collect .HashMultimap ;
21+ import com .google .common .collect .ImmutableList ;
2122import com .google .common .collect .ImmutableMap ;
2223import com .google .common .collect .Multimap ;
2324
@@ -39,27 +40,28 @@ public class ContainerConfig {
3940 private final Multimap <String , Map <String , Object >> portBindings ;
4041 private final Map <String , String > envVars ;
4142 private final Map <String , String > volumeBinds ;
43+ private final List <Device > devices ;
4244 private final String networkName ;
4345 private final boolean autoRemove ;
4446 private final long shmSize ;
4547
46-
4748 public ContainerConfig (Image image ,
4849 Multimap <String , Map <String , Object >> portBindings ,
4950 Map <String , String > envVars , Map <String , String > volumeBinds ,
50- String networkName , long shmSize ) {
51+ List < Device > devices , String networkName , long shmSize ) {
5152 this .image = image ;
5253 this .portBindings = portBindings ;
5354 this .envVars = envVars ;
5455 this .volumeBinds = volumeBinds ;
56+ this .devices = devices ;
5557 this .networkName = networkName ;
5658 this .autoRemove = true ;
5759 this .shmSize = shmSize ;
5860 }
5961
6062 public static ContainerConfig image (Image image ) {
6163 return new ContainerConfig (image , HashMultimap .create (), ImmutableMap .of (), ImmutableMap .of (),
62- DEFAULT_DOCKER_NETWORK , DEFAULT_SHM_SIZE );
64+ ImmutableList . of (), DEFAULT_DOCKER_NETWORK , DEFAULT_SHM_SIZE );
6365 }
6466
6567 public ContainerConfig map (Port containerPort , Port hostPort ) {
@@ -76,36 +78,43 @@ public ContainerConfig map(Port containerPort, Port hostPort) {
7678 containerPort .getPort () + "/" + containerPort .getProtocol (),
7779 ImmutableMap .of ("HostPort" , String .valueOf (hostPort .getPort ()), "HostIp" , "" ));
7880
79- return new ContainerConfig (image , updatedBindings , envVars , volumeBinds , networkName ,
80- shmSize );
81+ return new ContainerConfig (image , updatedBindings , envVars , volumeBinds , devices ,
82+ networkName , shmSize );
8183 }
8284
8385 public ContainerConfig env (Map <String , String > envVars ) {
8486 Require .nonNull ("Container env vars" , envVars );
8587
86- return new ContainerConfig (image , portBindings , envVars , volumeBinds , networkName ,
87- shmSize );
88+ return new ContainerConfig (image , portBindings , envVars , volumeBinds , devices ,
89+ networkName , shmSize );
8890 }
8991
9092 public ContainerConfig bind (Map <String , String > volumeBinds ) {
9193 Require .nonNull ("Container volume binds" , volumeBinds );
9294
93- return new ContainerConfig (image , portBindings , envVars , volumeBinds , networkName ,
94- shmSize );
95+ return new ContainerConfig (image , portBindings , envVars , volumeBinds , devices ,
96+ networkName , shmSize );
9597 }
9698
9799 public ContainerConfig network (String networkName ) {
98100 Require .nonNull ("Container network name" , networkName );
99101
100- return new ContainerConfig (image , portBindings , envVars , volumeBinds , networkName ,
102+ return new ContainerConfig (image , portBindings , envVars , volumeBinds , devices , networkName ,
101103 shmSize );
102104 }
103105
104106 public ContainerConfig shmMemorySize (long shmSize ) {
105- return new ContainerConfig (image , portBindings , envVars , volumeBinds , networkName ,
107+ return new ContainerConfig (image , portBindings , envVars , volumeBinds , devices , networkName ,
106108 shmSize );
107109 }
108110
111+ public ContainerConfig devices (List <Device > devices ) {
112+ Require .nonNull ("Container device files" , devices );
113+
114+ return new ContainerConfig (image , portBindings , envVars , volumeBinds , devices , networkName ,
115+ shmSize );
116+ }
117+
109118 @ Override
110119 public String toString () {
111120 return "ContainerConfig{" +
@@ -114,6 +123,7 @@ public String toString() {
114123 ", envVars=" + envVars +
115124 ", volumeBinds=" + volumeBinds +
116125 ", networkName=" + networkName +
126+ ", devices=" + devices +
117127 ", autoRemove=" + autoRemove +
118128 ", shmSize=" + shmSize +
119129 '}' ;
@@ -128,12 +138,21 @@ private Map<String, Object> toJson() {
128138 .map (key -> String .format ("%s:%s" , key , this .volumeBinds .get (key )))
129139 .collect (Collectors .toList ());
130140
141+ List <Map <String , String >> devicesMapping = this .devices .stream ()
142+ .map (device -> ImmutableMap .of (
143+ "PathOnHost" , device .getPathOnHost (),
144+ "PathInContainer" , device .getPathInContainer (),
145+ "CgroupPermissions" , device .getCgroupPermissions ()
146+ ))
147+ .collect (Collectors .toList ());
148+
131149 Map <String , Object > hostConfig = ImmutableMap .of (
132150 "PortBindings" , portBindings .asMap (),
133151 "AutoRemove" , autoRemove ,
134152 "NetworkMode" , networkName ,
135153 "ShmSize" , shmSize ,
136- "Binds" , volumeBinds );
154+ "Binds" , volumeBinds ,
155+ "Devices" , devicesMapping );
137156
138157 return ImmutableMap .of (
139158 "Image" , image .getId (),
0 commit comments