From 508e44f4907c43bff5fe3e0c065b897ea5ae273e Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 11 Sep 2018 22:25:09 -0700 Subject: [PATCH] Docker fixes --- .dockerignore | 12 ++++++++++++ Dockerfile | 37 +++++++++++++++++++++++++++++++++++++ photoapp/daemon.py | 5 +++-- photoapp/library.py | 4 ++-- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a235ff1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +build/ +cache/ +dist/ +dropbox/ +library/ +node_modules/ +photoapp.egg-info/ +photos.db +styles/css/ +styles/dist/ +styles/mincss/ +testenv/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..54c246e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM ubuntu:bionic + +RUN apt-get update && \ + apt-get install -y wget software-properties-common && \ + echo "deb https://deb.nodesource.com/node_10.x bionic main" | tee /etc/apt/sources.list.d/nodesource.list && \ + wget -O- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \ + apt-get update && \ + apt-get install -y nodejs + +ADD . /tmp/code/ + +RUN cd /tmp/code && \ + npm install && \ + ./node_modules/.bin/grunt + +FROM ubuntu:bionic + +ADD . /tmp/code/ + +COPY --from=0 /tmp/code/styles/dist/style.css /tmp/code/styles/dist/style.css + +RUN apt-get update && \ + apt-get install -y python3-pip + +RUN pip3 install -U pip && \ + cd /tmp/code && \ + pip install -r requirements.txt && \ + python3 setup.py install && \ + useradd --uid 1000 app + +VOLUME /srv/library +VOLUME /srv/cache +VOLUME /srv/db + +USER app + +ENTRYPOINT ["photoappd", "--library", "/srv/library", "--database", "/srv/db/photos.db", "--cache", "/srv/cache"] diff --git a/photoapp/daemon.py b/photoapp/daemon.py index 58db3c6..0095b45 100644 --- a/photoapp/daemon.py +++ b/photoapp/daemon.py @@ -230,7 +230,8 @@ def main(): parser.add_argument('-p', '--port', default=8080, type=int, help="tcp port to listen on") parser.add_argument('-l', '--library', default="./library", help="library path") - parser.add_argument('-s', '--database-path', default="./photos.db", help="path to persistent sqlite database") + parser.add_argument('-c', '--cache', default="./cache", help="cache path") + parser.add_argument('-s', '--database', default="./photos.db", help="path to persistent sqlite database") parser.add_argument('--debug', action="store_true", help="enable development options") args = parser.parse_args() @@ -238,7 +239,7 @@ def main(): logging.basicConfig(level=logging.INFO if args.debug else logging.WARNING, format="%(asctime)-15s %(levelname)-8s %(filename)s:%(lineno)d %(message)s") - library = PhotoLibrary(args.database_path, args.library) + library = PhotoLibrary(args.database, args.library, args.cache) tpl_dir = os.path.join(APPROOT, "templates") if not args.debug else "templates" diff --git a/photoapp/library.py b/photoapp/library.py index 1688a99..320d750 100644 --- a/photoapp/library.py +++ b/photoapp/library.py @@ -13,9 +13,9 @@ from PIL import Image, ImageOps class PhotoLibrary(object): - def __init__(self, db_path, lib_path): + def __init__(self, db_path, lib_path, cache_path): self.path = lib_path - self.cache_path = "./cache" # TODO param + self.cache_path = cache_path self.engine = create_engine('sqlite:///{}'.format(db_path), connect_args={'check_same_thread': False}, poolclass=StaticPool, echo=False) Base.metadata.create_all(self.engine)