File tree 5 files changed +28
-0
lines changed
5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,10 @@ The ``[docker:container-name]`` section may contain the following directives:
121
121
test run until the container reports healthy, and will fail the test
122
122
run if it never does so (within the parameters specified).
123
123
124
+ ``user ``
125
+ The `user<https://docs.docker.com/engine/reference/run/#user> `__ Username
126
+ or UID to run commands as inside the container.
127
+
124
128
Command-Line Arguments
125
129
----------------------
126
130
@@ -182,6 +186,8 @@ Example
182
186
# testing use cases, as this could persist data between test runs
183
187
volumes =
184
188
bind:rw:/my/own/datadir:/var/lib/postgresql/data
189
+ # Run the container under the specified user
190
+ user = 1234
185
191
186
192
[docker:appserv]
187
193
# You can use any value that `docker run` would accept as the image
Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ def __init__(
118
118
ports : Optional [Collection [Port ]] = None ,
119
119
links : Optional [Collection [Link ]] = None ,
120
120
volumes : Optional [Collection [Volume ]] = None ,
121
+ user : Optional [str ] = None ,
121
122
) -> None :
122
123
self .name = name
123
124
self .runas_name = runas_name (name )
@@ -139,3 +140,4 @@ def __init__(
139
140
int (healthcheck_start_period ) if healthcheck_start_period else None
140
141
)
141
142
self .healthcheck_retries = healthcheck_retries
143
+ self .user = user
Original file line number Diff line number Diff line change @@ -97,6 +97,13 @@ def docker_run(
97
97
if not os .path .exists (source ):
98
98
raise ValueError (f"Volume source { source !r} does not exist" )
99
99
100
+ user = None
101
+ if container_config .user :
102
+ try :
103
+ user = int (container_config .user )
104
+ except ValueError :
105
+ user = container_config .user
106
+
100
107
log (f"run { container_config .image !r} (from { container_config .name !r} )" )
101
108
container = docker .containers .run (
102
109
str (container_config .image ),
@@ -108,6 +115,7 @@ def docker_run(
108
115
ports = ports ,
109
116
publish_all_ports = len (ports ) == 0 ,
110
117
mounts = container_config .mounts ,
118
+ user = user ,
111
119
)
112
120
container .reload () # TODO: why do we need this?
113
121
return container
Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ def parse_container_config(
133
133
if reader .getstring ("volumes" ):
134
134
volumes = [Volume (line ) for line in reader .getlist ("volumes" )]
135
135
136
+ user = None
137
+ if reader .getstring ("user" ):
138
+ user = getstring (reader , "user" )
139
+
136
140
return ContainerConfig (
137
141
name = container_name ,
138
142
image = Image (reader .getstring ("image" )),
@@ -146,4 +150,5 @@ def parse_container_config(
146
150
ports = ports ,
147
151
links = links ,
148
152
volumes = volumes ,
153
+ user = user
149
154
)
Original file line number Diff line number Diff line change @@ -86,6 +86,12 @@ def register_config(self) -> None:
86
86
default = 0 ,
87
87
desc = "docker healthcheck retry count" ,
88
88
)
89
+ self .add_config (
90
+ keys = ["user" ],
91
+ of_type = str ,
92
+ default = "" ,
93
+ desc = "Username or UID to run commands as inside the container" ,
94
+ )
89
95
90
96
91
97
def parse_container_config (docker_config : DockerConfigSet ) -> ContainerConfig :
@@ -102,4 +108,5 @@ def parse_container_config(docker_config: DockerConfigSet) -> ContainerConfig:
102
108
ports = docker_config ["ports" ],
103
109
links = docker_config ["links" ],
104
110
volumes = docker_config ["volumes" ],
111
+ user = docker_config ["user" ]
105
112
)
You can’t perform that action at this time.
0 commit comments