From b666783b350b8c0258db1e0b3fbe67551fbc13b1 Mon Sep 17 00:00:00 2001 From: "vladimir.ferko" Date: Wed, 10 Apr 2024 11:24:16 +0200 Subject: [PATCH] docker fix --- annotation_app/Dockerfile | 6 ++++-- annotation_app/app.py | 29 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/annotation_app/Dockerfile b/annotation_app/Dockerfile index 9bb4826..233cdd6 100644 --- a/annotation_app/Dockerfile +++ b/annotation_app/Dockerfile @@ -6,8 +6,10 @@ COPY . /app/ RUN pip install --no-cache-dir -r requirements.txt -RUN python initial.py +ENV DB_URI="sqlite:///anot_db.db" +ENV SECRET_KEY="random_secret_key" EXPOSE 5050 -CMD ["python3", "app.py"] +# CMD ["python3", "app.py"] +ENTRYPOINT ["tail", "-f", "/dev/null"] diff --git a/annotation_app/app.py b/annotation_app/app.py index d9135bd..7dbaf03 100644 --- a/annotation_app/app.py +++ b/annotation_app/app.py @@ -1,6 +1,6 @@ from flask import Flask, render_template, request, redirect, flash, session, url_for from models import db, Users, Annotations, Samples -from dotenv import load_dotenv +# from dotenv import load_dotenv from sqlalchemy.orm import aliased import sqlalchemy import os @@ -8,12 +8,15 @@ import os import logging -load_dotenv() +# load_dotenv() app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DB_URI') -app.secret_key = os.getenv('SECRET_KEY') +# app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DB_URI') +# app.secret_key = os.getenv('SECRET_KEY') + +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DB_URI'] +app.secret_key = os.environ['SECRET_KEY'] db.init_app(app) @@ -104,12 +107,17 @@ def anot(): ) sample_id, sample_text = query.one_or_none() - data = { - 'email': session.get('email'), - 'text': sample_text, - 'sample_id': sample_id, - 'annotated_count': annotated_count - } + if sample_id: + data = { + 'email': session.get('email'), + 'text': sample_text, + 'sample_id': sample_id, + 'annotated_count': annotated_count + } + else: + flash('Anotácia je dokončená') + return redirect('/') + except (sqlalchemy.exc.OperationalError) as err: print(err) @@ -127,7 +135,6 @@ def anot(): def process(): if request.method == 'POST': data = request.get_json() - print(data) db.session.add(Annotations( user_id=session['id_user'], sample_id=data['sample_id'],