mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/ocr.git
synced 2025-01-13 18:00:33 +00:00
Update for unprivileged usage 2
This commit is contained in:
parent
a4b68bece7
commit
b5ba154f86
@ -42,6 +42,7 @@ mkdir -p /<mydatalocation>/files_for_ocr /<mydatalocation>/files_from_ocr
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-u $(id -u $USER):$(id -g $USER) \
|
||||
-v /<mydatalocation>/files_for_ocr:/input \
|
||||
-v /<mydatalocation>/files_from_ocr:/output \
|
||||
sfb1288inf/ocr:latest \
|
||||
@ -82,6 +83,7 @@ Example with all arguments used:
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-u $(id -u $USER):$(id -g $USER) \
|
||||
-v "$HOME"/ocr/files_for_ocr:/input \
|
||||
-v "$HOME"/ocr/files_from_ocr:/output \
|
||||
sfb1288inf/ocr:latest \
|
||||
|
29
wrapper/ocr
29
wrapper/ocr
@ -2,31 +2,38 @@
|
||||
# coding=utf-8
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
container_image = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:latest'
|
||||
container_input_dir = '/input'
|
||||
container_output_dir = '/output'
|
||||
uid = str(os.getuid())
|
||||
gid = str(os.getgid())
|
||||
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
parser.add_argument(
|
||||
'-i',
|
||||
dest='input_dir',
|
||||
required=False
|
||||
required=True
|
||||
)
|
||||
parser.add_argument(
|
||||
'-o',
|
||||
dest='output_dir',
|
||||
required=False
|
||||
required=True
|
||||
)
|
||||
dirs, args = parser.parse_known_args()
|
||||
args, remaining_args = parser.parse_known_args()
|
||||
|
||||
cmd = ['docker', 'run', '--rm', '-it']
|
||||
if dirs.input_dir is not None:
|
||||
cmd += ['-v', dirs.input_dir + ':/input']
|
||||
args += ['-i', '/input']
|
||||
if dirs.output_dir is not None:
|
||||
cmd += ['-v', dirs.output_dir + ':/output']
|
||||
args += ['-o', '/output']
|
||||
cmd = ['docker', 'run', '--rm', '-it', '-u', uid + ':' + gid]
|
||||
if args.input_dir is not None:
|
||||
host_input_dir = os.path.abspath(args.input_dir)
|
||||
cmd += ['-v', host_input_dir + ':' + container_input_dir]
|
||||
remaining_args += ['-i', '/input']
|
||||
if args.output_dir is not None:
|
||||
host_output_dir = os.path.abspath(args.output_dir)
|
||||
cmd += ['-v', host_output_dir + ':' + container_output_dir]
|
||||
remaining_args += ['-o', '/output']
|
||||
cmd.append(container_image)
|
||||
cmd += args
|
||||
cmd += remaining_args
|
||||
|
||||
subprocess.run(cmd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user