From 66b1bce16cf42461185060f999724b775bb0a2cb Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sat, 9 Dec 2017 09:49:17 +0100 Subject: Add Docker config --- Dockerfile | 39 ++++++++++++++++++++++ Makefile | 3 ++ README | 18 ++++++++++- data/config_example.pl | 2 +- util/docker-init.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100755 util/docker-init.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0220e6b5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +FROM ubuntu:rolling +MAINTAINER Yoran Heling + +RUN apt-get update + +RUN apt-get install -y locales && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +ENV LANG en_US.utf8 + +RUN apt-get install -y --no-install-recommends \ + build-essential \ + cpanminus \ + git \ + graphviz \ + imagemagick \ + libalgorithm-diff-xs-perl \ + libanyevent-irc-perl \ + libanyevent-perl \ + libcrypt-urandom-perl \ + libdbd-pg-perl \ + libfcgi-perl \ + libhttp-server-simple-perl \ + libimage-magick-perl \ + libjson-xs-perl \ + libperlio-gzip-perl \ + libpq-dev \ + libtie-ixhash-perl \ + libxml-parser-perl \ + postgresql + +# These modules aren't packaged +RUN cpanm -vn \ + Crypt::ScryptKDF \ + AnyEvent::Pg + +# Get TUWF from Git; I tend to experiment with VNDB before releasing new versions to CPAN. +RUN cd /root && git clone git://g.blicky.net/tuwf.git && cd tuwf && perl Build.PL && ./Build install + +RUN touch /var/vndb-docker-image +CMD /var/www/util/docker-init.sh diff --git a/Makefile b/Makefile index 33a6bd6e..1ad640ba 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,9 @@ static/ch static/cv static/sf static/st: data/log www www/feeds www/api static/f: mkdir -p $@ +data/config.pl: + cp -n data/config_example.pl data/config.pl + static/f/vndb.js: data/js/*.js util/jsgen.pl data/config.pl data/global.pl | static/f util/jsgen.pl diff --git a/README b/README index fd3d3e08..e44ae07b 100644 --- a/README +++ b/README @@ -1,7 +1,23 @@ The VNDB.org Source Code ------------------------ -Requirements +Quick and dirty setup using Docker + + # Setup + docker build -t vndb . + docker volume create --name vndb-data + + # Run (will run on the foreground) + docker run -ti --name vndb -p 3000:3000 -v vndb-data:/var/lib/postgresql -v "`pwd`":/var/www --rm vndb + + # While running, if you need another terminal into the container + docker exec -ti vndb bash # root shell + docker exec -ti vndb su -l devuser # development shell + docker exec -ti vndb su postgres -c psql # postgres superuser shell + docker exec -ti vndb su devuser -c 'psql -U vndb' # postgres vndb shell + + +Requirements (when not using Docker) global requirements: Linux, or an OS that resembles Linux. Chances are VNDB won't run on Windows. diff --git a/data/config_example.pl b/data/config_example.pl index dd714c9c..4d0988c6 100644 --- a/data/config_example.pl +++ b/data/config_example.pl @@ -5,7 +5,7 @@ package VNDB; %O = ( %O, - db_login => [ 'dbi:Pg:dbname=vndb', 'vndb_site', '' ], + db_login => [ 'dbi:Pg:dbname=vndb', 'vndb_site', 'vndb_site' ], logfile => $ROOT.'/err.log', xml_pretty => 0, log_queries => 0, diff --git a/util/docker-init.sh b/util/docker-init.sh new file mode 100755 index 00000000..dce2339c --- /dev/null +++ b/util/docker-init.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +if ! test -f /var/vndb-docker-image; then + echo "This script should only be run from within the VNDB docker container." + echo "Check the README for instructions." + exit 1 +fi + + +mkdevuser() { + # Create a new user with the same UID and GID as the owner of the VNDB + # directory. This allows for convenient exchange of files without worrying + # about permission stuff. + USER_UID=`stat -c '%u' /var/www` + USER_GID=`stat -c '%g' /var/www` + groupadd -g $USER_GID devgroup + useradd -u $USER_UID -g $USER_GID -m -s /bin/bash devuser + + # So you can easily do a 'psql -U vndb' + echo '*:*:*:vndb:vndb' >/home/devuser/.pgpass + echo '*:*:*:vndb_site:vndb_site' >>/home/devuser/.pgpass + echo '*:*:*:vndb_multi:vndb_multi' >>/home/devuser/.pgpass + chown devuser /home/devuser/.pgpass + chmod 600 /home/devuser/.pgpass +} + + +pg_start() { + echo 'local all postgres peer' >/etc/postgresql/9.6/main/pg_hba.conf + echo 'local all all md5' >>/etc/postgresql/9.6/main/pg_hba.conf + # I'm glad Ubuntu 17.10 still has an init script for this + /etc/init.d/postgresql start +} + + +pg_init() { + if test -f /var/lib/postgresql/vndb-init-done; then + echo "Database initialization already done." + echo "Run the following as root to bypass this check:" + echo " rm /var/lib/postgresql/vndb-init-done" + return + fi + su postgres -c '/var/www/util/docker-init.sh pg_load_superuser' + su devuser -c '/var/www/util/docker-init.sh pg_load_vndb' + touch /var/lib/postgresql/vndb-init-done +} + +# Should run as the postgres user +pg_load_superuser() { + psql -f /var/www/util/sql/superuser_init.sql + echo "ALTER ROLE vndb LOGIN UNENCRYPTED PASSWORD 'vndb'" | psql -U postgres + echo "ALTER ROLE vndb_site LOGIN UNENCRYPTED PASSWORD 'vndb_site'" | psql -U postgres + echo "ALTER ROLE vndb_multi LOGIN UNENCRYPTED PASSWORD 'vndb_multi'" | psql -U postgres +} + +# Should run as devuser +pg_load_vndb() { + cd /var/www + psql -U vndb -f util/sql/all.sql +} + + +# Should run as devuser +devshell() { + cd /var/www + make && util/vndb.pl + bash +} + + +case "$1" in + '') + mkdevuser + pg_start + pg_init + exec su devuser -c '/var/www/util/docker-init.sh devshell' + ;; + pg_load_superuser) + pg_load_superuser + ;; + pg_load_vndb) + pg_load_vndb + ;; + devshell) + devshell + ;; +esac -- cgit v1.2.3