From cebf3263947a7c8d45c1f5be0df50ef78a55c273 Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@tetras-libre.fr> Date: Tue, 5 May 2020 21:52:01 +0200 Subject: [PATCH] WIP Almost working version + GIT_VERSION can now be defined in .env + Intermediate file remove is temporarily disabled --- .env.sample | 1 + Dockerfile | 9 ++++----- docker-compose.yml | 5 ++++- src/app/app.py | 14 ++++++++------ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.env.sample b/.env.sample index 5288e19..74416ea 100644 --- a/.env.sample +++ b/.env.sample @@ -1,3 +1,4 @@ RESTART=no APP_DEBUG=false DEV_PORT=5000 +GIT_VERSION=1-project-creation diff --git a/Dockerfile b/Dockerfile index 6af5706..81c1214 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,8 @@ RUN apt-get update RUN apt-get -y upgrade RUN apt-get update - - FROM base As builder -ARG GIT_VERSION=1-project-creation - RUN apt-get install -y \ apache2 \ git \ @@ -22,7 +18,10 @@ RUN git clone https://gitlab.tetras-libre.fr/unl/unl2rdf WORKDIR /opt/unl2rdf +ARG GIT_VERSION=master + RUN git checkout $GIT_VERSION + RUN mvn package FROM base @@ -44,7 +43,7 @@ RUN a2dissite 000-default RUN a2ensite flask -COPY --from=builder /opt/unl2rdf/target/*.jar /opt/ +COPY --from=builder /opt/unl2rdf/target/*.jar /opt/unl2rdf.jar # Force code reloading RUN sed -i 's/^\(\s*MaxConnectionsPerChild\s*\) 0/\1 1/g' /etc/apache2/mods-enabled/mpm_event.conf diff --git a/docker-compose.yml b/docker-compose.yml index 1a7806f..b07ef8b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,10 @@ version: '2' services: front: - build: ./ + build: + context: . + args: + GIT_VERSION: ${GIT_VERSION} volumes: - "./src:/var/www/app" environment: diff --git a/src/app/app.py b/src/app/app.py index 5b2e6b2..9eed382 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -1,3 +1,5 @@ +#! /usr/bin/env python3 + from flask import Flask from flask import request from flask import render_template @@ -30,25 +32,25 @@ def convertUnl(unl, outputs): with tempfile.NamedTemporaryFile() as temp: out_name = temp.name - with tempfile.NamedTemporaryFile() as in_file: + with tempfile.NamedTemporaryFile(mode="w") as in_file: in_file.write(unl) - unl2rdf_path = "/opt/UnlParser-1.0-SNAPSHOT.jar" + unl2rdf_path = "/opt/unl2rdf.jar" cmd = ['java', '-jar', unl2rdf_path, '--input-file', in_file.name, - '--output-filename', out_name, '--output-type', outputs] + '--output-file', out_name, '--output-type', ','.join(outputs)] subprocess.run(cmd) res = {} if 'rdf' in outputs: fname = '{}.rdf'.format(out_name) - with open('{}.rdf'.format(out_name), 'r') as f: + with open(fname, 'r') as f: res['rdf'] = f.read() - os.remove(fname) + #os.remove(fname) if 'dot' in outputs: fname = '{}.dot'.format(out_name) cmd = ['dot', '-Tsvg', fname] with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc: res['dot'] = proc.stdout.read() - os.remove(fname) + #os.remove(fname) return res -- GitLab