Skip to content

Instantly share code, notes, and snippets.

@geggo98
Last active March 1, 2016 14:40
Show Gist options
  • Save geggo98/f2bb034c4734fd92ac88 to your computer and use it in GitHub Desktop.
Save geggo98/f2bb034c4734fd92ac88 to your computer and use it in GitHub Desktop.
Vagrantfile for multi machien setup with Sencha ExtJS, MySQL 5.7 and sbt
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "boxcutter/ubuntu1404"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network "private_network", type: "dhcp"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
#vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "512"
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
config.vm.provision "apt", type: "shell", privileged: false, inline: <<-SHELL
echo Initialize package cache with the newest version on the internet
export DEBIAN_FRONTEND=noninteractive
sudo perl -pi -e '$_ = "# $_"' /etc/apt/sources.list
echo "deb mirror://mirrors.ubuntu.com/mirrors.txt $(lsb_release -c -s) main restricted universe multiverse" | sudo tee --append /etc/apt/sources.list
echo "deb mirror://mirrors.ubuntu.com/mirrors.txt $(lsb_release -c -s)-updates main restricted universe multiverse" | sudo tee --append /etc/apt/sources.list
echo "deb mirror://mirrors.ubuntu.com/mirrors.txt $(lsb_release -c -s)-security main restricted universe multiverse" | sudo tee --append /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y software-properties-common debconf-utils
SHELL
config.vm.provision "mdns", type: "shell", privileged: false, inline: <<-SHELL
sudo env DEBIAN_FRONTEND=noninteractive apt-get -y install avahi-daemon libnss-mdns avahi-utils
SHELL
config.vm.define "web" do |web|
web.vm.network "forwarded_port", guest: 1841, host: 1841, auto_correct: true
web.vm.hostname = "web"
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
web.vm.provision "sencha", type: "shell", privileged: false, inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
echo Install software required by the Sencha SDK
sudo apt-get -y install vim default-jre default-jdk ruby
sudo apt-get -y install unp unrar unrar-free xdms p7zip p7zip-full unzip cabextract
echo Installing the Sencha Cmd tool
curl --silent --show-error -O http://cdn.sencha.com/cmd/6.0.2/no-jre/SenchaCmd-6.0.2-linux-amd64.sh.zip
unp -u SenchaCmd-6.0.2-linux-amd64.sh.zip
./SenchaCmd-6.0.2-linux-amd64.sh/SenchaCmd-6.0.2.14-linux-amd64.sh -q
source ~/.profile
rm -r SenchaCmd-6.0.2-linux-amd64.sh
echo Installing the Ext JS SDK version 6
curl --silent --show-error -O http://cdn.sencha.com/ext/gpl/ext-6.0.0-gpl.zip
unp ext-6.0.0-gpl.zip > /dev/null && echo OK
rm ext-6.0.0-gpl.zip
echo Installation succesful.
echo Build project for the first time
cd /vagrant/WebClient
test -f build.xml && sencha app upgrade ~/ext-6.0.0/ && sencha app build devel || true
echo Getting started: https://docs.sencha.com/extjs/6.0/getting_started/getting_started.html
echo Done.
SHELL
end
config.vm.define "db" do |db|
db.vm.network "forwarded_port", guest: 3306, host: 3306
db.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
db.vm.hostname = "db"
db.vm.provision "mysql", type: "shell", privileged: false, inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
echo Install MySql config...
#sudo apt-get install -y wget curl
#wget -nv https://dev.mysql.com/get/mysql-apt-config_0.6.0-1_all.deb
echo mysql-apt-config mysql-apt-config/enable-repo select mysql-5.7 | sudo debconf-set-selections
echo mysql-apt-config mysql-apt-config/select-tools select | sudo debconf-set-selections
echo mysql-apt-config mysql-apt-config/repo-codename select $(lsb_release -c -s) | sudo debconf-set-selections
echo mysql-apt-config mysql-apt-config/select-product select Apply | sudo debconf-set-selections
#sudo dpkg -i mysql-apt-config_0.6.0-1_all.deb
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 5072E1F5
echo deb http://repo.mysql.com/apt/ubuntu/ $(lsb_release -c -s) mysql-5.7 | sudo tee /etc/apt/sources.list.d/mysql.list
echo Install MySql server...
sudo apt-get update
echo mysql-community-server mysql-community-server/root-pass password | sudo debconf-set-selections
echo mysql-community-server mysql-community-server/re-root-pass password | sudo debconf-set-selections
echo mysql-community-server mysql-community-server/remove-data-dir boolean false | sudo debconf-set-selections
echo mysql-community-server mysql-community-server/data-dir note | sudo debconf-set-selections
echo "mysql-server-5.7 mysql-server/root_password password " | sudo debconf-set-selections
echo "mysql-server-5.7 mysql-server/root_password_again password " | sudo debconf-set-selections
sudo apt-get install -y mysql-server-5.7
sudo mysql --force <<-EOF
create user if not exists vagrant@localhost identified by '';
grant all privileges on *.* to vagrant@localhost with grant option;
create user if not exists root@'%' identified by 'root';
grant all privileges on *.* to root@'%' with grant option;
create user if not exists flyway@'%' identified by 'flyway';
grant all privileges on *.* to flyway@'%' with grant option;
flush privileges;
EOF
(echo [mysqld]; echo bind-address = ::) | sudo tee /etc/mysql/conf.d/bind-to-all.cnf
sudo service mysql restart
SHELL
db.vm.provision "adminer", type: "shell", privileged: false, inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
echo 'Install admin GUI (adminer)'
sudo apt-get install -y lighttpd php5-cgi php5-mysqlnd
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
sudo service lighttpd force-reload
sudo mkdir -p /var/www/plugins
cd /var/www
sudo curl --silent --show-error -o adminer.php https://www.adminer.org/static/download/4.2.4/adminer-4.2.4.php
sudo curl --silent --show-error -o editor.php https://www.adminer.org/static/download/4.2.4/editor-4.2.4.php
sudo tee index.html <<-EOF
<html>
<head>
<title>MySQL Admin</title>
</head><body>
<ul>
<li><a href="/adminer.php?username=vagrant&db=production">Adminer database admin tool (without plugins)</a></li>
<li><a href="/editor.php?username=vagrant&db=production">Table editor</a></li>
</ul>
</body>
</html>
EOF
echo Done
SHELL
db.vm.provision "flyway", type: "shell", privileged: false, inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
echo Intall flyway database migration
sudo apt-get install -y unp
echo Download Flyway
wget --quiet https://bintray.com/artifact/download/business/maven/flyway-commandline-3.2.1-linux-x64.tar.gz
echo Installing Flyway
sudo mkdir -p /opt
sudo rm -r /opt/flyway* || true
cd /opt
sudo unp ~/flyway-commandline*.tar.gz
for i in /opt/flyway*
do
sudo chmod a+x ${i}/flyway
pushd .
cd ${i}
sudo perl -pi.bak -e 's/(.*JAVA.*) (-cp.*)/$1 -Xms512m -Xmx1536m $2/g' flyway
cd ${i}/conf
sudo mv flyway.conf flyway.conf.orig
sudo ln -s /vagrant/DbServer/flyway.conf flyway.conf
popd
echo 'export PATH=$PATH:'${i} | sudo tee --append /etc/profile.d/flyway.sh
done
source /etc/profile.d/flyway.sh
echo Migrate database
cd /vagrant/DbServer/production
flyway clean
flyway migrate
flyway validate
flyway info
SHELL
end
config.vm.define "app" do |app|
app.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
app.vm.hostname = "app"
app.vm.provision "sbt", type: "shell", privileged: false, inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
echo Install Java...
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 boolean true | sudo debconf-set-selections
sudo apt-get -y install oracle-java8-installer
echo Intall sbt build tool
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
sudo apt-get update
sudo apt-get -y install sbt
echo Compile for the first time...
cd /vagrant
test -f build.sbt && sbt compile || true
SHELL
app.vm.provision "HTTPie", type: "shell", privileged: false, inline: <<-SHELL
export DEBIAN_FRONTEND=noninteractive
echo 'Install newest version of HTTPie (https://github.com/jkbrzt/httpie)'
sudo apt-get install -y python-pip
sudo pip install --upgrade pip setuptools
sudo pip install --upgrade httpie
echo Done
SHELL
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment