diff --git a/.gitignore b/.gitignore index 8000dd9..da8b73f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .vagrant +ubuntu*.log diff --git a/README.md b/README.md index 29b7d8d..2684caa 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,68 @@ Based off project: https://github.com/jackdb/pg-app-dev-vm -* Ubuntu 14.04 LTS -* Elixir 1.0.5 -* Phoenix 1.0.0 -* PosgreSQL 9.4.4 -* NodeJS 0.12.7 -* Git 1.9.1 +* Ubuntu 15.10 +* Elixir 1.2.4 (latest version) +* Phoenix 1.1.4 (latest version) +* PosgreSQL 9.5 (latest version 9.5.x) +* NodeJS 5.x (latest version 5.x) +* Git 2.8.0 (latest version) This box is published in Atlas as 'lazygray/phoenix-postgres' and can be used simply by adding `config.vm.box = 'lazygray/phoenix-postgres'` to your `Vagrantfile`. + +## For Vagrant users on Windows +On Windows platforms with Vagrant version 1.8.0 and 1.8.1 there are issues +getting rsync to work. + +Perhaps a newer version of Vagrant might resolve this issue on Windows. +- https://github.com/mitchellh/vagrant/issues/6702 +- https://github.com/mitchellh/vagrant/issues/3230 + +If on Windows, and you are not able to get rsync to work, the following code +in the `Vagrantfile` can be commented out +``` +config.vm.synced_folder( + '.', + '/vagrant', + type: 'rsync', + rsync__exclude: [ + '.git/', + '.vagrant/', + 'log/*', + 'tmp/' + ] +) +``` + +and replaced with the code below. + +Use the following on Windows to 'resolve' the rsync issue above. +``` +config.vm.synced_folder "..", "/vagrant_data" +``` + +Your file structure on windows will then be as follows: + +``` +project +| +└─── vagrant-phoenix-postgres-master + │ .gitignore + │ README.mde + │ Vagrantfile + | + ├─── .vagrant + | | ... + ├─── config + | + ├─── vagrant + | build_dependency_setup.sh + | elixir_setup.sh + | git_setup.sh + | phoenix_setup.sh + | postgresql_setup.sh +``` + +The fixes in the issues above seem to relate the use of rsync in relation to +CygWin. I tried using cwRsync (https://www.itefix.net/cwrsync) on Windows, but was not able to get that rsync to work. diff --git a/Vagrantfile b/Vagrantfile index f855099..e7c39b1 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -9,27 +9,27 @@ SCRIPT # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = '2' +MEMORY_SIZE_MB = 1024 +NUMBER_OF_CPUS = 2 +VM_NAME = "vagrant-phoenix-postgres" +VM_LINKED = true + Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. + config.vm.provider "virtualbox" do |v| + v.memory = MEMORY_SIZE_MB + v.cpus = NUMBER_OF_CPUS + v.name = VM_NAME + v.linked_clone = VM_LINKED + end + config.vm.provision 'shell', inline: $script # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = 'ubuntu/trusty64' - - config.vm.synced_folder( - '.', - '/vagrant', - type: 'rsync', - rsync__exclude: [ - '.git/', - '.vagrant/', - 'log/*', - 'tmp/' - ] - ) + config.vm.box = 'ubuntu/xenial64' config.vm.provision :shell, path: 'config/vagrant/build_dependency_setup.sh' config.vm.provision :shell, path: 'config/vagrant/git_setup.sh' @@ -37,6 +37,29 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provision :shell, path: 'config/vagrant/postgresql_setup.sh' config.vm.provision :shell, path: 'config/vagrant/elixir_setup.sh' config.vm.provision :shell, path: 'config/vagrant/phoenix_setup.sh', privileged: false + config.vm.provision :shell, path: 'config/vagrant/post_install_priveleged.sh' + config.vm.provision :shell, path: 'config/vagrant/post_install_user.sh', privileged: false + config.vm.provision :shell, path: 'config/vagrant/check_versions.sh', privileged: false + + # On Windows there are problems using rsync, which is why I commented out this + # original code. Here the github references for Vagrant 1.8.1 . + # Perhaps a newer version of Vagrant might resolve this issue on Windows. + # https://github.com/mitchellh/vagrant/issues/6702 + # https://github.com/mitchellh/vagrant/issues/3230 + # config.vm.synced_folder( + # '.', + # '/vagrant', + # type: 'rsync', + # rsync__exclude: [ + # '.git/', + # '.vagrant/', + # 'log/*', + # 'tmp/' + # ] + # ) + + # Use the following on Windows to 'resolve' the rsync issue above. + # config.vm.synced_folder ".", "/vagrant" # PostgreSQL Server port forwarding config.vm.network :forwarded_port, host: 4000, guest: 4000 diff --git a/config/vagrant/build_dependency_setup.sh b/config/vagrant/build_dependency_setup.sh index 509776e..ac738c8 100644 --- a/config/vagrant/build_dependency_setup.sh +++ b/config/vagrant/build_dependency_setup.sh @@ -1,9 +1,33 @@ #!/usr/bin/env bash +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" echo "=== Begin Vagrant Provisioning using 'config/vagrant/build_dependency_setup.sh'" +# https://bugs.launchpad.net/ubuntu/+bug/1561250 +if [ $(cat /etc/hosts | grep -co 'ubuntu-xenial') = 0 ]; then + echo "sudo sh -c ""echo '127.0.1.1 ubuntu-xenial' >> /etc/hosts""" + sudo sh -c "echo '127.0.1.1 ubuntu-xenial' >> /etc/hosts" +else + echo "Found entry 'ubuntu-xenial' in the /etc/hosts" +fi + # Install build dependencies for a sane build environment -apt-get -y update -apt-get -y install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev +sudo apt-get -y update +sudo apt-get -y install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev libgtk2.0-0 libgtk2.0-bin libgtk2.0-common + +# Problem installing esl-erlang. +# Standard installation methods for libwxbase fail. +# http://packages.ubuntu.com/search?suite=default§ion=all&arch=any&keywords=libwxbase&searchon=names +# Even after the explicit installation of libwxbase3.0-0v5 the dependencies are not resolved, so +# this forces us to manually install libwxbase3 and libwxgtk3. +wget http://archive.ubuntu.com/ubuntu/pool/universe/w/wxwidgets3.0/libwxbase3.0-0_3.0.2-1_amd64.deb +yes Y | sudo dpkg -i libwxbase3.0-0_3.0.2-1*.deb +yes Y | sudo apt-get -f install + +wget http://archive.ubuntu.com/ubuntu/pool/universe/w/wxwidgets3.0/libwxgtk3.0-0_3.0.2-1_amd64.deb +yes Y | sudo dpkg -i libwxgtk3.0-0_3.0.2-1*.deb +yes Y | sudo apt-get -f install echo "=== End Vagrant Provisioning using 'config/vagrant/build_dependency_setup.sh'" diff --git a/config/vagrant/check_versions.sh b/config/vagrant/check_versions.sh new file mode 100644 index 0000000..d497693 --- /dev/null +++ b/config/vagrant/check_versions.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" +echo "=== Begin Vagrant Provisioning using 'config/vagrant/check_version.sh'" + +echo " " +echo " " +echo "--- git" +echo "--------------------" +echo "git --version" +git --version +echo " " +echo " " +echo "--- node" +echo "--------------------" +echo "node --version" +node --version +echo " " +echo " " +echo "--- postgres" +echo "--------------------" +echo "psql --version" +psql --version +echo " " +echo " " +echo "--- erlang" +echo "--------------------" +echo "cat /usr/lib/erlang/releases/RELEASES" +cat /usr/lib/erlang/releases/RELEASES +echo " " +echo " " +echo "--- elixir" +echo "--------------------" +echo "elixir --version" +elixir --version +echo " " +echo " " +echo "--- phoenix" +echo "--------------------" +echo "mix help phoenix.new" +if [ $(strings ~/.mix/archives/phoenix_new.ez | grep -co '{vsn,') = 0 ]; then + echo "Error: unable to find installed phoenix" +else + mix help phoenix.new | sed -e 3b -e '$!d' + strings ~/.mix/archives/phoenix_new.ez | grep '{vsn,' +fi +echo " " +echo " " + +echo "=== End Vagrant Provisioning using 'config/vagrant/check_version.sh'" diff --git a/config/vagrant/elixir_setup.sh b/config/vagrant/elixir_setup.sh index d921896..6cc5910 100644 --- a/config/vagrant/elixir_setup.sh +++ b/config/vagrant/elixir_setup.sh @@ -1,17 +1,27 @@ #!/usr/bin/env bash +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" echo "=== Begin Vagrant Provisioning using 'config/vagrant/elixir_setup.sh'" -PHOENIX_VERSION=0.17.0 - -# Install Git if not available +# Install elixir if not available +# Note: the URL of erlang will if [ -z `which elixir` ]; then echo "===== Installing Elixir" - wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb - apt-get -y update - apt-get -y install elixir - yes Y | mix local.hex - yes Y | mix archive.install "https://github.com/phoenixframework/phoenix/releases/download/v0.17.0/phoenix_new-$PHOENIX_VERSION.ez" + # https://www.erlang-solutions.com/resources/download.html + # We have to use the more complex alternative erlang install as the + # standard install does not detect the Ubuntu codename correctly. + # Even if you have Ubuntu wily installed, the codename squeezy is + # prompted, and used for the insall, and the installation of erlang fails. + wget http://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc + sudo apt-key add erlang_solutions.asc + # There is as of now no erlang download for xenial, so we have to hard code wily. + sudo add-apt-repository "deb http://packages.erlang-solutions.com/ubuntu wily contrib" + # sudo add-apt-repository "deb http://packages.erlang-solutions.com/ubuntu $(lsb_release -s -c) contrib" + sudo apt-get update + yes Y | sudo apt-get install esl-erlang + sudo apt-get install elixir fi echo "=== End Vagrant Provisioning using 'config/vagrant/elixir_setup.sh'" diff --git a/config/vagrant/git_setup.sh b/config/vagrant/git_setup.sh index 54a8be9..400be19 100644 --- a/config/vagrant/git_setup.sh +++ b/config/vagrant/git_setup.sh @@ -1,12 +1,15 @@ #!/usr/bin/env bash +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" echo "=== Begin Vagrant Provisioning using 'config/vagrant/git_setup.sh'" # Install Git if not available if [ -z `which git` ]; then echo "===== Installing Git" - apt-get -y update - apt-get -y install git-core + sudo apt-get -y update + sudo apt-get -y install git-core fi echo "=== End Vagrant Provisioning using 'config/vagrant/git_setup.sh'" diff --git a/config/vagrant/nodejs_setup.sh b/config/vagrant/nodejs_setup.sh index 884ddf6..86b9861 100644 --- a/config/vagrant/nodejs_setup.sh +++ b/config/vagrant/nodejs_setup.sh @@ -1,11 +1,14 @@ #!/usr/bin/env bash +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" echo "=== Begin Vagrant Provisioning using 'config/vagrant/nodejs_setup.sh'" if [ -z `which nodejs` ]; then # Instructions from: # https://nodesource.com/blog/nodejs-v012-iojs-and-the-nodesource-linux-repositories - curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash - + curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - sudo apt-get install -y nodejs fi diff --git a/config/vagrant/phoenix_setup.sh b/config/vagrant/phoenix_setup.sh index 6477a2f..5d1575e 100644 --- a/config/vagrant/phoenix_setup.sh +++ b/config/vagrant/phoenix_setup.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" echo "=== Begin Vagrant Provisioning using 'config/vagrant/phoenix_setup.sh'" -PHOENIX_VERSION=1.0.0 - -# Install Git if not available -# if [ -z `which elixir` ]; then +# Install the latest version of Phoenix echo "===== Installing Phoenix" - yes Y | mix local.hex - yes Y | mix archive.install "https://github.com/phoenixframework/phoenix/releases/download/v$PHOENIX_VERSION/phoenix_new-$PHOENIX_VERSION.ez" -# fi + mix local.hex --force + mix local.rebar --force + mix archive.install "https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez" --force echo "=== End Vagrant Provisioning using 'config/vagrant/phoenix_setup.sh'" diff --git a/config/vagrant/post_install_priveleged.sh b/config/vagrant/post_install_priveleged.sh new file mode 100644 index 0000000..b6d70de --- /dev/null +++ b/config/vagrant/post_install_priveleged.sh @@ -0,0 +1,13 @@ + +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" +echo "=== Begin Vagrant Provisioning using 'config/vagrant/post_install_priveleged.sh'" + +# Here I can place post install commands to install stuff which I need for +# my project. This file is specifically for code that must be +# executed as the super-user. + +sudo npm install -g elm + +echo "=== End Vagrant Provisioning using 'config/vagrant/post_install_priveleged.sh'" diff --git a/config/vagrant/post_install_user.sh b/config/vagrant/post_install_user.sh new file mode 100644 index 0000000..e956c81 --- /dev/null +++ b/config/vagrant/post_install_user.sh @@ -0,0 +1,11 @@ + +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" +echo "=== Begin Vagrant Provisioning using 'config/vagrant/post_install_user.sh'" + +# Here I can place post install commands to install stuff which I need for +# my project. + + +echo "=== End Vagrant Provisioning using 'config/vagrant/post_install_user.sh'" diff --git a/config/vagrant/postgresql_setup.sh b/config/vagrant/postgresql_setup.sh index 472dea1..5ebaa96 100755 --- a/config/vagrant/postgresql_setup.sh +++ b/config/vagrant/postgresql_setup.sh @@ -1,5 +1,8 @@ #!/bin/sh -e +echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" +echo "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" +echo "======================================================================" echo "=== Begin Vagrant Provisioning using 'config/vagrant/postgresql_setup.sh'" # Edit the following to change the name of the database user that will be created: @@ -10,7 +13,7 @@ APP_DB_PASS=$APP_DB_USER # APP_DB_NAME=${APP_DB_USER}_unused # Edit the following to change the version of PostgreSQL that is installed -PG_VERSION=9.4 +PG_VERSION=9.5 ########################################################### # Changes below this line are probably not necessary @@ -55,18 +58,18 @@ PG_REPO_APT_SOURCE=/etc/apt/sources.list.d/pgdg.list if [ ! -f "$PG_REPO_APT_SOURCE" ] then # Add PG apt repo: - echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > "$PG_REPO_APT_SOURCE" + echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" > "$PG_REPO_APT_SOURCE" # Add PGDG repo key: - wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add - + wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add - fi # Update package list and upgrade all packages -apt-get update -apt-get -y upgrade +sudo apt-get update +sudo apt-get -y upgrade -apt-get -y install "postgresql-$PG_VERSION" "postgresql-contrib-$PG_VERSION" -apt-get -y install libpq-dev # For building ruby 'pg' gem +sudo apt-get -y install "postgresql-$PG_VERSION" "postgresql-contrib-$PG_VERSION" +sudo apt-get -y install libpq-dev # For building ruby 'pg' gem PG_CONF="/etc/postgresql/$PG_VERSION/main/postgresql.conf" PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf"