Update for unprivileged usage.

This commit is contained in:
Patrick Jentsch 2019-06-02 21:38:47 +02:00
parent bc28f8a8b4
commit 6ddfd51ba9
3 changed files with 22 additions and 18 deletions

View File

@ -37,4 +37,7 @@ RUN pip3 install wheel && pip3 install -U spacy && \
COPY nlp /usr/local/bin COPY nlp /usr/local/bin
COPY spacy_nlp /usr/local/bin COPY spacy_nlp /usr/local/bin
mkdir /input /output
chmod a+rw /input /output
ENTRYPOINT ["nlp"] ENTRYPOINT ["nlp"]

View File

@ -44,12 +44,12 @@ mkdir -p /<mydatalocation>/files_for_nlp /<mydatalocation>/files_from_nlp
docker run \ docker run \
--rm \ --rm \
-it \ -it \
-v /<mydatalocation>/files_for_nlp:/files_for_nlp \ -v /<mydatalocation>/files_for_nlp:/input \
-v /<mydatalocation>/files_from_nlp:/files_from_nlp \ -v /<mydatalocation>/files_from_nlp:/output \
sfb1288inf/nlp:latest \ sfb1288inf/nlp:latest \
-i /files_for_nlp \ -i /input \
-o /files_from_nlp \ -l <languagecode> \
-l <languagecode> -o /output
``` ```
The arguments below `sfb1288inf/nlp:latest` are described in the [NLP arguments](#nlp-arguments) part. The arguments below `sfb1288inf/nlp:latest` are described in the [NLP arguments](#nlp-arguments) part.

View File

@ -10,22 +10,23 @@ parser = argparse.ArgumentParser(add_help=False)
parser.add_argument( parser.add_argument(
'-i', '-i',
dest='input_dir', dest='input_dir',
required=False required=True
) )
parser.add_argument( parser.add_argument(
'-o', '-o',
dest='output_dir', dest='output_dir',
required=False required=True
) )
args, nlp_args = parser.parse_known_args() dirs, args = parser.parse_known_args()
if args.input_dir == None or args.output_dir == None: cmd = ['docker', 'run', '--rm', '-it']
if args.input_dir != None: if dirs.input_dir is not None:
nlp_args.append('-i') cmd += ['-v', dirs.input_dir + ':/input']
nlp_args.append('/files_for_nlp') args += ['-i', '/input']
if args.output_dir != None: if dirs.output_dir is not None:
nlp_args.append('-o') cmd += ['-v', dirs.output_dir + ':/output']
nlp_args.append('/files_from_nlp') args += ['-o', '/output']
subprocess.run(['docker', 'run', '--rm', '-it', container_image] + nlp_args) cmd.append(container_image)
else: cmd += args
subprocess.run(['docker', 'run', '--rm', '-it', '-v', args.input_dir + ':/files_for_nlp', '-v', args.output_dir + ':/files_from_nlp', container_image, '-i', '/files_for_nlp', '-o', '/files_from_nlp'] + nlp_args)
subprocess.run(cmd)