diff --git a/.gitignore b/.gitignore index 83b3f92..cd18224 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ **/__pycache__/** **.pyc Pipfile.lock -config.json +**/config.json data/*.jpg data/*.jpeg data/*.png diff --git a/Dockerfile b/Dockerfile index e69de29..de9d8dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Pull Python 3.8.1 on alpine +FROM python:3.8.1-alpine + +RUN apk --no-cache add gcc \ + musl-dev \ + python3-dev \ + g++ \ + libxslt-dev + +# Create a new user to run as and set the working directory +ENV USER=twitter_media_tool +ENV UID=991 +ENV GID=991 + +RUN addgroup -g "${GID}" twitter_media_tool +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/home/twitter_media_tool" \ + --ingroup "${USER}" \ + --uid "${UID}" \ + "${USER}" + +USER twitter_media_tool +WORKDIR /home/twitter_media_tool/ +ENV PATH="${PATH}:/home/twitter_media_tool/.local/bin" + +COPY Pipfile Pipfile + +RUN pip install pipenv +RUN pipenv install Pipfile + +COPY twitter_media_tool.py twitter_media_tool.py + +ENTRYPOINT [ "pipenv", "run", "python", "twitter_media_tool.py" ] \ No newline at end of file diff --git a/template_config.json b/config/template_config.json similarity index 100% rename from template_config.json rename to config/template_config.json diff --git a/docker-compose.yml b/docker-compose.yml index e69de29..b57ee5c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +--- +version: "3" +services: + twitter_media_tool: + restart: always + build: + context: . + dockerfile: Dockerfile + image: twitter_media_tool:latest + user: twitter_media_tool + container_name: twitter_media_tool_container_service + volumes: + - ./lib:/home/twitter_media_tool/lib + - ./config:/home/twitter_media_tool/config + - ./data:/home/twitter_media_tool/data + environment: + TMT_CONFIG_PATH: config/config.json diff --git a/lib/TweetStreamer.py b/lib/TweetStreamer.py index e021ef7..800c5e1 100644 --- a/lib/TweetStreamer.py +++ b/lib/TweetStreamer.py @@ -3,6 +3,7 @@ from tweepy import StreamListener from lib.archival import archive_media_status from lib.echo_nextcloud import nextcloud_upload_media +import logging class TweetStreamer(StreamListener): diff --git a/lib/setup.py b/lib/setup.py index a5fa732..0faeeeb 100644 --- a/lib/setup.py +++ b/lib/setup.py @@ -1,12 +1,12 @@ #!/usr/bin/python3 from json import load -from sys import argv +from os import environ def import_from_default_path(): try: - with open('config.json') as config_file: + with open('config/config.json') as config_file: return load(config_file) config_file.close() except Exception as e: @@ -15,9 +15,9 @@ def import_from_default_path(): def import_config_file(): - if(len(argv) > 1): + if('TMT_CONFIG_PATH' in environ.keys()): try: - with open(argv[1]) as config_file: + with open(f'{environ["TMT_CONFIG_PATH"]}') as config_file: return load(config_file) config_file.close() except: