[PATCH v2 1/4] docker: Move 'docker' directory to 'tools'

Stephen Finucane stephenfinucane at hotmail.com
Tue Aug 30 09:35:38 AEST 2016


...like the Vagrant scripts (which have been renamed also).

Signed-off-by: Stephen Finucane <stephenfinucane at hotmail.com>
---
 .dockerignore                 |  2 +-
 Vagrantfile                   |  2 +-
 docker-compose.yml            |  6 +--
 docker/Dockerfile             | 46 ---------------------
 docker/bashrc                 |  5 ---
 docker/db/.dockerignore       |  1 -
 docker/db/.gitignore          |  1 -
 docker/db/Dockerfile          | 10 -----
 docker/entrypoint.sh          | 93 -------------------------------------------
 tools/docker/Dockerfile       | 46 +++++++++++++++++++++
 tools/docker/bashrc           |  5 +++
 tools/docker/db/.dockerignore |  1 +
 tools/docker/db/.gitignore    |  1 +
 tools/docker/db/Dockerfile    | 10 +++++
 tools/docker/entrypoint.sh    | 93 +++++++++++++++++++++++++++++++++++++++++++
 tools/install/install.sh      | 75 ----------------------------------
 tools/vagrant/install.sh      | 75 ++++++++++++++++++++++++++++++++++
 17 files changed, 236 insertions(+), 236 deletions(-)
 delete mode 100644 docker/Dockerfile
 delete mode 100644 docker/bashrc
 delete mode 100644 docker/db/.dockerignore
 delete mode 100644 docker/db/.gitignore
 delete mode 100644 docker/db/Dockerfile
 delete mode 100755 docker/entrypoint.sh
 create mode 100644 tools/docker/Dockerfile
 create mode 100644 tools/docker/bashrc
 create mode 100644 tools/docker/db/.dockerignore
 create mode 100644 tools/docker/db/.gitignore
 create mode 100644 tools/docker/db/Dockerfile
 create mode 100755 tools/docker/entrypoint.sh
 delete mode 100644 tools/install/install.sh
 create mode 100644 tools/vagrant/install.sh

diff --git a/.dockerignore b/.dockerignore
index 24473bb..83cfa98 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,3 +1,3 @@
 .vagrant
-docker/db
+tools/docker/db
 
diff --git a/Vagrantfile b/Vagrantfile
index b316d41..2ddbca0 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -22,5 +22,5 @@ Vagrant.configure(2) do |config|
   #   vb.memory = "1024"
   # end
 
-  config.vm.provision :shell, :path => "tools/install/install.sh"
+  config.vm.provision :shell, :path => "tools/vagrant/install.sh"
 end
diff --git a/docker-compose.yml b/docker-compose.yml
index 881a72a..7db3486 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -5,12 +5,12 @@
 # or upgrade to v2 and use the build-arg to override it.
 
 db:
-  build: docker/db
+  build: tools/docker/db
   volumes:
-   - ./docker/db/data:/var/lib/mysql
+   - ./tools/docker/db/data:/var/lib/mysql
 web:
   build: .
-  dockerfile: ./docker/Dockerfile
+  dockerfile: ./tools/docker/Dockerfile
   command: python3 manage.py runserver 0.0.0.0:8000
   volumes:
     - .:/home/patchwork/patchwork/
