summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2019-09-03 15:46:53 +0100
committerStephen Finucane <stephen@that.guru>2019-09-08 18:30:38 +0100
commita0db4732139d2e2c310738c9e60da20b75527a28 (patch)
tree56d0d5dfc410824b3d1e6363fdb1429bd6569760 /tools
parent140453e5df61d4782656fffae0c8940a3e91de6b (diff)
downloadpatchwork-a0db4732139d2e2c310738c9e60da20b75527a28.tar
patchwork-a0db4732139d2e2c310738c9e60da20b75527a28.tar.gz
docker: Use pyenv for Python versions
This is slightly slower to initially configure but requires less hacking to get the same environment and should be a lot more maintainable (just a simple modification to change the Python version). Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'tools')
-rw-r--r--tools/docker/Dockerfile79
-rwxr-xr-xtools/docker/entrypoint.sh10
-rw-r--r--tools/docker/xenial-ports.list3
-rw-r--r--tools/docker/xenial.list3
4 files changed, 47 insertions, 48 deletions
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index 556085c..35324b1 100644
--- a/tools/docker/Dockerfile
+++ b/tools/docker/Dockerfile
@@ -1,54 +1,59 @@
FROM ubuntu:18.04
ARG UID
-ARG TZ="Australia/Canberra"
+
+# make sure the user has configured the '.env' file and quick fail if not
RUN echo $UID
RUN [ -n "$UID" ] || { echo "You must define UID in .env" 1>&2; exit 1; }
-ENV PROJECT_HOME /home/patchwork/patchwork
-
-ENV DJANGO_SETTINGS_MODULE patchwork.settings.dev
+ARG TZ="Australia/Canberra"
+ENV LANG="C.UTF-8"
+ENV LC_ALL="C.UTF-8"
+ENV PATH="/opt/pyenv/shims:/opt/pyenv/bin:$PATH"
+ENV PYENV_ROOT="/opt/pyenv"
+ENV PYENV_SHELL="bash"
ENV DEBIAN_FRONTEND noninteractive
ENV PYTHONUNBUFFERED 1
+ENV PROJECT_HOME /home/patchwork/patchwork
+ENV DJANGO_SETTINGS_MODULE patchwork.settings.dev
-
-# System
-# xenial is for python3.5
-# TODO(stephenfin): Are curl, unzip required?
-COPY tools/docker/*.list /etc/apt/sources.list.d/
-
-RUN cd /etc/apt/sources.list.d; \
- echo $(uname -m) > /tmp/arch; \
- if [ $(cat /tmp/arch) != 'x86_64' ] && grep -q -v "i.86" /tmp/arch; then \
- mv xenial-ports.list xenial.list; \
- else \
- rm *-ports.list; \
- fi
-
-RUN apt-get update -qq && \
- apt-get install -y --no-install-recommends --allow-downgrades \
- python-dev python-pip python-setuptools python-wheel \
- python3.5-dev python3-pip python3-setuptools python3-wheel \
- python3.6-dev \
- libmysqlclient-dev mysql-client curl unzip build-essential \
- git postgresql-client tzdata libpq-dev
-
-# User
RUN useradd --uid=$UID --create-home patchwork
-
-# Timezone
RUN rm /etc/localtime; ln -s /usr/share/zoneinfo/$TZ /etc/localtime
-# Python requirements.
-# If you update requirements, you should rebuild the container.
-# entrypoint.sh will prompt you to do this.
-# we install both Python 2 and Python 3 versions so you can use either
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ build-essential \
+ ca-certificates \
+ curl \
+ git \
+ libbz2-dev \
+ libffi-dev \
+ libmysqlclient-dev \
+ libpq-dev \
+ libreadline-dev \
+ libsqlite3-dev \
+ libssl1.0-dev \
+ mysql-client \
+ postgresql-client \
+ tzdata \
+ zlib1g-dev \
+ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
+
+RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash && \
+ git clone https://github.com/momo-lab/xxenv-latest $PYENV_ROOT/plugins/xxenv-latest && \
+ pyenv update
+
+RUN pyenv latest install 2.7 && \
+ pyenv latest install 3.5 && \
+ pyenv latest install 3.6 && \
+ pyenv latest install 3.7
+
+RUN pyenv global $(pyenv versions --bare | tac)
+
COPY requirements-*.txt /tmp/
-RUN pip3 install virtualenv tox && \
- pip3 install -r /tmp/requirements-dev.txt
-RUN pip2 install virtualenv tox && \
- pip2 install -r /tmp/requirements-dev.txt
+RUN pip install tox tox-pyenv && \
+ pip install -r /tmp/requirements-dev.txt
+
# we deliberately leave the requirements files in tmp so we can
# ping the user in entrypoint.sh if the change them!
diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh
index 08fa190..456d640 100755
--- a/tools/docker/entrypoint.sh
+++ b/tools/docker/entrypoint.sh
@@ -46,10 +46,10 @@ reset_data() {
fi
# load initial data
- python3 $PROJECT_HOME/manage.py migrate #> /dev/null
- python3 $PROJECT_HOME/manage.py loaddata default_tags #> /dev/null
- python3 $PROJECT_HOME/manage.py loaddata default_states #> /dev/null
- python3 $PROJECT_HOME/manage.py loaddata default_projects #> /dev/null
+ python manage.py migrate #> /dev/null
+ python manage.py loaddata default_tags #> /dev/null
+ python manage.py loaddata default_states #> /dev/null
+ python manage.py loaddata default_projects #> /dev/null
}
# the script begins!
@@ -126,7 +126,7 @@ elif [ "$1" == "--shell" ]; then
exec bash
elif [ "$1" == "--test" ] || [ "$1" == "--quick-test" ]; then
shift
- python3 manage.py test $@
+ python manage.py test $@
elif [ "$1" == "--tox" ] || [ "$1" == "--quick-tox" ]; then
shift
tox $@
diff --git a/tools/docker/xenial-ports.list b/tools/docker/xenial-ports.list
deleted file mode 100644
index d84641f..0000000
--- a/tools/docker/xenial-ports.list
+++ /dev/null
@@ -1,3 +0,0 @@
-deb http://ports.ubuntu.com/ubuntu-ports/ xenial main
-deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main
-deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main
diff --git a/tools/docker/xenial.list b/tools/docker/xenial.list
deleted file mode 100644
index a70ff56..0000000
--- a/tools/docker/xenial.list
+++ /dev/null
@@ -1,3 +0,0 @@
-deb http://archive.ubuntu.com/ubuntu/ xenial main
-deb http://archive.ubuntu.com/ubuntu/ xenial-updates main
-deb http://security.ubuntu.com/ubuntu xenial-security main