Browse Source

Add Docker config

Yorhel 11 months ago
parent
commit
66b1bce16c
5 changed files with 147 additions and 2 deletions
  1. 39
    0
      Dockerfile
  2. 3
    0
      Makefile
  3. 17
    1
      README
  4. 1
    1
      data/config_example.pl
  5. 87
    0
      util/docker-init.sh

+ 39
- 0
Dockerfile View File

@@ -0,0 +1,39 @@
1
+FROM ubuntu:rolling
2
+MAINTAINER Yoran Heling <contact@vndb.org>
3
+
4
+RUN apt-get update
5
+
6
+RUN apt-get install -y locales && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
7
+ENV LANG en_US.utf8
8
+
9
+RUN apt-get install -y --no-install-recommends \
10
+    build-essential \
11
+    cpanminus \
12
+    git \
13
+    graphviz \
14
+    imagemagick \
15
+    libalgorithm-diff-xs-perl \
16
+    libanyevent-irc-perl \
17
+    libanyevent-perl \
18
+    libcrypt-urandom-perl \
19
+    libdbd-pg-perl \
20
+    libfcgi-perl \
21
+    libhttp-server-simple-perl \
22
+    libimage-magick-perl \
23
+    libjson-xs-perl \
24
+    libperlio-gzip-perl \
25
+    libpq-dev \
26
+    libtie-ixhash-perl \
27
+    libxml-parser-perl \
28
+    postgresql
29
+
30
+# These modules aren't packaged
31
+RUN cpanm -vn \
32
+    Crypt::ScryptKDF \
33
+    AnyEvent::Pg
34
+
35
+# Get TUWF from Git; I tend to experiment with VNDB before releasing new versions to CPAN.
36
+RUN cd /root && git clone git://g.blicky.net/tuwf.git && cd tuwf && perl Build.PL && ./Build install
37
+
38
+RUN touch /var/vndb-docker-image
39
+CMD /var/www/util/docker-init.sh

+ 3
- 0
Makefile View File

@@ -59,6 +59,9 @@ static/ch static/cv static/sf static/st:
59 59
 data/log www www/feeds www/api static/f:
60 60
 	mkdir -p $@
61 61
 