diff --git a/docker/Dockerfile b/docker/Dockerfile
deleted file mode 100644
index ea2a8fc..0000000
--- a/docker/Dockerfile
+++ /dev/null
@@ -1,46 +0,0 @@
-FROM ubuntu
-
-ARG UID=1000
-
-ENV PROJECT_HOME /home/patchwork/patchwork
-
-ENV db_user root
-ENV db_pass password
-
-ENV DJANGO_SETTINGS_MODULE patchwork.settings.dev
-ENV DEBIAN_FRONTEND noninteractive
-ENV PYTHONUNBUFFERED 1
-
-# System
-RUN apt-get update -qq && \
-    apt-get install -y --no-install-recommends \
-    python-dev python-pip python-setuptools python-wheel \
-    python3-dev python3-pip python3-setuptools python3-wheel \
-    libmysqlclient-dev mysql-client curl unzip xvfb chromium-chromedriver \
-    chromium-browser build-essential && \
-    ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/
-
-# User
-RUN useradd --uid=$UID --create-home patchwork
-
-# Python requirements.
-# If you update requirements, you should rebuild the container.
-# entrypoint.sh will prompt you to do this.
-COPY requirements-*.txt /tmp/
-RUN pip3  install virtualenv tox && \
-    pip3  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!
-
-COPY docker/bashrc /tmp/bashrc
-
-# we put the code in ~/patchwork rather than ~ so that we
-# can put in these bashrc snippets without dirtying the
-# working directory
-RUN cat /tmp/bashrc >> /home/patchwork/.bashrc
-
-COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
-
-ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
-USER patchwork
-WORKDIR /home/patchwork/patchwork
diff --git a/docker/bashrc b/docker/bashrc
deleted file mode 100644
index eb2ed7d..0000000
--- a/docker/bashrc
+++ /dev/null
@@ -1,5 +0,0 @@
-# This snippet is appended to ~/.bashrc when the container is created
-
-alias runserver='python3 $PROJECT_HOME/manage.py runserver 0.0.0.0:8000'
-alias createsu='python3 $PROJECT_HOME/manage.py createsuperuser'
-
diff --git a/docker/db/.dockerignore b/docker/db/.dockerignore
deleted file mode 100644
index 1269488..0000000
--- a/docker/db/.dockerignore
+++ /dev/null
@@ -1 +0,0 @@
-data
diff --git a/docker/db/.gitignore b/docker/db/.gitignore
deleted file mode 100644
index 60baa9c..0000000
--- a/docker/db/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-data/*
diff --git a/docker/db/Dockerfile b/docker/db/Dockerfile
deleted file mode 100644
index 5df9b5a..0000000
--- a/docker/db/Dockerfile
+++ /dev/null
@@ -1,10 +0,0 @@
-FROM mysql:5.7
-
-ENV MYSQL_ROOT_PASSWORD password
-ENV MYSQL_USER patchwork
-ENV MYSQL_PASSWORD password
-
-# We don't want to use the MYSQL_DATABASE env here because
-# we want to be able to create the database with UTF-8 explictly.
-# We also can't load in the data because it's in XML, yay.
-
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
deleted file mode 100755
index 744ed69..0000000
--- a/docker/entrypoint.sh
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-set -euo pipefail
-
-# functions
-
-test_db_connection() {
-    mysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping > /dev/null 2> /dev/null
-}
-
-reset_data() {
-    mysql -u$db_user -p$db_pass -h $PW_TEST_DB_HOST << EOF
-DROP DATABASE IF EXISTS patchwork;
-CREATE DATABASE patchwork CHARACTER SET utf8;
-GRANT ALL ON patchwork.* TO 'patchwork' IDENTIFIED BY 'password';
-GRANT ALL PRIVILEGES ON test_patchwork.* TO 'patchwork'@'%';
-FLUSH PRIVILEGES;
-EOF
-
-    # 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
-}
-
-# the script begins!
-
-# check if patchwork is mounted. Checking if we exist is a
-# very good start!
-if [ ! -f ~patchwork/patchwork/docker/entrypoint.sh ]; then
-    echo "The patchwork directory doesn't seem to be mounted!"
-    echo "Are you using docker-compose?"
-    echo "If not, you need -v PATH_TO_PATCHWORK:/home/patchwork/patchwork"
-    exit 1
-fi
-
-# check if we need to rebuild because requirements changed
-for x in /tmp/requirements-*.txt; do
-    if ! cmp $x ~/patchwork/$(basename $x); then
-        echo "A requirements file has changed."
-        echo "Please rebuild the patchwork image:"
-        echo "    docker-compose build web"
-        exit 1
-    fi
-done
-
-# check if mysql is connected
-if ! test_db_connection; then
-    echo "MySQL seems not to be connected, or the patchwork user is broken"
-    echo "MySQL may still be starting. Waiting 5 seconds."
-    sleep 5
-    if ! test_db_connection; then
-        echo "Still cannot connect to MySQL."
-        echo "Maybe you are starting the db for the first time. Waiting 15 seconds."
-        sleep 15
-        if ! test_db_connection; then
-            echo "Still cannot connect to MySQL. Giving up."
-            echo "Are you using docker-compose? If not, have you set up the link correctly?"
-            exit 1
-        fi
-    fi
-fi
-
-# rebuild mysql db
-# do this on --reset or if the db doesn't exist
-if [[ "$1" == "--reset" ]]; then
-    shift
-    reset_data
-elif ! ( echo ';' | mysql -h db -u patchwork -ppassword patchwork 2> /dev/null ); then
-    reset_data
-fi
-
-if [ $# -eq 0 ]; then
-    # we probably ran with --reset and nothing else
-    # just exit cleanly
-    exit 0
-elif [ "$1" == "--shell" ]; then
-    exec bash
-elif [ "$1" == "--quick-test" ]; then
-    export PW_SKIP_BROWSER_TESTS=yes
-    python3 manage.py test
-elif [ "$1" == "--test" ]; then
-    xvfb-run --server-args='-screen 0, 1024x768x16' python3 manage.py test
-elif [ "$1" == "--quick-tox" ]; then
-    shift
-    export PW_SKIP_BROWSER_TESTS=yes
-    tox $@
-elif [ "$1" == "--tox" ]; then
-    shift
-    xvfb-run --server-args='-screen 0, 1024x768x16' tox $@
-else # run whatever CMD is set to
-    $@
-fi
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
new file mode 100644
index 0000000..99a03bd
--- /dev/null
+++ b/tools/docker/Dockerfile
@@ -0,0 +1,46 @@
+FROM ubuntu
+
+ARG UID=1000
+
+ENV PROJECT_HOME /home/patchwork/patchwork
+
+ENV db_user root
+ENV db_pass password
+
+ENV DJANGO_SETTINGS_MODULE patchwork.settings.dev
+ENV DEBIAN_FRONTEND noninteractive
+ENV PYTHONUNBUFFERED 1
+
+# System
+RUN apt-get update -qq && \
+    apt-get install -y --no-install-recommends \
+    python-dev python-pip python-setuptools python-wheel \
+    python3-dev python3-pip python3-setuptools python3-wheel \
+    libmysqlclient-dev mysql-client curl unzip xvfb chromium-chromedriver \
+    chromium-browser build-essential && \
+    ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/
+
+# User
+RUN useradd --uid=$UID --create-home patchwork
+
+# Python requirements.
+# If you update requirements, you should rebuild the container.
+# entrypoint.sh will prompt you to do this.
+COPY requirements-*.txt /tmp/
+RUN pip3  install virtualenv tox && \
+    pip3  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!
+
+COPY tools/docker/bashrc /tmp/bashrc
+
+# we put the code in ~/patchwork rather than ~ so that we
+# can put in these bashrc snippets without dirtying the
+# working directory
+RUN cat /tmp/bashrc >> /home/patchwork/.bashrc
+
+COPY tools/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
+
+ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
+USER patchwork
+WORKDIR /home/patchwork/patchwork
diff --git a/tools/docker/bashrc b/tools/docker/bashrc
new file mode 100644
index 0000000..eb2ed7d
--- /dev/null
+++ b/tools/docker/bashrc
@@ -0,0 +1,5 @@
+# This snippet is appended to ~/.bashrc when the container is created
+
+alias runserver='python3 $PROJECT_HOME/manage.py runserver 0.0.0.0:8000'
+alias createsu='python3 $PROJECT_HOME/manage.py createsuperuser'
+
diff --git a/tools/docker/db/.dockerignore b/tools/docker/db/.dockerignore
new file mode 100644
index 0000000..1269488
--- /dev/null
+++ b/tools/docker/db/.dockerignore
@@ -0,0 +1 @@
+data
diff --git a/tools/docker/db/.gitignore b/tools/docker/db/.gitignore
new file mode 100644
index 0000000..60baa9c
--- /dev/null
+++ b/tools/docker/db/.gitignore
@@ -0,0 +1 @@
+data/*
diff --git a/tools/docker/db/Dockerfile b/tools/docker/db/Dockerfile
new file mode 100644
index 0000000..5df9b5a
--- /dev/null
+++ b/tools/docker/db/Dockerfile
@@ -0,0 +1,10 @@
+FROM mysql:5.7
+
+ENV MYSQL_ROOT_PASSWORD password
+ENV MYSQL_USER patchwork
+ENV MYSQL_PASSWORD password
+
+# We don't want to use the MYSQL_DATABASE env here because
+# we want to be able to create the database with UTF-8 explictly.
+# We also can't load in the data because it's in XML, yay.
+
diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh
new file mode 100755
index 0000000..d8ca798
--- /dev/null
+++ b/tools/docker/entrypoint.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+set -euo pipefail
+
+# functions
+
+test_db_connection() {
+    mysqladmin -h $PW_TEST_DB_HOST -u patchwork --password=password ping > /dev/null 2> /dev/null
+}
+
+reset_data() {
+    mysql -u$db_user -p$db_pass -h $PW_TEST_DB_HOST << EOF
+DROP DATABASE IF EXISTS patchwork;
+CREATE DATABASE patchwork CHARACTER SET utf8;
+GRANT ALL ON patchwork.* TO 'patchwork' IDENTIFIED BY 'password';
+GRANT ALL PRIVILEGES ON test_patchwork.* TO 'patchwork'@'%';
+FLUSH PRIVILEGES;
+EOF
+
+    # 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
+}
+
+# the script begins!
+
+# check if patchwork is mounted. Checking if we exist is a
+# very good start!
+if [ ! -f ~patchwork/patchwork/tools/docker/entrypoint.sh ]; then
+    echo "The patchwork directory doesn't seem to be mounted!"
+    echo "Are you using docker-compose?"
+    echo "If not, you need -v PATH_TO_PATCHWORK:/home/patchwork/patchwork"
+    exit 1
+fi
+
+# check if we need to rebuild because requirements changed
+for x in /tmp/requirements-*.txt; do
+    if ! cmp $x ~/patchwork/$(basename $x); then
+        echo "A requirements file has changed."
+        echo "Please rebuild the patchwork image:"
+        echo "    docker-compose build web"
+        exit 1
+    fi
+done
+
+# check if mysql is connected
+if ! test_db_connection; then
+    echo "MySQL seems not to be connected, or the patchwork user is broken"
+    echo "MySQL may still be starting. Waiting 5 seconds."
+    sleep 5
+    if ! test_db_connection; then
+        echo "Still cannot connect to MySQL."
+        echo "Maybe you are starting the db for the first time. Waiting 15 seconds."
+        sleep 15
+        if ! test_db_connection; then
+            echo "Still cannot connect to MySQL. Giving up."
+            echo "Are you using docker-compose? If not, have you set up the link correctly?"
+            exit 1
+        fi
+    fi
+fi
+
+# rebuild mysql db
+# do this on --reset or if the db doesn't exist
+if [[ "$1" == "--reset" ]]; then
+    shift
+    reset_data
+elif ! ( echo ';' | mysql -h db -u patchwork -ppassword patchwork 2> /dev/null ); then
+    reset_data
+fi
+
+if [ $# -eq 0 ]; then
+    # we probably ran with --reset and nothing else
+    # just exit cleanly
+    exit 0
+elif [ "$1" == "--shell" ]; then
+    exec bash
+elif [ "$1" == "--quick-test" ]; then
+    export PW_SKIP_BROWSER_TESTS=yes
+    python3 manage.py test
+elif [ "$1" == "--test" ]; then
+    xvfb-run --server-args='-screen 0, 1024x768x16' python3 manage.py test
+elif [ "$1" == "--quick-tox" ]; then
+    shift
+    export PW_SKIP_BROWSER_TESTS=yes
+    tox $@
+elif [ "$1" == "--tox" ]; then
+    shift
+    xvfb-run --server-args='-screen 0, 1024x768x16' tox $@
+else # run whatever CMD is set to
+    $@
+fi
diff --git a/tools/install/install.sh b/tools/install/install.sh
deleted file mode 100644
index 3edec85..0000000
--- a/tools/install/install.sh
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/bin/bash
-
-# Script to set up Patchwork on a Vagrant-powered Ubuntu Trusty host
-
-echo -e "\n--- Configuring environment ---\n"
-
-PROJECT_NAME=patchwork
-PROJECT_HOME=/vagrant
-WORKON_HOME=$PROJECT_HOME/.virtualenvs
-
-db_user=root
-db_pass=password
-
-export DJANGO_SETTINGS_MODULE=patchwork.settings.dev
-export DEBIAN_FRONTEND=noninteractive
-
-echo "mysql-server mysql-server/root_password password $db_pass" | debconf-set-selections
-echo "mysql-server mysql-server/root_password_again password $db_pass" | debconf-set-selections
-
-echo -e "\n--- Updating packages list ---\n"
-
-apt-get update -qq
-
-echo -e "\n--- Installing system packages ---\n"
-
-apt-get install -y python python3-dev python3-pip mysql-server \
-    libmysqlclient-dev curl > /dev/null
-
-echo -e "\n--- Installing Python dependencies ---\n"
-
-pip3 -q install virtualenv tox
-pip3 -q install -r $PROJECT_HOME/requirements-dev.txt
-
-echo -e "\n--- Configuring database ---\n"
-
-mysql -u$db_user -p$db_pass << EOF
-DROP DATABASE IF EXISTS patchwork;
-CREATE DATABASE patchwork CHARACTER SET utf8;
-GRANT ALL ON patchwork.* TO 'patchwork'@'localhost' IDENTIFIED BY 'password';
-EOF
-
-chmod a+x $PROJECT_HOME/manage.py
-
-echo -e "\n--- Loading initial data ---\n"
-
-sudo -E -u vagrant python3 $PROJECT_HOME/manage.py migrate > /dev/null
-sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
-    default_tags > /dev/null
-sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
-    default_states > /dev/null
-sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
-    default_projects > /dev/null
-
-echo -e "\n--- Configuring environment ---\n"
-
-cat >> /home/vagrant/.bashrc << EOF
-export DJANGO_SETTINGS_MODULE='patchwork.settings.dev'
-
-alias runserver='python3 /vagrant/manage.py runserver 0.0.0.0:8000'
-alias createsu='python3 /vagrant/manage.py createsuperuser'
-cd /vagrant
-EOF
-
-echo "Done."
-echo "You may now log in:"
-echo "    $ vagrant ssh"
-echo "Once logged in, start the server using the 'runserver' alias:"
-echo "    $ runserver"
-echo "You may wish to create a superuser for use with the admin console:"
-echo "    $ createsuperuser"
-echo "For information on the above, and some examples on loading sample date,"
-echo "please refer to the documentation found in the 'doc' folder."
-echo "Alternatively, check out the docs online:"
-echo "    https://patchwork.readthedocs.org/en/latest/development/"
-echo "Happy patchworking."
diff --git a/tools/vagrant/install.sh b/tools/vagrant/install.sh
new file mode 100644
index 0000000..3edec85
--- /dev/null
+++ b/tools/vagrant/install.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+# Script to set up Patchwork on a Vagrant-powered Ubuntu Trusty host
+
+echo -e "\n--- Configuring environment ---\n"
+
+PROJECT_NAME=patchwork
+PROJECT_HOME=/vagrant
+WORKON_HOME=$PROJECT_HOME/.virtualenvs
+
+db_user=root
+db_pass=password
+
+export DJANGO_SETTINGS_MODULE=patchwork.settings.dev
+export DEBIAN_FRONTEND=noninteractive
+
+echo "mysql-server mysql-server/root_password password $db_pass" | debconf-set-selections
+echo "mysql-server mysql-server/root_password_again password $db_pass" | debconf-set-selections
+
+echo -e "\n--- Updating packages list ---\n"
+
+apt-get update -qq
+
+echo -e "\n--- Installing system packages ---\n"
+
+apt-get install -y python python3-dev python3-pip mysql-server \
+    libmysqlclient-dev curl > /dev/null
+
+echo -e "\n--- Installing Python dependencies ---\n"
+
+pip3 -q install virtualenv tox
+pip3 -q install -r $PROJECT_HOME/requirements-dev.txt
+
+echo -e "\n--- Configuring database ---\n"
+
+mysql -u$db_user -p$db_pass << EOF
+DROP DATABASE IF EXISTS patchwork;
+CREATE DATABASE patchwork CHARACTER SET utf8;
+GRANT ALL ON patchwork.* TO 'patchwork'@'localhost' IDENTIFIED BY 'password';
+EOF
+
+chmod a+x $PROJECT_HOME/manage.py
+
+echo -e "\n--- Loading initial data ---\n"
+
+sudo -E -u vagrant python3 $PROJECT_HOME/manage.py migrate > /dev/null
+sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
+    default_tags > /dev/null
+sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
+    default_states > /dev/null
+sudo -E -u vagrant python3 $PROJECT_HOME/manage.py loaddata \
+    default_projects > /dev/null
+
+echo -e "\n--- Configuring environment ---\n"
+
+cat >> /home/vagrant/.bashrc << EOF
+export DJANGO_SETTINGS_MODULE='patchwork.settings.dev'
+
+alias runserver='python3 /vagrant/manage.py runserver 0.0.0.0:8000'
+alias createsu='python3 /vagrant/manage.py createsuperuser'
+cd /vagrant
+EOF
+
+echo "Done."
+echo "You may now log in:"
+echo "    $ vagrant ssh"
+echo "Once logged in, start the server using the 'runserver' alias:"
+echo "    $ runserver"
+echo "You may wish to create a superuser for use with the admin console:"
+echo "    $ createsuperuser"
+echo "For information on the above, and some examples on loading sample date,"
+echo "please refer to the documentation found in the 'doc' folder."
+echo "Alternatively, check out the docs online:"
+echo "    https://patchwork.readthedocs.org/en/latest/development/"
+echo "Happy patchworking."
-- 
2.7.4



More information about the Patchwork mailing list