From 21949bdd2c6a3980291bafeb9b29646d1e56c74a Mon Sep 17 00:00:00 2001 From: Notoric Date: Sun, 2 Jun 2024 18:57:30 +0100 Subject: [PATCH] Added docker release --- .gitignore | 3 +- Docker/Dockerfile | 9 ++ Docker/config_template.json | 20 +++ Docker/docker-compose.yml | 23 ++++ Docker/generate-config.py | 24 ++++ Docker/requirements.txt | Bin 0 -> 720 bytes Docker/snc.py | 260 ++++++++++++++++++++++++++++++++++++ script.py => snc.py | 5 +- 8 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 Docker/Dockerfile create mode 100644 Docker/config_template.json create mode 100644 Docker/docker-compose.yml create mode 100644 Docker/generate-config.py create mode 100644 Docker/requirements.txt create mode 100644 Docker/snc.py rename script.py => snc.py (97%) diff --git a/.gitignore b/.gitignore index f9fab25..7d1b864 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config.json -venv/* \ No newline at end of file +venv/* +Docker/data \ No newline at end of file diff --git a/Docker/Dockerfile b/Docker/Dockerfile new file mode 100644 index 0000000..dd4068b --- /dev/null +++ b/Docker/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.9-slim +WORKDIR /usr/src/app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python", "-u", "snc.py"] \ No newline at end of file diff --git a/Docker/config_template.json b/Docker/config_template.json new file mode 100644 index 0000000..c805c1a --- /dev/null +++ b/Docker/config_template.json @@ -0,0 +1,20 @@ +{ + "mongo" : { + "host" : "$MONGO_HOST", + "port" : "$MONGO_PORT", + "db" : "$MONGO_DB" + }, + "groq" : { + "api_key" : "$GROQ_API_KEY" + }, + "weather" : { + "api_key" : "$OPENWEATHERMAP_API_KEY", + "city" : "coalville,uk" + }, + "news" : { + "api_key" : "$NEWSAPI_API_KEY", + "country" : "$NEWSAPI_COUNTRY", + "article_lifetime": "$NEWSAPI_ARTICLE_LIFETIME", + "article_interval": "$NEWSAPI_ARTICLE_INTERVAL" + } +} \ No newline at end of file diff --git a/Docker/docker-compose.yml b/Docker/docker-compose.yml new file mode 100644 index 0000000..031fa35 --- /dev/null +++ b/Docker/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3' +services: + python-script: + container_name: notoric-snc + build: . + environment: + - MONGO_HOST=mongodb + - MONGO_PORT=27017 + - MONGO_DB=notoric-snc + - GROQ_API_KEY= + - OPENWEATHERMAP_API_KEY= + - OPENWEATHERMAP_CITY=London,uk + - NEWSAPI_API_KEY= + - NEWSAPI_COUNTRY=gb + - ARTICLE_LIFETIME=6 # in hours + - ARTICLE_INTERVAL=1 # in hours + mongodb: + container_name: notoric-snc-mongo + image: mongo + ports: + - "27017:27017" + volumes: + - ./data:/data/db \ No newline at end of file diff --git a/Docker/generate-config.py b/Docker/generate-config.py new file mode 100644 index 0000000..36cec46 --- /dev/null +++ b/Docker/generate-config.py @@ -0,0 +1,24 @@ +import os +import json + +# Load the template +with open('config_template.json', 'r') as template_file: + config_template = template_file.read() + +# Replace the placeholders with the actual values +config = config_template.replace('$MONGO_HOST', os.environ['MONGO_HOST']) \ + .replace('$MONGO_PORT', os.environ['MONGO_PORT']) \ + .replace('$MONGO_DB', os.environ['MONGO_DB']) \ + .replace('$GROQ_API_KEY', os.environ['GROQ_API_KEY']) \ + .replace('$OPENWEATHERMAP_API_KEY', os.environ['OPENWEATHERMAP_API_KEY']) \ + .replace('$OPENWEATHERMAP_CITY', os.environ['OPENWEATHERMAP_CITY']) \ + .replace('$NEWSAPI_API_KEY', os.environ['NEWSAPI_API_KEY']) \ + .replace('$NEWSAPI_COUNTRY', os.environ['NEWSAPI_COUNTRY']) \ + .replace('$NEWSAPI_ARTICLE_LIFETIME', os.environ['ARTICLE_LIFETIME']) \ + .replace('$NEWSAPI_ARTICLE_INTERVAL', os.environ['ARTICLE_INTERVAL']) + +# Write the config to a file +with open('config.json', 'w') as config_file: + config_file.write(config) + +print("Config file created!") \ No newline at end of file diff --git a/Docker/requirements.txt b/Docker/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..2e0139172d70b875e22b9247d2ebfdd093cdd974 GIT binary patch literal 720 zcmZ9K(N2S44264b;-hRCpiVD*mSqACk_|T)3G?CA@3equNC*3SdU|^Pet+$);rXzu z?TOL~Tk*cxneWbCc{aATEwQnCy93pbt*KD%fpbOVa%x(tYkMb@PsyZ?NI|8}kXr>y z3wsH6<=tC5adxEY(>YX|QK5*cf?Nl_9XlsvUWn*iz|x`l2BHGdjNRAv1Savmr41&9 zXICi9!P$CF)K8338R*DeJR=95iRe{B8F@ z_Zxherr&yvrYhWbIh%V{I&~-E&40x1kAj#<`m>quORBY*s