62
+data/config.pl:
63
+	cp -n data/config_example.pl data/config.pl
64
+
62 65
 static/f/vndb.js: data/js/*.js util/jsgen.pl data/config.pl data/global.pl | static/f
63 66
 	util/jsgen.pl
64 67
 

+ 17
- 1
README View File

@@ -1,7 +1,23 @@
1 1
 The VNDB.org Source Code
2 2
 ------------------------
3 3
 
4
-Requirements
4
+Quick and dirty setup using Docker
5
+
6
+  # Setup
7
+  docker build -t vndb .
8
+  docker volume create --name vndb-data
9
+
10
+  # Run (will run on the foreground)
11
+  docker run -ti --name vndb -p 3000:3000 -v vndb-data:/var/lib/postgresql -v "`pwd`":/var/www --rm vndb
12
+
13
+  # While running, if you need another terminal into the container
14
+  docker exec -ti vndb bash                           # root shell
15
+  docker exec -ti vndb su -l devuser                  # development shell
16
+  docker exec -ti vndb su postgres -c psql            # postgres superuser shell
17
+  docker exec -ti vndb su devuser -c 'psql -U vndb'   # postgres vndb shell
18
+
19
+
20
+Requirements (when not using Docker)
5 21
 
6 22
   global requirements:
7 23
     Linux, or an OS that resembles Linux. Chances are VNDB won't run on Windows.

+ 1
- 1
data/config_example.pl View File

@@ -5,7 +5,7 @@ package VNDB;
5 5
 
6 6
 %O = (
7 7
   %O,
8
-  db_login      => [ 'dbi:Pg:dbname=vndb', 'vndb_site', '<password>' ],
8
+  db_login      => [ 'dbi:Pg:dbname=vndb', 'vndb_site', 'vndb_site' ],
9 9
   logfile       => $ROOT.'/err.log',
10 10
   xml_pretty    => 0,
11 11
   log_queries   => 0,

+ 87
- 0
util/docker-init.sh View File

@@ -0,0 +1,87 @@
1
+#!/bin/sh
2
+
3
+if ! test -f /var/vndb-docker-image; then
4
+    echo "This script should only be run from within the VNDB docker container."
5
+    echo "Check the README for instructions."
6
+    exit 1
7
+fi
8
+
9
+
10
+mkdevuser() {
11
+    # Create a new user with the same UID and GID as the owner of the VNDB
12
+    # directory. This allows for convenient exchange of files without worrying
13
+    # about permission stuff.
14
+    USER_UID=`stat -c '%u' /var/www`
15
+    USER_GID=`stat -c '%g' /var/www`
16
+    groupadd -g $USER_GID devgroup
17
+    useradd -u $USER_UID -g $USER_GID -m -s /bin/bash devuser
18
+
19
+    # So you can easily do a 'psql -U vndb'
20
+    echo '*:*:*:vndb:vndb'              >/home/devuser/.pgpass
21
+    echo '*:*:*:vndb_site:vndb_site'   >>/home/devuser/.pgpass
22
+    echo '*:*:*:vndb_multi:vndb_multi' >>/home/devuser/.pgpass
23
+    chown devuser /home/devuser/.pgpass
24
+    chmod 600 /home/devuser/.pgpass
25
+}
26
+
27
+
28
+pg_start() {
29
+    echo 'local all postgres peer' >/etc/postgresql/9.6/main/pg_hba.conf
30
+    echo 'local all all md5'      >>/etc/postgresql/9.6/main/pg_hba.conf
31
+    # I'm glad Ubuntu 17.10 still has an init script for this
32
+    /etc/init.d/postgresql start
33
+}
34
+
35
+
36
+pg_init() {
37
+    if test -f /var/lib/postgresql/vndb-init-done; then
38
+        echo "Database initialization already done."
39
+        echo "Run the following as root to bypass this check:"
40
+        echo "  rm /var/lib/postgresql/vndb-init-done"
41
+        return
42
+    fi
43
+    su postgres -c '/var/www/util/docker-init.sh pg_load_superuser'
44
+    su devuser -c '/var/www/util/docker-init.sh pg_load_vndb'
45
+    touch /var/lib/postgresql/vndb-init-done
46
+}
47
+
48
+# Should run as the postgres user
49
+pg_load_superuser() {
50
+    psql -f /var/www/util/sql/superuser_init.sql
51
+    echo "ALTER ROLE vndb       LOGIN UNENCRYPTED PASSWORD 'vndb'"       | psql -U postgres
52
+    echo "ALTER ROLE vndb_site  LOGIN UNENCRYPTED PASSWORD 'vndb_site'"  | psql -U postgres
53
+    echo "ALTER ROLE vndb_multi LOGIN UNENCRYPTED PASSWORD 'vndb_multi'" | psql -U postgres
54
+}
55
+
56
+# Should run as devuser
57
+pg_load_vndb() {
58
+    cd /var/www
59
+    psql -U vndb -f util/sql/all.sql
60
+}
61
+
62
+
63
+# Should run as devuser
64
+devshell() {
65
+    cd /var/www
66
+    make && util/vndb.pl
67
+    bash
68
+}
69
+
70
+
71
+case "$1" in
72
+    '')
73
+        mkdevuser
74
+        pg_start
75
+        pg_init
76
+        exec su devuser -c '/var/www/util/docker-init.sh devshell'
77
+        ;;
78
+    pg_load_superuser)
79
+        pg_load_superuser
80
+        ;;
81
+    pg_load_vndb)
82
+        pg_load_vndb
83
+        ;;
84
+    devshell)
85
+        devshell
86
+        ;;
87
+esac