12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- import base64
16
- import json
17
15
import logging
18
16
import os
19
17
31
29
ContainerEngine ,
32
30
ContainerRequest ,
33
31
ContainerStatus ,
34
- Credential ,
35
32
LogHandler ,
36
33
)
37
34
@@ -73,7 +70,6 @@ def __init__(
73
70
self .client = get_podman_client ()
74
71
LOGGER .debug (self .client .version ())
75
72
76
- self .auth_file = None
77
73
except APIError as e :
78
74
LOGGER .error (f"Failed to initialize podman engine: f{ e } " )
79
75
raise exceptions .ContainerEngineInitError (str (e ))
@@ -100,6 +96,11 @@ def cleanup(self, container_id: str, log_handler: LogHandler) -> None:
100
96
# ContainerCleanupError handled by the manager
101
97
except APIError as e :
102
98
raise exceptions .ContainerCleanupError (str (e )) from e
99
+ finally :
100
+ # Ensure volumes are purged due to a bug in podman
101
+ # ref: https://github.com/containers/podman-py/issues/328
102
+ pruned_volumes = self .client .volumes .prune ()
103
+ LOGGER .info (f"Pruned volumes: { pruned_volumes } " )
103
104
104
105
def _image_exists (self , image_url : str ) -> bool :
105
106
try :
@@ -113,7 +114,6 @@ def start(self, request: ContainerRequest, log_handler: LogHandler) -> str:
113
114
raise exceptions .ContainerStartError ("Missing image url" )
114
115
115
116
try :
116
- self ._set_auth_json_file ()
117
117
self ._login (request )
118
118
LOGGER .info (f"Image URL is { request .image_url } " )
119
119
if request .pull_policy == "Always" or not self ._image_exists (
@@ -326,44 +326,6 @@ def _login(self, request: ContainerRequest) -> None:
326
326
LOGGER .exception ("Login failed: f{e}" )
327
327
raise exceptions .ContainerStartError (str (e ))
328
328
329
- def _write_auth_json (self , request : ContainerRequest ) -> None :
330
- if not self .auth_file :
331
- LOGGER .debug ("No auth file to create" )
332
- return
333
-
334
- auth_dict = {}
335
- if os .path .exists (self .auth_file ):
336
- with open (self .auth_file , encoding = "utf-8" ) as f :
337
- auth_dict = json .load (f )
338
-
339
- if "auths" not in auth_dict :
340
- auth_dict ["auths" ] = {}
341
- registry = request .image_url .split ("/" )[0 ]
342
- auth_dict ["auths" ][registry ] = self ._create_auth_key (
343
- request .credential
344
- )
345
-
346
- with open (self .auth_file , mode = "w" , encoding = "utf-8" ) as f :
347
- json .dump (auth_dict , f , indent = 6 )
348
-
349
- def _create_auth_key (self , credential : Credential ) -> dict :
350
- data = f"{ credential .username } :{ credential .secret } "
351
- encoded_data = data .encode ("ascii" )
352
- return {"auth" : base64 .b64encode (encoded_data ).decode ("ascii" )}
353
-
354
- def _set_auth_json_file (self ) -> None :
355
- xdg_runtime_dir = os .getenv (
356
- "XDG_RUNTIME_DIR" , f"/run/user/{ os .getuid ()} "
357
- )
358
- auth_file = f"{ xdg_runtime_dir } /containers/auth.json"
359
- dir_name = os .path .dirname (auth_file )
360
- if os .path .exists (dir_name ):
361
- self .auth_file = auth_file
362
- LOGGER .debug ("Will use auth file %s" , auth_file )
363
- else :
364
- self .auth_file = None
365
- LOGGER .debug ("Will not use auth file" )
366
-
367
329
def _pull_image (
368
330
self , request : ContainerRequest , log_handler : LogHandler
369
331
) -> Image :
@@ -376,7 +338,6 @@ def _pull_image(
376
338
"username" : request .credential .username ,
377
339
"password" : request .credential .secret ,
378
340
}
379
- self ._write_auth_json (request )
380
341
image = self .client .images .pull (request .image_url , ** kwargs )
381
342
382
343
# https://github.com/containers/podman-py/issues/301
0 commit comments