Created
January 3, 2016 14:35
-
-
Save Blizzke/0bc3ec65d9a7c058d99d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
HOSTNAME = "irrelevant.dev" # VM/nginx hostname | |
IP = "172.16.190.10" # One of the IPs of your host only virtualbox network | |
SSHPORT = 12222 # Set to a custom port, not taken on your machine | |
Vagrant.configure(2) do |config| | |
config.vm.box = "internal-dvp" | |
config.vm.box_url = "http://internal.url/base.box" | |
config.vm.hostname = HOSTNAME | |
config.ssh.port = SSHPORT | |
# Change the SSH port to what is configured | |
config.vm.network :forwarded_port, :guest => 22, :host => SSHPORT, :id => "ssh-custom" | |
config.vm.network :forwarded_port, :guest => 22, :host => 2222, :id => "ssh", :disabled => "true" | |
# Define and use a host-only network. Leave the adapter part, otherwise it tries to reconfigure the primary one and hangs! | |
config.vm.network "private_network", :ip => IP, :adapter => 2 | |
config.vm.provider "virtualbox" do |vb| | |
# Uncomment to show the VM "display" | |
# vb.gui = true | |
# http://stackoverflow.com/questions/20194128/vagrant-crashes-depending-on-physical-network | |
# vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] | |
# vb.customize ["modifyvm", :id, "--natnet1", PRIVATE_RANGE] | |
vb.customize ['modifyvm', :id, '--memory', "512"] | |
vb.customize ['modifyvm', :id, '--cpus', "1"] | |
vb.customize ['modifyvm', :id, '--name', config.vm.hostname] | |
end | |
# 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" | |
# one time scripts (root) | |
config.vm.provision :shell, :path => "vagrant/do-composer.sh" | |
# Pass on the hostname so it can be added in the nginx config (root) | |
config.vm.provision "shell" do |s| | |
s.path = "vagrant/www-setup.sh" | |
s.args = [HOSTNAME] | |
end | |
# Store the github client access token so that we don't have to log in separately and then init the configuration | |
$script = <<SCRIPT | |
echo Configuring github authentication... | |
/usr/local/bin/composer config -g github-oauth.github.com <token> | |
echo Setting up environment... | |
cd /vagrant | |
SCRIPT | |
config.vm.provision "shell", :inline => $script, :privileged => false | |
config.vm.provision :shell, :path => "vagrant/www-composer-update.sh", :privileged => false | |
# needs to go as last because it requires a configured yii | |
config.vm.provision :shell, :path => "vagrant/sap-setup-db.sh" | |
end |
sap-setup-db.sh
#!/bin/bash
if [ ! -f ~/.my.cnf ]; then
echo "mysql: Creating personal settings file"
echo [client] >> ~/.my.cnf
echo password=root >> ~/.my.cnf
fi
DB=databasename
echo "mysql: verifying if $DB exists"
EXISTS=`mysql --batch --skip-column-names -e "SHOW DATABASES LIKE '$DB'" | grep $DB`
if [[ "$EXISTS" != "$DB" ]]; then
echo "mysql: $DB not found, creating"
mysql --batch --skip-column-names -e "CREATE DATABASE $DB CHARACTER SET utf8 COLLATE utf8_general_ci"
# DB created, start migration
cd /vagrant
/usr/bin/php yii migrate --interactive=0
/usr/bin/php yii migrate --interactive=0 --migrationPath=vendor/bedezign/yii2-audit/src/migrations
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
www-composer-update.sh