File tree Expand file tree Collapse file tree 3 files changed +17
-13
lines changed Expand file tree Collapse file tree 3 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -303,6 +303,16 @@ def make_r2d(argv=None):
303303 r2d .user_id = args .user_id
304304 if args .user_name :
305305 r2d .user_name = args .user_name
306+ if r2d .user_id == 0 and not r2d .dry_run :
307+ print ("Root as the primary user in the image is not permitted." )
308+ print (
309+ "The uid and the username of the user invoking repo2docker "
310+ "is used to create a mirror account in the image by default. "
311+ "To override that behavior pass --user-id <numeric_id> and "
312+ " --user-name <string> to repo2docker.\n "
313+ "Please see repo2docker --help for more details.\n "
314+ )
315+ sys .exit (1 )
306316
307317 if args .build_memory_limit :
308318 # if the string only contains numerals we assume it should be an int
Original file line number Diff line number Diff line change 77
88 python -m repo2docker https://github.com/you/your-repo
99"""
10- import errno
1110import json
1211import sys
1312import logging
@@ -670,17 +669,9 @@ def build(self):
670669
671670 if not self .dry_run :
672671 if self .user_id == 0 :
673- self . log . error (
674- "Root as the primary user in the image is not permitted.\n "
672+ raise ValueError (
673+ "Root as the primary user in the image is not permitted."
675674 )
676- self .log .info (
677- "The uid and the username of the user invoking repo2docker "
678- "is used to create a mirror account in the image by default. "
679- "To override that behavior pass --user-id <numeric_id> and "
680- " --user-name <string> to repo2docker.\n "
681- "Please see repo2docker --help for more details.\n "
682- )
683- sys .exit (errno .EPERM )
684675
685676 build_args = {
686677 "NB_USER" : self .user_name ,
Original file line number Diff line number Diff line change @@ -110,10 +110,13 @@ def test_root_not_allowed():
110110 with TemporaryDirectory () as src , patch ("os.geteuid" ) as geteuid :
111111 geteuid .return_value = 0
112112 argv = [src ]
113- app = make_r2d (argv )
114113 with pytest .raises (SystemExit ) as exc :
114+ app = make_r2d (argv )
115+ assert exc .code == 1
116+
117+ with pytest .raises (ValueError ):
118+ app = Repo2Docker (repo = src , run = False )
115119 app .build ()
116- assert exc .code == errno .EPERM
117120
118121 app = Repo2Docker (repo = src , user_id = 1000 , user_name = "jovyan" , run = False )
119122 app .initialize ()
You can’t perform that action at this time.
0 commit comments