Skip to content

Commit c9c64cd

Browse files
roastariobsideup
andauthored
add support for docker-for-windows new bind serialization format (docker-java#1463)
* add support for docker-for-windows new bind serialization format * add shade version plugin to fix CI * Update pom.xml * Update Bind.java Co-authored-by: Sergei Egorov <bsideup@gmail.com>
1 parent 7f97462 commit c9c64cd

File tree

2 files changed

+109
-1
lines changed
  • docker-java-api/src/main/java/com/github/dockerjava/api/model
  • docker-java/src/test/java/com/github/dockerjava/api/model

2 files changed

+109
-1
lines changed

docker-java-api/src/main/java/com/github/dockerjava/api/model/Bind.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public PropagationMode getPropagationMode() {
9797
*/
9898
public static Bind parse(String serialized) {
9999
try {
100-
String[] parts = serialized.split(":");
100+
// Split by ':' but not ':\' (Windows-style path)
101+
String[] parts = serialized.split(":(?!\\\\)");
101102
switch (parts.length) {
102103
case 2: {
103104
return new Bind(parts[0], new Volume(parts[1]));

docker-java/src/test/java/com/github/dockerjava/api/model/BindTest.java

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,113 @@ public void parseUsingDefaultAccessMode() {
2626
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
2727
}
2828

29+
@Test
30+
public void parseReadWriteWindows() {
31+
Bind bind = Bind.parse("C:\\host:/container:rw");
32+
assertThat(bind.getPath(), is("C:\\host"));
33+
assertThat(bind.getVolume().getPath(), is("/container"));
34+
assertThat(bind.getAccessMode(), is(rw));
35+
assertThat(bind.getSecMode(), is(SELContext.none));
36+
assertThat(bind.getNoCopy(), nullValue());
37+
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
38+
}
39+
40+
@Test
41+
public void parseReadWriteNoCopyWindows() {
42+
Bind bind = Bind.parse("C:\\host:/container:rw,nocopy");
43+
assertThat(bind.getPath(), is("C:\\host"));
44+
assertThat(bind.getVolume().getPath(), is("/container"));
45+
assertThat(bind.getAccessMode(), is(rw));
46+
assertThat(bind.getSecMode(), is(SELContext.none));
47+
assertThat(bind.getNoCopy(), is(true));
48+
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
49+
}
50+
51+
@Test
52+
public void parseReadWriteSharedWindows() {
53+
Bind bind = Bind.parse("C:\\host:/container:rw,shared");
54+
assertThat(bind.getPath(), is("C:\\host"));
55+
assertThat(bind.getVolume().getPath(), is("/container"));
56+
assertThat(bind.getAccessMode(), is(rw));
57+
assertThat(bind.getSecMode(), is(SELContext.none));
58+
assertThat(bind.getNoCopy(), nullValue());
59+
assertThat(bind.getPropagationMode(), is(PropagationMode.SHARED));
60+
}
61+
62+
@Test
63+
public void parseReadWriteSlaveWindows() {
64+
Bind bind = Bind.parse("C:\\host:/container:rw,slave");
65+
assertThat(bind.getPath(), is("C:\\host"));
66+
assertThat(bind.getVolume().getPath(), is("/container"));
67+
assertThat(bind.getAccessMode(), is(rw));
68+
assertThat(bind.getSecMode(), is(SELContext.none));
69+
assertThat(bind.getNoCopy(), nullValue());
70+
assertThat(bind.getPropagationMode(), is(PropagationMode.SLAVE));
71+
}
72+
73+
@Test
74+
public void parseReadWritePrivateWindows() {
75+
Bind bind = Bind.parse("C:\\host:/container:rw,private");
76+
assertThat(bind.getPath(), is("C:\\host"));
77+
assertThat(bind.getVolume().getPath(), is("/container"));
78+
assertThat(bind.getAccessMode(), is(rw));
79+
assertThat(bind.getSecMode(), is(SELContext.none));
80+
assertThat(bind.getNoCopy(), nullValue());
81+
assertThat(bind.getPropagationMode(), is(PropagationMode.PRIVATE));
82+
}
83+
84+
@Test
85+
public void parseReadOnlyWindows() {
86+
Bind bind = Bind.parse("C:\\host:/container:ro");
87+
assertThat(bind.getPath(), is("C:\\host"));
88+
assertThat(bind.getVolume().getPath(), is("/container"));
89+
assertThat(bind.getAccessMode(), is(ro));
90+
assertThat(bind.getSecMode(), is(SELContext.none));
91+
assertThat(bind.getNoCopy(), nullValue());
92+
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
93+
}
94+
95+
@Test
96+
public void parseSELOnlyWindows() {
97+
Bind bind = Bind.parse("C:\\host:/container:Z");
98+
assertThat(bind.getPath(), is("C:\\host"));
99+
assertThat(bind.getVolume().getPath(), is("/container"));
100+
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
101+
assertThat(bind.getSecMode(), is(SELContext.single));
102+
assertThat(bind.getNoCopy(), nullValue());
103+
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
104+
105+
bind = Bind.parse("C:\\host:/container:z");
106+
assertThat(bind.getPath(), is("C:\\host"));
107+
assertThat(bind.getVolume().getPath(), is("/container"));
108+
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
109+
assertThat(bind.getSecMode(), is(SELContext.shared));
110+
assertThat(bind.getNoCopy(), nullValue());
111+
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
112+
}
113+
114+
@Test
115+
public void parseReadWriteSELWindows() {
116+
Bind bind = Bind.parse("C:\\host:/container:rw,Z");
117+
assertThat(bind.getPath(), is("C:\\host"));
118+
assertThat(bind.getVolume().getPath(), is("/container"));
119+
assertThat(bind.getAccessMode(), is(rw));
120+
assertThat(bind.getSecMode(), is(SELContext.single));
121+
assertThat(bind.getNoCopy(), nullValue());
122+
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
123+
}
124+
125+
@Test
126+
public void parseReadOnlySELWindows() {
127+
Bind bind = Bind.parse("C:\\host:/container:ro,z");
128+
assertThat(bind.getPath(), is("C:\\host"));
129+
assertThat(bind.getVolume().getPath(), is("/container"));
130+
assertThat(bind.getAccessMode(), is(ro));
131+
assertThat(bind.getSecMode(), is(SELContext.shared));
132+
assertThat(bind.getNoCopy(), nullValue());
133+
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
134+
}
135+
29136
@Test
30137
public void parseReadWrite() {
31138
Bind bind = Bind.parse("/host:/container:rw");

0 commit comments

Comments
 (0)