aboutsummaryrefslogtreecommitdiff
path: root/docker/entrypoint.sh
diff options
context:
space:
mode:
authorDaniel Axtens <dja@axtens.net>2016-08-09 14:27:40 +1000
committerStephen Finucane <stephenfinucane@hotmail.com>2016-08-20 20:33:07 +0100
commit1f055c4f88553ac5e38bfff89239cb2c45309a78 (patch)
tree29ec5fd994f15fc03dadebb80471e47c6698a0de /docker/entrypoint.sh
parentdc6fc4b72226a1381de30da7a68f4755a105db60 (diff)
downloadpatchwork-1f055c4f88553ac5e38bfff89239cb2c45309a78.tar
patchwork-1f055c4f88553ac5e38bfff89239cb2c45309a78.tar.gz
Allow use of Docker for development
This makes it possible to use Docker and docker-compose for development as an alternative to Vagrant. I quite liked vagrant a couple of years ago, but currently: * Trying to install VirtualBox on Ubuntu wants me to disable Secure Boot, and I don't want to do that. * Trying to use the libvirt plugin for vagrant requires I pick from a very small set of possible images, and requires that I install the upstream vagrant rather than the vagrant shipped with Ubuntu 16.04 * I find docker containers faster to work with and more transparent. So I've done the work to make docker work for Patchwork development. This doesn't break or in any way interfere with using Vagrant, it just provides an alternative. It includes support for headless selenium tests using Chromium. Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Stephen Finucane <stephenfinucane@hotmail.com>
Diffstat (limited to 'docker/entrypoint.sh')
-rwxr-xr-xdocker/entrypoint.sh86
1 files changed, 86 insertions, 0 deletions
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
new file mode 100755
index 0000000..8efaada
--- /dev/null
+++ b/docker/entrypoint.sh
@@ -0,0 +1,86 @@
+#!/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
+else # run whatever CMD is set to
+ $@
+fi