Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Commit

Permalink
Refactor the Dockerfile to build from the Django source directory. Cl…
Browse files Browse the repository at this point in the history
…oses #5
  • Loading branch information
orf authored and Tom Forbes committed Oct 22, 2018
1 parent 2e9ad61 commit c06a82c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 50 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dist: trusty
services:
- docker
language: python
cache: pip
install: skip


Expand Down Expand Up @@ -104,10 +103,6 @@ env:


script:
- export PIP_CACHE_VOLUME=$HOME/.cache/pip/
# Ensure the cache directory works with docker. It is extracted with
# the 'travis' user owning it
- sudo chown -R root:root $HOME/.cache/pip/
- git clone https://github.com/django/django.git --depth=1
- docker-compose pull --include-deps $COMPOSE_APP
- docker-compose build $COMPOSE_APP
Expand Down
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
60 changes: 45 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -58,6 +63,12 @@ services:

postgres-gis:
<<: *base
build:
context: ${DJANGO_PATH}
dockerfile: ${PWD}/Dockerfile
args:
- PYTHON_VERSION=${PYTHON_VERSION}
- EXTRA_REQUIREMENTS=postgres.txt
environment:
- DJANGO_SETTINGS_MODULE=settings.test_postgres_gis
- EXTRA_REQUIREMENTS=postgres.txt
Expand All @@ -77,9 +88,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
Expand All @@ -100,9 +116,14 @@ services:

mysql-gis:
<<: *base
build:
context: ${DJANGO_PATH}
dockerfile: ${PWD}/Dockerfile
args:
- PYTHON_VERSION=${PYTHON_VERSION}
- EXTRA_REQUIREMENTS=mysql.txt
environment:
- DJANGO_SETTINGS_MODULE=settings.test_mysql_gis
- EXTRA_REQUIREMENTS=mysql.txt
depends_on:
mysql-gis-db:
condition: service_healthy
Expand All @@ -113,9 +134,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
Expand All @@ -135,10 +161,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
Expand Down Expand Up @@ -169,17 +200,16 @@ services:

docs:
<<: *base
image: tomforbes/django-docker-box:docs
environment:
- EXTRA_REQUIREMENTS=extra/docs.txt
entrypoint: /entrypoint.sh
command: bash -c "cd docs && make spelling"
command: bash -c "pip install -r extra/docs.txt && cd docs && make spelling"
user: root

flake8:
<<: *base
environment:
- EXTRA_REQUIREMENTS=extra/linting.txt
entrypoint: /entrypoint.sh flake8
image: tomforbes/django-docker-box:flake8
command: bash -c "pip install -r extra/linting.txt && flake8"

volumes:
oracle:
Expand Down
27 changes: 0 additions & 27 deletions entrypoint.sh

This file was deleted.

12 changes: 12 additions & 0 deletions oracle_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 $@

0 comments on commit c06a82c

Please sign in to comment.