diff --git a/Dockerfile b/Dockerfile index 3db0429..90784d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,20 +26,24 @@ COPY *.sql /viasat/minitwit #### FROM builder AS tester +# Only copy the development tools from the requirements for tests COPY requirements-dev.txt . RUN pip install -r requirements-dev.txt -# Note that we are executing the tests here because we don't want to build -# A runtime image before the tests are executed successfully! -RUN pytest test_minitwit.py +# All the requirements are installed and so the test cases can be executed CMD ["pytest", "test_minitwit.py"] ### -### runtime environment containing only the runtime dependencies. +### Runtime environment containing only the runtime dependencies. +### Note that this image does NOT have anything for testing! ### FROM builder AS runtime # All the other resources are there, so let's add the run-app as it's part of the runtime +# Note that the builder runtime defines the WORKDIR already so we can COPY to . COPY run-app . +COPY init-db . + +RUN rm -rf requirements* test_minitwit.py ENTRYPOINT ["bash", "/viasat/minitwit/run-app"] diff --git a/init-db b/init-db index 61b5de7..7373673 100755 --- a/init-db +++ b/init-db @@ -4,9 +4,11 @@ export FLASK_APP=minitwit.py export LC_ALL=en_US.utf-8 export LANG=en_US.utf-8 +DB_DIR=${DB_DIR:-/var/minitwit} + # Initialize the path where the db is -if [ ! -d /var/minitwit ]; then - mkdir -p /var/minitwit/ +if [ ! -d ${DB_DIR} ]; then + mkdir -p ${DB_DIR} fi flask initdb diff --git a/run-app b/run-app index 2775dab..10a02af 100755 --- a/run-app +++ b/run-app @@ -4,8 +4,10 @@ export FLASK_APP=minitwit.py export LC_ALL=en_US.utf-8 export LANG=en_US.utf-8 -if [ ! -f /var/minitwit/minitwit.db ] || [ -n "${INIT_DB}" ]; then - echo "Initializing database at /var/minitwit/minitwit.db" +export DB_DIR=${DB_DIR:-/var/minitwit} + +if [ ! -f ${DB_DIR}/minitwit.db ] || [ -n "${INIT_DB}" ]; then + echo "Initializing database at ${DB_DIR}/minitwit.db" ./init-db fi