d-utils

simple utils to use docker images without docker
git clone https://git.ce9e.org/d-utils.git

commit
759ff4e80674aed3d2e0908334c3aad147cdb4e3
parent
e4c3c6660b32c5e135657b707e4bb3ad5aa9268d
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-08-05 07:28
d-run: replace custom fakeroot by standard User

use `-u 0:0` instead of -r

Diffstat

M README.md 2 +-
M d-run 33 +++++++++++++++++++++++++--------

2 files changed, 26 insertions, 9 deletions


diff --git a/README.md b/README.md

@@ -12,6 +12,7 @@ This is the full list of values from docker's
   12    12 [`config.json`](https://github.com/opencontainers/image-spec/blob/main/config.md)
   13    13 that are actually used by `d-run`:
   14    14 
   -1    15 -	`User`
   15    16 -	`Hostname`
   16    17 -	`WorkingDir`
   17    18 -	`Env`
@@ -22,7 +23,6 @@ that are actually used by `d-run`:
   22    23 `d-run` uses the following additional values:
   23    24 
   24    25 -	`net` (bool) - enable networking (default: false)
   25    -1 -	`fakeroot` (bool) - map UID and GID to 0 (default: false)
   26    26 -	`rw` (bool) - allow to modify the base image (default: false)
   27    27 
   28    28 You are encouraged to modify this file, e.g. to add a volume or change the

diff --git a/d-run b/d-run

@@ -3,6 +3,8 @@
    3     3 import os
    4     4 import json
    5     5 import argparse
   -1     6 import grp
   -1     7 import pwd
    6     8 
    7     9 
    8    10 def make_volume(path, dir):
@@ -25,6 +27,21 @@ def make_volume(path, dir):
   25    27 	return [op, hostpath, path]
   26    28 
   27    29 
   -1    30 def parse_user(user):
   -1    31 	uid = user
   -1    32 	gid = None
   -1    33 
   -1    34 	if ':' in user:
   -1    35 		uid, gid = uid.split(':', 1)
   -1    36 		if not gid.isdigit():
   -1    37 			gid = grp.getgrnam(gid).gr_gid
   -1    38 
   -1    39 	if not uid.isdigit():
   -1    40 		uid = pwd.getpwnam(uid).pw_uid
   -1    41 
   -1    42 	return uid, gid
   -1    43 
   -1    44 
   28    45 def build_cmd(dir, config):
   29    46 	cmd = [
   30    47 		'bwrap',
@@ -59,11 +76,11 @@ def build_cmd(dir, config):
   59    76 	if not config.get('rw'):
   60    77 		cmd += ['--remount-ro', '/']
   61    78 
   62    -1 	if config.get('fakeroot'):
   63    -1 		cmd += [
   64    -1 			'--uid', '0',
   65    -1 			'--gid', '0',
   66    -1 		]
   -1    79 	if config.get('User'):
   -1    80 		uid, gid = parse_user(config['User'])
   -1    81 		cmd += ['--uid', str(uid)]
   -1    82 		if gid is not None:
   -1    83 			cmd += ['--gid', str(gid)]
   67    84 
   68    85 	if config.get('Entrypoint'):
   69    86 		cmd += config['Entrypoint']
@@ -77,8 +94,8 @@ def parse_args():
   77    94 	parser = argparse.ArgumentParser()
   78    95 	parser.add_argument('dir')
   79    96 	parser.add_argument('-v', '--volume', action='append')
   -1    97 	parser.add_argument('-u', '--user')
   80    98 	parser.add_argument('-n', '--net', action='store_true')
   81    -1 	parser.add_argument('-r', '--fakeroot', action='store_true')
   82    99 	parser.add_argument('-w', '--rw', action='store_true')
   83   100 	parser.add_argument('cmd', nargs='*')
   84   101 	return parser.parse_args()
@@ -96,8 +113,8 @@ if __name__ == '__main__':
   96   113 		config['net'] = True
   97   114 	if args.rw:
   98   115 		config['rw'] = True
   99    -1 	if args.fakeroot:
  100    -1 		config['fakeroot'] = True
   -1   116 	if args.user:
   -1   117 		config['User'] = args.user
  101   118 	if args.volume:
  102   119 		if not config.get('Volumes'):
  103   120 			config['Volumes'] = {}