Vagrantfile 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. Vagrant.configure("2") do |config|
  4. config.vm.box = 'debian/jessie64'
  5. config.vm.host_name = 'postgresql'
  6. config.vm.provider "virtualbox" do |v|
  7. v.customize ["modifyvm", :id, "--memory", 512]
  8. end
  9. config.vm.network "forwarded_port", guest: 5432, host: 15432
  10. config.vm.provision "shell", privileged: true, inline: <<-SHELL
  11. APP_DB_USER=coin
  12. APP_DB_NAME=coin
  13. APP_DB_PASS=coin
  14. PG_VERSION=9.4
  15. PG_CONF="/etc/postgresql/$PG_VERSION/main/postgresql.conf"
  16. PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf"
  17. apt-get -y update
  18. apt-get install -y postgresql
  19. # Edit postgresql.conf to change listen address to '*':
  20. sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" "$PG_CONF"
  21. # Append to pg_hba.conf to add password auth:
  22. echo "host all all all md5" >> "$PG_HBA"
  23. cat << EOF | su - postgres -c psql
  24. -- Cleanup, if required
  25. DROP DATABASE IF EXISTS $APP_DB_NAME;
  26. DROP USER IF EXISTS $APP_DB_USER;
  27. -- Create the database user:
  28. CREATE USER $APP_DB_USER WITH PASSWORD '$APP_DB_PASS';
  29. -- Allow db creation (usefull for unit testing)
  30. ALTER USER $APP_DB_USER CREATEDB;
  31. -- Create the database:
  32. CREATE DATABASE $APP_DB_NAME WITH OWNER=$APP_DB_USER
  33. LC_COLLATE='en_US.utf8'
  34. LC_CTYPE='en_US.utf8'
  35. ENCODING='UTF8'
  36. TEMPLATE=template0;
  37. EOF
  38. systemctl restart postgresql
  39. SHELL
  40. end