From 97061a2efea42432133b4693ac0ea1d8bcc04120 Mon Sep 17 00:00:00 2001 From: Sebastian Steiner Date: Sun, 20 Jan 2019 13:27:30 +0100 Subject: [PATCH] issue #49 for service analysis: indico api key is now in a .env file. readmes, docker-compose file and code adjusted accordingly --- README.md | 2 +- g6t4.yml | 2 ++ service-analysis/Dockerfile | 3 ++- service-analysis/README.md | 4 ++-- service-analysis/analysis.env | 1 + service-analysis/indico_api_key.txt | 1 - service-analysis/sentiment_analysis.py | 3 ++- 7 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 service-analysis/analysis.env delete mode 100644 service-analysis/indico_api_key.txt diff --git a/README.md b/README.md index 8b34e9c..345397a 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ We now support multiple hypervisors! :) + Main Contributor: Sebastian Steiner + external services + https://www.indico.io - + `API KEY: G6T4/service-analysis/indico_api_key.txt` + + `API KEY: G6T4/service-analysis/analysis.env`: `INDICO_API_KEY` ### fallback + Full readme: [fallback](service-fallback/README.md) + Main Contributor: Jan Vales diff --git a/g6t4.yml b/g6t4.yml index ccd58bd..7d9398f 100644 --- a/g6t4.yml +++ b/g6t4.yml @@ -18,6 +18,8 @@ services: ports: - "8081:8081" restart: always + env_file: + - service-analysis/analysis.env service-fallback: build: ./service-fallback diff --git a/service-analysis/Dockerfile b/service-analysis/Dockerfile index be70c7c..c9bbb69 100644 --- a/service-analysis/Dockerfile +++ b/service-analysis/Dockerfile @@ -2,7 +2,8 @@ FROM python:3.7-slim LABEL maintainer="Sebastian Steiner" WORKDIR /app -COPY . /app/ +COPY *.py /app/ +COPY *.txt /app/ RUN pip install -r requirements.txt diff --git a/service-analysis/README.md b/service-analysis/README.md index 57c6b0c..28c838b 100644 --- a/service-analysis/README.md +++ b/service-analysis/README.md @@ -50,12 +50,12 @@ For more examples see curl commands in local -> commands. ## external services This sentiment analysis service uses the online sentiment analysis indico (https://www.indico.io). -The indico api key can be set in the file indico_api_key.txt. The current key does work, however excessive use of this service will require you to provide your own key, since the amount of requests for this key is limited. +The indico api key can be set in the file `analysis.env`. The current key does work, however excessive use of this service will require you to provide your own key, since the amount of requests for this key is limited. In case of an 503 error, you can use the `/offline_analysis`. ## run with docker - `docker build -t sentiment_analysis .` -- `docker container run -d -p YOUR_PORT:8081 sentiment_analysis` +- `docker container run --env-file=analysis.env -d -p YOUR_PORT:8081 sentiment_analysis` ## run local ### requirements diff --git a/service-analysis/analysis.env b/service-analysis/analysis.env new file mode 100644 index 0000000..cdc07a4 --- /dev/null +++ b/service-analysis/analysis.env @@ -0,0 +1 @@ +INDICO_API_KEY=525f16078717a430f9dac17cdc9dbaa3 diff --git a/service-analysis/indico_api_key.txt b/service-analysis/indico_api_key.txt deleted file mode 100644 index 339d02b..0000000 --- a/service-analysis/indico_api_key.txt +++ /dev/null @@ -1 +0,0 @@ -525f16078717a430f9dac17cdc9dbaa3 diff --git a/service-analysis/sentiment_analysis.py b/service-analysis/sentiment_analysis.py index 055a48d..a190266 100644 --- a/service-analysis/sentiment_analysis.py +++ b/service-analysis/sentiment_analysis.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import json import indicoio +import os from analysis import Analysis from offline_analysis import Offline_Analysis @@ -13,7 +14,7 @@ app = Flask(__name__) api = Api(app) with open('indico_api_key.txt', 'r') as key: - indicoio.config.api_key = key.read().replace('\n','') + indicoio.config.api_key = os.environ['INDICO_API_KEY'] api.add_resource(Analysis, '/') api.add_resource(Offline_Analysis, '/offline_analysis') -- 2.43.0