Commit 1643442
authored
feat: add user configuration for container commands (#784)
This was inspired by
#762 and my
project's requirement to use an image that requires running with root
user inside the container.
This pull request introduces the ability to configure a user that
commands are run as inside a container in the `testcontainers` library.
The most important changes include adding a new `user` field to the
`ContainerRequest` struct, implementing methods to set and retrieve the
user, and updating relevant tests to ensure this functionality works
correctly.
Enhancements to `ContainerRequest`:
*
[`testcontainers/src/core/containers/request.rs`](diffhunk://#diff-450493263e745439645d3062a1defe3bdedcadacabb123fe7664244e42570049R46):
Added a new `user` field to the `ContainerRequest` struct and provided a
method to retrieve the user.
[[1]](diffhunk://#diff-450493263e745439645d3062a1defe3bdedcadacabb123fe7664244e42570049R46)
[[2]](diffhunk://#diff-450493263e745439645d3062a1defe3bdedcadacabb123fe7664244e42570049R196-R200)
[[3]](diffhunk://#diff-450493263e745439645d3062a1defe3bdedcadacabb123fe7664244e42570049R230)
[[4]](diffhunk://#diff-450493263e745439645d3062a1defe3bdedcadacabb123fe7664244e42570049L268-R276)
Enhancements to `ImageExt`:
*
[`testcontainers/src/core/image/image_ext.rs`](diffhunk://#diff-5d7331a740328676b08bc371893a5aa3e743d351bccafc3da0e2c55ffbf2004fR169-R171):
Added a new method `with_user` to the `ImageExt` trait to set the user
for the container.
[[1]](diffhunk://#diff-5d7331a740328676b08bc371893a5aa3e743d351bccafc3da0e2c55ffbf2004fR169-R171)
[[2]](diffhunk://#diff-5d7331a740328676b08bc371893a5aa3e743d351bccafc3da0e2c55ffbf2004fR386-R393)
Updates to `async_runner`:
*
[`testcontainers/src/runners/async_runner.rs`](diffhunk://#diff-24518a824e97296d94c621275ed17e1f3fa9ae37e0b66158ee4dcf549c21b868R152):
Updated the `async_runner` to include the user configuration and added a
new test to verify that the user is correctly set inside the container.
[[1]](diffhunk://#diff-24518a824e97296d94c621275ed17e1f3fa9ae37e0b66158ee4dcf549c21b868R152)
[[2]](diffhunk://#diff-24518a824e97296d94c621275ed17e1f3fa9ae37e0b66158ee4dcf549c21b868R877-R894)1 parent 8168a82 commit 1643442
File tree
3 files changed
+39
-1
lines changed- testcontainers/src
- core
- containers
- image
- runners
3 files changed
+39
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
195 | 201 | | |
196 | 202 | | |
197 | 203 | | |
| |||
221 | 227 | | |
222 | 228 | | |
223 | 229 | | |
| 230 | + | |
224 | 231 | | |
225 | 232 | | |
226 | 233 | | |
| |||
265 | 272 | | |
266 | 273 | | |
267 | 274 | | |
268 | | - | |
| 275 | + | |
| 276 | + | |
269 | 277 | | |
270 | 278 | | |
271 | 279 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
169 | 172 | | |
170 | 173 | | |
171 | 174 | | |
| |||
380 | 383 | | |
381 | 384 | | |
382 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
383 | 394 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| |||
873 | 874 | | |
874 | 875 | | |
875 | 876 | | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
876 | 895 | | |
0 commit comments