summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-07-17 16:25:21 +0200
committerYorhel <git@yorhel.nl>2019-07-17 16:30:18 +0200
commit0455e42fe95404c998c560b13d4022b0fe097f4e (patch)
tree3ea4d7fa3ce3f902e07e8ecb2115db1b608be746
parent7e95323045b559bbbb637ffd2cf045e15241450d (diff)
Docker: Store Postgres DB in data/ + simplify the setup a bit
I initially wanted to move the static/.. files onto the Docker volume, so that all dynamic site data is stored in a single place. But that turned out to be impossible to do without some really ugly hacks. So instead I went with the opposite approach: get rid of the 'vndb-data' volume and instead store everything in the source directory. This also requires running PostgreSQL as the 'devuser', but that's fine for a development setup. All of this makes it more obvious what is going on and simplifies the init script.
-rw-r--r--.gitignore2
-rw-r--r--README.md32
-rw-r--r--data/config_example.pl2
-rwxr-xr-xutil/docker-init.sh66
4 files changed, 49 insertions, 53 deletions
diff --git a/.gitignore b/.gitignore
index 5309a6ce..2e0ca556 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
/data/config.pl
-/data/docs/8
+/data/docker-pg
/data/icons/icons.css
/data/log/
/data/multi.pid
diff --git a/README.md b/README.md
index 9c8c7268..8fe62550 100644
--- a/README.md
+++ b/README.md
@@ -6,30 +6,38 @@ 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
+ docker run -ti --name vndb -p 3000:3000 -v "`pwd`":/var/www --rm vndb
```
-While running, if you need another terminal into the container:
+If you need another terminal into the container while it's running:
```
- 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
+ docker exec -ti vndb su -l devuser # development shell (files are at /var/www)
+ docker exec -ti vndb psql -U devuser vndb # postgres superuser shell
+ docker exec -ti vndb psql -U vndb # postgres vndb shell
```
-To run Multi, the optional application server:
+To start Multi, the optional application server:
```
- docker exec -ti vndb su -l devuser
- cd /var/www
- make multi-restart
+ docker exec -ti vndb su -l devuser -c 'make -C /var/www multi-restart'
+```
+
+It will run in the background for as long as the container is alive. Logs are
+written to `data/log/multi.log`.
+
+The PostgreSQL database will be stored in `data/docker-pg/` and the uploaded
+files in `static/{ch,cv,sf,st}`. If you want to restart with a clean slate, you
+can stop the container and run:
+
+```
+ # Might want to make a backup of these dirs first if you have any interesting data.
+ rm -rf data/docker-pg static/{ch,cv,sf,st}
```
## Development database
@@ -107,8 +115,8 @@ util/multi.pl (application server, optional):
- Update the vndb_site password in data/config.pl to whatever you set it in
the previous step.
-- (Optional) Import the "Development database" as explained above.
- (Optional) Do the same for vndb_multi if Multi is needed.
+- (Optional) Import the "Development database" as explained above.
- Now simply run:
```
diff --git a/data/config_example.pl b/data/config_example.pl
index dd2fb9db..52482ad8 100644
--- a/data/config_example.pl
+++ b/data/config_example.pl
@@ -6,7 +6,7 @@ package VNDB;
%O = (
%O,
db_login => [ 'dbi:Pg:dbname=vndb', 'vndb_site', 'vndb_site' ],
- logfile => $ROOT.'/err.log',
+ #logfile => $ROOT.'/err.log',
xml_pretty => 0,
log_queries => 0,
debug => 1,
diff --git a/util/docker-init.sh b/util/docker-init.sh
index 6beaf9f4..31c1f415 100755
--- a/util/docker-init.sh
+++ b/util/docker-init.sh
@@ -7,6 +7,7 @@ if ! test -f /var/vndb-docker-image; then
fi
+# Should run as root
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
@@ -24,50 +25,34 @@ mkdevuser() {
useradd -u $USER_UID -g $USER_GID -m -s /bin/bash devuser
fi
- # 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
+ echo 'LANG=en_US.UTF-8' >>/home/devuser/.profile
+ echo 'export LANG' >>/home/devuser/.profile
+ chown devuser:devgroup -R /var/run/postgresql/
}
+# Should run as devuser
pg_start() {
- echo 'local all postgres peer' >/etc/postgresql/10/main/pg_hba.conf
- echo 'local all all md5' >>/etc/postgresql/10/main/pg_hba.conf
- # I'm glad Ubuntu 18.04 still has an init script for this
- /etc/init.d/postgresql start
-}
-
+ if [ ! -d /var/www/data/docker-pg/10 ]; then
+ mkdir -p /var/www/data/docker-pg/10
+ /usr/lib/postgresql/10/bin/pg_ctl initdb -D /var/www/data/docker-pg/10
+ fi
+ echo 'local all all trust' >/var/www/data/docker-pg/10/pg_hba.conf
+ /usr/lib/postgresql/10/bin/pg_ctl -D /var/www/data/docker-pg/10 -l /var/www/data/docker-pg/10/logfile start
-pg_init() {
- if test -f /var/lib/postgresql/vndb-init-done; then
+ cd /var/www
+ if test -f data/docker-pg/vndb-init-done; then
echo
echo "Database initialization already done."
echo
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
- echo
- echo "Database initialization done!"
- echo
-}
-
-# Should run as the postgres user
-pg_load_superuser() {
- psql -f /var/www/util/sql/superuser_init.sql
- echo "ALTER ROLE vndb LOGIN PASSWORD 'vndb'" | psql -U postgres
- echo "ALTER ROLE vndb_site LOGIN PASSWORD 'vndb_site'" | psql -U postgres
- echo "ALTER ROLE vndb_multi LOGIN PASSWORD 'vndb_multi'" | psql -U postgres
-}
+ psql postgres -f util/sql/superuser_init.sql
+ echo "ALTER ROLE vndb LOGIN" | psql postgres
+ echo "ALTER ROLE vndb_site LOGIN" | psql postgres
+ echo "ALTER ROLE vndb_multi LOGIN" | psql postgres
-# Should run as devuser
-pg_load_vndb() {
- cd /var/www
make util/sql/editfunc.sql
psql -U vndb -f util/sql/all.sql
@@ -84,7 +69,14 @@ pg_load_vndb() {
then
curl https://s.vndb.org/devdump.tar.gz | tar -xzf-
psql -U vndb -f dump.sql
+ rm dump.sql
fi
+
+ touch data/docker-pg/vndb-init-done
+
+ echo
+ echo "Database initialization done!"
+ echo
}
@@ -99,15 +91,11 @@ devshell() {
case "$1" in
'')
mkdevuser
- pg_start
- pg_init
+ su devuser -c '/var/www/util/docker-init.sh pg_start'
exec su devuser -c '/var/www/util/docker-init.sh devshell'
;;
- pg_load_superuser)
- pg_load_superuser
- ;;
- pg_load_vndb)
- pg_load_vndb
+ pg_start)
+ pg_start
;;
devshell)
devshell