allow data folder to be configured via env var. Adds to #137

This commit is contained in:
Nicholas St. Germain 2019-06-18 17:09:46 -05:00
parent 5ce0447c53
commit 4ee0551ca2
4 changed files with 17 additions and 14 deletions

View file

@ -4,6 +4,8 @@ LABEL maintainers="dirtycajunrice,samwiseg0"
ENV DEBUG="True" ENV DEBUG="True"
ENV DATA_FOLDER="/config"
WORKDIR /app WORKDIR /app
COPY /requirements.txt /Varken.py /app/ COPY /requirements.txt /Varken.py /app/
@ -17,6 +19,6 @@ COPY /utilities /app/data/utilities
RUN apk add --no-cache tzdata && \ RUN apk add --no-cache tzdata && \
pip install --no-cache-dir -r /app/requirements.txt pip install --no-cache-dir -r /app/requirements.txt
CMD cp /app/data/varken.example.ini /config/varken.example.ini && python3 /app/Varken.py --data-folder /config CMD cp /app/data/varken.example.ini /config/varken.example.ini && python3 /app/Varken.py
VOLUME /config VOLUME /config

View file

@ -4,6 +4,8 @@ LABEL maintainers="dirtycajunrice,samwiseg0"
ENV DEBUG="True" ENV DEBUG="True"
ENV DATA_FOLDER="/config"
WORKDIR /app WORKDIR /app
COPY /requirements.txt /Varken.py /app/ COPY /requirements.txt /Varken.py /app/
@ -15,6 +17,6 @@ COPY /data /app/data
RUN apk add --no-cache tzdata && \ RUN apk add --no-cache tzdata && \
pip install --no-cache-dir -r /app/requirements.txt pip install --no-cache-dir -r /app/requirements.txt
CMD cp /app/data/varken.example.ini /config/varken.example.ini && python3 /app/Varken.py --data-folder /config CMD cp /app/data/varken.example.ini /config/varken.example.ini && python3 /app/Varken.py
VOLUME /config VOLUME /config

View file

@ -4,6 +4,8 @@ LABEL maintainers="dirtycajunrice,samwiseg0"
ENV DEBUG="True" ENV DEBUG="True"
ENV DATA_FOLDER="/config"
WORKDIR /app WORKDIR /app
COPY /requirements.txt /Varken.py /app/ COPY /requirements.txt /Varken.py /app/
@ -15,6 +17,6 @@ COPY /data /app/data
RUN apk add --no-cache tzdata && \ RUN apk add --no-cache tzdata && \
pip install --no-cache-dir -r /app/requirements.txt pip install --no-cache-dir -r /app/requirements.txt
CMD cp /app/data/varken.example.ini /config/varken.example.ini && python3 /app/Varken.py --data-folder /config CMD cp /app/data/varken.example.ini /config/varken.example.ini && python3 /app/Varken.py
VOLUME /config VOLUME /config

View file

@ -4,6 +4,7 @@ from time import sleep
from queue import Queue from queue import Queue
from sys import version from sys import version
from threading import Thread from threading import Thread
from os import environ as env
from os import access, R_OK, getenv from os import access, R_OK, getenv
from distro import linux_distribution from distro import linux_distribution
from os.path import isdir, abspath, dirname, join from os.path import isdir, abspath, dirname, join
@ -45,8 +46,6 @@ if __name__ == "__main__":
opts = parser.parse_args() opts = parser.parse_args()
DATA_FOLDER = abspath(join(dirname(__file__), 'data'))
templogger = getLogger('temp') templogger = getLogger('temp')
templogger.setLevel(DEBUG) templogger.setLevel(DEBUG)
tempch = StreamHandler() tempch = StreamHandler()
@ -54,17 +53,15 @@ if __name__ == "__main__":
tempch.setFormatter(tempformatter) tempch.setFormatter(tempformatter)
templogger.addHandler(tempch) templogger.addHandler(tempch)
if opts.data_folder: DATA_FOLDER = env.get('DATA_FOLDER', vars(opts).get('data_folder') or abspath(join(dirname(__file__), 'data')))
ARG_FOLDER = opts.data_folder
if isdir(ARG_FOLDER): if isdir(DATA_FOLDER):
DATA_FOLDER = ARG_FOLDER if not access(DATA_FOLDER, R_OK):
if not access(DATA_FOLDER, R_OK): templogger.error("Read permission error for %s", DATA_FOLDER)
templogger.error("Read permission error for %s", DATA_FOLDER)
exit(1)
else:
templogger.error("%s does not exist", ARG_FOLDER)
exit(1) exit(1)
else:
templogger.error("%s does not exist", DATA_FOLDER)
exit(1)
# Set Debug to True if DEBUG env is set # Set Debug to True if DEBUG env is set
enable_opts = ['True', 'true', 'yes'] enable_opts = ['True', 'true', 'yes']