diff --git a/Dockerfile b/Dockerfile index 40e3d0c..f46da6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,10 +20,14 @@ RUN echo "test ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/test && \ chmod 0440 /etc/sudoers.d/test RUN pip install --upgrade pip -RUN mkdir /tests && chown -R test:test /tests -COPY --chown=test:test entrypoint.sh /entrypoint.sh +COPY --chown=test:test tests/requirements/ /requirements/ +RUN pip install -r /requirements/py3.txt +ARG EXTRA_REQUIREMENTS +RUN test -z ${EXTRA_REQUIREMENTS} || pip install -r /requirements/${EXTRA_REQUIREMENTS} +RUN mkdir /tests && chown -R test:test /tests USER test:test ENV PYTHONPATH "${PYTHONPATH}:/tests/django" -ENTRYPOINT /entrypoint.sh WORKDIR /tests + +ENTRYPOINT /entrypoint.sh \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 698752f..a7e83a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,18 +3,18 @@ version: "2.3" x-base: &base build: - context: . + context: ${DJANGO_PATH} + dockerfile: ${PWD}/Dockerfile args: - PYTHON_VERSION=${PYTHON_VERSION} volumes: - ${DJANGO_PATH}:/tests/django/ - ./settings:/tests/django/tests/settings - ./extra-requirements:/tests/django/tests/requirements/extra/ - - ./entrypoint.sh:/entrypoint.sh - - ${PIP_CACHE_VOLUME}:/root/.cache/pip/ + - ./oracle_entrypoint.sh:/oracle_entrypoint.sh # Using yaml merging here overwrites the arrays. Simpler to just mount this in every service. - ./oracle:/oracle - entrypoint: /entrypoint.sh python tests/runtests.py + entrypoint: python django/tests/runtests.py services: sqlite: @@ -34,9 +34,14 @@ services: postgres: <<: *base + build: + context: ${DJANGO_PATH} + dockerfile: ${PWD}/Dockerfile + args: + - PYTHON_VERSION=${PYTHON_VERSION} + - EXTRA_REQUIREMENTS=postgres.txt environment: - DJANGO_SETTINGS_MODULE=settings.test_postgres - - EXTRA_REQUIREMENTS=postgres.txt depends_on: postgres-db: condition: service_healthy @@ -75,9 +80,14 @@ services: mysql: <<: *base + build: + context: ${DJANGO_PATH} + dockerfile: ${PWD}/Dockerfile + args: + - PYTHON_VERSION=${PYTHON_VERSION} + - EXTRA_REQUIREMENTS=mysql.txt environment: - DJANGO_SETTINGS_MODULE=settings.test_mysql - - EXTRA_REQUIREMENTS=mysql.txt depends_on: mysql-db: condition: service_healthy @@ -111,9 +121,14 @@ services: mariadb: <<: *base + build: + context: ${DJANGO_PATH} + dockerfile: ${PWD}/Dockerfile + args: + - PYTHON_VERSION=${PYTHON_VERSION} + - EXTRA_REQUIREMENTS=mysql.txt environment: - DJANGO_SETTINGS_MODULE=settings.test_mariadb - - EXTRA_REQUIREMENTS=mysql.txt depends_on: mariadb-db: condition: service_healthy @@ -133,10 +148,15 @@ services: oracle: <<: *base + build: + context: ${DJANGO_PATH} + dockerfile: ${PWD}/Dockerfile + args: + - PYTHON_VERSION=${PYTHON_VERSION} + - EXTRA_REQUIREMENTS=oracle.txt environment: - DJANGO_SETTINGS_MODULE=settings.test_oracle - - EXTRA_REQUIREMENTS=oracle.txt - - IS_ORACLE=1 + entrypoint: /oracle_entrypoint.sh python tests/runtests.py depends_on: oracle-db: condition: service_healthy @@ -185,7 +205,6 @@ services: entrypoint: /entrypoint.sh flake8 volumes: - pip-cache: oracle: mysql: mysql-gis: diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 1f6994f..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -set -e -IFS=$'\n\t' - -if [ -z "$(ls -A ./django/)" ]; then - echo "Incorrect DJANGO_PATH specified." - exit 1 -fi - -sudo pip install -r django/tests/requirements/py3.txt - -if [ -n "$EXTRA_REQUIREMENTS" ]; then - sudo pip install -r django/tests/requirements/${EXTRA_REQUIREMENTS} -fi - -if [ -n "$IS_ORACLE" ]; then - if compgen -G "/oracle/*.zip" > /dev/null; then - sudo mkdir -p /opt/oracle - sudo unzip /oracle/*.zip -d /opt/oracle - sudo bash -c "echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf" - sudo ldconfig - fi -fi -cd django/ -echo "Running $@" -exec $@ diff --git a/oracle_entrypoint.sh b/oracle_entrypoint.sh new file mode 100755 index 0000000..18a333b --- /dev/null +++ b/oracle_entrypoint.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e +IFS=$'\n\t' + +if compgen -G "/oracle/*.zip" > /dev/null; then + sudo mkdir -p /opt/oracle + sudo unzip /oracle/*.zip -d /opt/oracle + sudo bash -c "echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf" + sudo ldconfig +fi +exec $@