Browse Source

Add a vagrant VM running a PostgreSQL database

fix #109
Jocelyn Delalande 8 years ago
parent
commit
18663e40c6
3 changed files with 76 additions and 1 deletions
  1. 2 1
      .gitignore
  2. 53 0
      Vagrantfile
  3. 21 0
      coin/isp_database/migrations/0011_auto_20170227_0029.py

+ 2 - 1
.gitignore

@@ -13,4 +13,5 @@ coin/settings_local.py
 .idea
 venv
 /coin.sqlite3
-.cache/
+.cache/
+.vagrant/

+ 53 - 0
Vagrantfile

@@ -0,0 +1,53 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant.configure("2") do |config|
+
+  config.vm.box = 'debian/jessie64'
+  config.vm.host_name = 'postgresql'
+
+  config.vm.provider "virtualbox" do |v|
+    v.customize ["modifyvm", :id, "--memory", 512]
+  end
+
+  config.vm.network "forwarded_port", guest: 5432, host: 15432
+
+  config.vm.provision "shell", privileged: true, inline: <<-SHELL
+    APP_DB_USER=coin
+    APP_DB_NAME=coin
+    APP_DB_PASS=coin
+
+    PG_VERSION=9.4
+    PG_CONF="/etc/postgresql/$PG_VERSION/main/postgresql.conf"
+    PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf"
+
+    apt-get -y update
+    apt-get install -y postgresql
+
+    # Edit postgresql.conf to change listen address to '*':
+    sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" "$PG_CONF"
+
+    # Append to pg_hba.conf to add password auth:
+    echo "host    all             all             all                     md5" >> "$PG_HBA"
+
+    cat << EOF | su - postgres -c psql
+    -- Cleanup, if required
+    DROP DATABASE IF EXISTS $APP_DB_NAME;
+    DROP USER IF EXISTS $APP_DB_USER;
+
+    -- Create the database user:
+    CREATE USER $APP_DB_USER WITH PASSWORD '$APP_DB_PASS';
+    -- Allow db creation (usefull for unit testing)
+    ALTER USER $APP_DB_USER CREATEDB;
+
+    -- Create the database:
+    CREATE DATABASE $APP_DB_NAME WITH OWNER=$APP_DB_USER
+                                  LC_COLLATE='en_US.utf8'
+                                  LC_CTYPE='en_US.utf8'
+                                  ENCODING='UTF8'
+                                  TEMPLATE=template0;
+EOF
+
+    systemctl restart postgresql
+    SHELL
+end

+ 21 - 0
coin/isp_database/migrations/0011_auto_20170227_0029.py

@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import re
+import django.core.validators
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('isp_database', '0010_ispinfo_phone_number'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='chatroom',
+            name='url',
+            field=models.CharField(max_length=256, verbose_name='URL', validators=[django.core.validators.RegexValidator(regex=re.compile('(?P<protocol>\\w+://)(?P<server>[\\w\\.]+)/(?P<channel>.*)'), message='Enter a value of the form  <proto>://<server>/<channel>')]),
+        ),
+    ]