From bbd3cdacc0ebf8b426466a973e1a2845de17eb2c Mon Sep 17 00:00:00 2001 From: Nathan Ostgard Date: Sun, 10 Jan 2016 11:00:56 -0800 Subject: [PATCH 1/2] Added a Dockerfile --- .dockerignore | 1 + Dockerfile | 25 +++++++++++++++++++++++++ elodie/tests/filesystem_test.py | 17 ++++++++++++----- elodie/tests/requirements.txt | 1 + 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6b8710a --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cc0858b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM gliderlabs/alpine + +COPY requirements.txt /opt/elodie/requirements.txt +COPY docs/requirements.txt /opt/elodie/docs/requirements.txt +COPY elodie/tests/requirements.txt /opt/elodie/elodie/tests/requirements.txt +WORKDIR /opt/elodie + +RUN apk add --update boost-python ca-certificates exiftool exiv2 make python py-pip && \ + apk add --virtual build-dependencies build-base boost-dev exiv2-dev openssl python-dev scons wget && \ + pip install -r docs/requirements.txt && \ + pip install -r elodie/tests/requirements.txt && \ + wget -O /tmp/pyexiv2-0.3.2.tar.bz2 https://launchpad.net/pyexiv2/0.3.x/0.3.2/+download/pyexiv2-0.3.2.tar.bz2 && \ + echo "9c0377ca4cf7d5ceeee994af0b5536ae /tmp/pyexiv2-0.3.2.tar.bz2" | md5sum -c - && \ + tar -C /tmp -xjf /tmp/pyexiv2-0.3.2.tar.bz2 && \ + rm -f /tmp/pyexiv2-0.3.2.tar.bz2 && \ + cd /tmp/pyexiv2-0.3.2 && \ + scons && \ + scons install && \ + cd / && \ + apk del build-dependencies && \ + rm -rf /root/.cache/pip /tmp/* /var/cache/apk/* + +COPY . /opt/elodie + +CMD ["/bin/sh"] diff --git a/elodie/tests/filesystem_test.py b/elodie/tests/filesystem_test.py index 78e4be9..6257831 100644 --- a/elodie/tests/filesystem_test.py +++ b/elodie/tests/filesystem_test.py @@ -1,12 +1,13 @@ # Project imports import os -import sys - import re import shutil +import time +import sys from datetime import datetime from datetime import timedelta -import time + +import mock sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) @@ -31,7 +32,7 @@ def test_create_directory_success(): assert status == True assert os.path.isdir(folder) == True assert os.path.exists(folder) == True - + # Clean up shutil.rmtree(folder) @@ -50,9 +51,15 @@ def test_create_directory_recursive_success(): shutil.rmtree(folder) -def test_create_directory_invalid_permissions(): +@mock.patch('elodie.filesystem.os.makedirs') +def test_create_directory_invalid_permissions(mock_makedirs): if os.name == 'nt': raise SkipTest("It isn't implemented on Windows") + + # Mock the case where makedirs raises an OSError because the user does + # not have permission to create the given directory. + mock_makedirs.side_effect = OSError() + filesystem = FileSystem() status = filesystem.create_directory('/apathwhichdoesnotexist/afolderwhichdoesnotexist') diff --git a/elodie/tests/requirements.txt b/elodie/tests/requirements.txt index 0964c1c..0e75cd6 100644 --- a/elodie/tests/requirements.txt +++ b/elodie/tests/requirements.txt @@ -1,3 +1,4 @@ -r ../../requirements.txt +flake8>=2.2.5,<3.0 mock>=1.3.0,<2.0 nose>=1.3.7,<2.0 From 0b5f9cd14354dfea79afcd8c65eeed2eed022795 Mon Sep 17 00:00:00 2001 From: Nathan Ostgard Date: Wed, 2 Mar 2016 10:35:07 -0800 Subject: [PATCH 2/2] Using Debian instead of Alpine It seems that Alpine's boost-dev package (required to build pyexiv2) installed Python 3, and this somehow confuses pyexiv2's build process, which ends up compiling against the Python 3 libraries instead of the Python 2 ones. --- Dockerfile | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index cc0858b..4b10b12 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,33 @@ -FROM gliderlabs/alpine +FROM debian:jessie + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update -y && \ + apt-get install -y --no-install-recommends ca-certificates libimage-exiftool-perl python2.7 python-pip python-pyexiv2 && \ + pip install --upgrade pip setuptools && \ + apt-get autoremove -y && \ + rm -rf /var/lib/apt/lists/* + +# RUN apk add --update boost-python ca-certificates exiftool exiv2 make python py-pip && \ +# pip install --upgrade pip setuptools && \ +# apk add --virtual build-dependencies build-base boost-dev exiv2-dev python-dev scons wget && \ +# wget -O /tmp/pyexiv2-0.3.2.tar.bz2 https://launchpad.net/pyexiv2/0.3.x/0.3.2/+download/pyexiv2-0.3.2.tar.bz2 && \ +# echo "9c0377ca4cf7d5ceeee994af0b5536ae /tmp/pyexiv2-0.3.2.tar.bz2" | md5sum -c - && \ +# tar -C /tmp -xjf /tmp/pyexiv2-0.3.2.tar.bz2 && \ +# rm -f /tmp/pyexiv2-0.3.2.tar.bz2 && \ +# cd /tmp/pyexiv2-0.3.2 && \ +# scons && \ +# scons install && \ +# cd / && \ +# rm -rf /tmp/* COPY requirements.txt /opt/elodie/requirements.txt COPY docs/requirements.txt /opt/elodie/docs/requirements.txt COPY elodie/tests/requirements.txt /opt/elodie/elodie/tests/requirements.txt WORKDIR /opt/elodie - -RUN apk add --update boost-python ca-certificates exiftool exiv2 make python py-pip && \ - apk add --virtual build-dependencies build-base boost-dev exiv2-dev openssl python-dev scons wget && \ - pip install -r docs/requirements.txt && \ +RUN pip install -r docs/requirements.txt && \ pip install -r elodie/tests/requirements.txt && \ - wget -O /tmp/pyexiv2-0.3.2.tar.bz2 https://launchpad.net/pyexiv2/0.3.x/0.3.2/+download/pyexiv2-0.3.2.tar.bz2 && \ - echo "9c0377ca4cf7d5ceeee994af0b5536ae /tmp/pyexiv2-0.3.2.tar.bz2" | md5sum -c - && \ - tar -C /tmp -xjf /tmp/pyexiv2-0.3.2.tar.bz2 && \ - rm -f /tmp/pyexiv2-0.3.2.tar.bz2 && \ - cd /tmp/pyexiv2-0.3.2 && \ - scons && \ - scons install && \ - cd / && \ - apk del build-dependencies && \ - rm -rf /root/.cache/pip /tmp/* /var/cache/apk/* + rm -rf /root/.cache/pip COPY . /opt/elodie