From 9a5c281a8b0666972a69e3536852203586bc065b Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 21 May 2018 00:39:40 -0400 Subject: [PATCH] Add support for running tests from a Docker container. Signed-off-by: Roberto Rosario --- .gitlab-ci.yml | 14 ++++++----- contrib/scripts/docker/run-tests.sh | 8 ++++++ docker/entrypoint.sh | 39 ++++++++++++++++++++--------- 3 files changed, 43 insertions(+), 18 deletions(-) create mode 100755 contrib/scripts/docker/run-tests.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7cb1413814..ae82fbc5ce 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,9 +1,9 @@ stages: - test - build - + job_docker_master: - stage: build + stage: build image: docker:latest services: - docker:dind @@ -11,10 +11,11 @@ job_docker_master: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker build --pull -t "$CI_REGISTRY_IMAGE" -f docker/Dockerfile . + - docker run --rm "$CI_REGISTRY_IMAGE" run-tests - docker push "$CI_REGISTRY_IMAGE" only: - master - + job_docker_other: stage: build image: docker:latest @@ -24,6 +25,7 @@ job_docker_other: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" -f docker/Dockerfile . + - docker run --rm "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" run-tests - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" except: - master @@ -44,7 +46,7 @@ job_docker_other: - export LC_ALL=en_US.UTF-8 - apt-get install -qq curl gcc ghostscript gpgv gnupg graphviz libjpeg-dev libmagic1 libpng-dev libtiff-dev poppler-utils libreoffice poppler-utils python-dev python-pip tesseract-ocr tesseract-ocr-deu - pip install -r requirements/testing.txt - + test-mysql: <<: *test_base variables: @@ -59,7 +61,7 @@ test-mysql: - python manage.py test --mayan-apps --settings=mayan.settings.testing.gitlab-ci.db_mysql --nomigrations tags: - mysql - + test-postgres: <<: *test_base variables: @@ -73,7 +75,7 @@ test-postgres: - python manage.py test --mayan-apps --settings=mayan.settings.testing.gitlab-ci.db_postgres --nomigrations tags: - postgres - + test-sqlite: <<: *test_base script: diff --git a/contrib/scripts/docker/run-tests.sh b/contrib/scripts/docker/run-tests.sh new file mode 100755 index 0000000000..6c704ebf34 --- /dev/null +++ b/contrib/scripts/docker/run-tests.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +apt-get update +apt-get install -y --no-install-recommends tesseract-ocr-deu + +pip install -r $DOCKER_ROOT/requirements-testing.txt + +mayan-edms.py test --mayan-apps diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 2cae44a51f..55df42cc57 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -3,6 +3,7 @@ set -e echo "mayan: starting entrypoint.sh" INSTALL_FLAG=/var/lib/mayan/media/system/SECRET_KEY +export DOCKER_ROOT=/root export MAYAN_DEFAULT_BROKER_URL=redis://127.0.0.1:6379/0 export MAYAN_DEFAULT_CELERY_RESULT_BACKEND=redis://127.0.0.1:6379/0 @@ -57,15 +58,29 @@ pip_installs() { os_package_installs || true pip_installs || true -if [ "$1" = 'mayan' ]; then - # Check if this is a new install, otherwise try to upgrade the existing - # installation on subsequent starts - if [ ! -f $INSTALL_FLAG ]; then - initialize - else - upgrade - fi - start -else - su mayan -c "mayan-edms.py $@"; -fi +case "$1" in + +mayan) # Check if this is a new install, otherwise try to upgrade the existing + # installation on subsequent starts + if [ ! -f $INSTALL_FLAG ]; then + initialize + else + upgrade + fi + start + ;; + +run-tests) # Check if this is a new install, otherwise try to upgrade the existing + # installation on subsequent starts + if [ ! -f $INSTALL_FLAG ]; then + initialize + else + upgrade + fi + $DOCKER_ROOT/run-tests.sh + ;; + +*) su mayan -c "$@"; + ;; + +esac