Skip to content

Commit

Permalink
[vagrant] implemented 2 independent vagrant vms
Browse files Browse the repository at this point in the history
* one for developing the frontend
** fixed output of provisioner script (RAILS_ENV=development was missing)
* one for testing deploment and appliance
* added code to make Vagrantfile more usable with vagrant-libvirt
  • Loading branch information
M0ses committed Nov 25, 2015
1 parent 55a9e7f commit 60deb31
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ We are using [Vagrant](https://www.vagrantup.com/) to create our development env

```
vagrant plugin install vagrant-exec
vagrant plugin install vagrant-reload
# optional if you are running vagrant with libvirt (e.g. kvm)
vagrant plugin install vagrant-libvirt
```

3. Clone this code repository:
Expand Down
44 changes: 35 additions & 9 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,32 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# please see the online documentation at vagrantup.com.

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = 'webhippie/opensuse-13.2'
config.vm.define "frontend" , primary: true do |fe|
fe.vm.box = 'webhippie/opensuse-13.2'
# Provision the box with a simple shell script
fe.vm.provision :shell, path: 'bootstrap.sh'
fe.vm.provision :shell, inline: 'mount /vagrant/src/api/tmp', run: "always"

# Execute commands in the frontend directory
fe.exec.commands '*', directory: '/vagrant/src/api'
fe.exec.commands '*', env: {'DATABASE_URL' => 'mysql2://root:opensuse@localhost/api_development'}
fe.vm.network :forwarded_port, guest: 3000, host: 3000
end


config.vm.define "appliance" , primary: true do |app|
app.vm.box = 'webhippie/opensuse-13.2'
# app.exec.commands '*', env: {'RAILS_ENV' => 'production'}
# app.exec.commands '*', env: {'DATABASE_URL' => 'mysql2://root:opensuse@localhost/api_development'}
# Provision the box with a simple shell script
app.vm.provision :shell, path: 'bootstrap-appliance.sh'

# reboot vm to run obsapisetup
app.vm.provision :reload


app.vm.provision :shell, path: 'bootstrap-appliance-finalize.sh'
end

# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
Expand All @@ -19,7 +44,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# 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.
config.vm.network :forwarded_port, guest: 3000, host: 3000

config.vm.define "appliance", autostart: false

# Create a private network, which allows host-only access to the machine
# using a specific IP.
Expand All @@ -46,11 +72,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vb.destroy_unused_network_interfaces = true
end

# Provision the box with a simple shell script
config.vm.provision :shell, path: 'bootstrap.sh'
config.vm.provision :shell, inline: 'mount /vagrant/src/api/tmp', run: "always"

# Execute commands in the frontend directory
config.exec.commands '*', directory: '/vagrant/src/api'
config.exec.commands '*', env: {'DATABASE_URL' => 'mysql2://root:opensuse@localhost/api_development'}
config.vm.provider :libvirt do |lv|
lv.memory = 2048
# Still having permissions problems with synced_folder 9p but keeping this
# for documentation purpose
# config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false
end

end
10 changes: 10 additions & 0 deletions bootstrap-appliance-finalize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

echo "Waiting 60 sec to give obsapisetup chance to finish"
sleep 60
make -C /vagrant/dist t ts
echo -en "\n\n\n"
echo -en "\n\n\n"
echo -en "Visit this URL to login https://"$(ip route show|grep "scope link"|perl -p -e 's/.* src ([0-9\.]+)/$1/')
echo -en "\n\n\n"
echo "!!!!!!!! Finished Installation !!!!!!!"
127 changes: 127 additions & 0 deletions bootstrap-appliance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/bash

MYSQL_USER=root
MYSQL_PASSWD=opensuse

function prepare_apache2 {

echo -e "\nPreparing apache setup\n"

PACKAGES="apache2 apache2-mod_xforward rubygem-passenger-apache2 memcached"
PKG2INST=""
for pkg in $PACKAGES;do
rpm -q $pkg >/dev/null || PKG2INST="$PKG2INST $pkg"
done

if [[ -n $PKG2INST ]];then
zypper --non-interactive install $PKG2INST >/dev/null
fi

MODULES="passenger rewrite proxy proxy_http xforward headers socache_shmcb"

for mod in $MODULES;do
a2enmod -q $mod || a2enmod $mod
done

FLAGS=SSL

for flag in $FLAGS;do
a2enflag $flag >/dev/null
done

}

echo -e "\nPreparing additional services"
echo 'solver.allowVendorChange = true' >> /etc/zypp/zypp.conf

for repo in \
http://download.opensuse.org/repositories/devel:/languages:/perl/openSUSE_13.2/devel:languages:perl.repo \
http://download.opensuse.org/repositories/OBS:/Server:/Unstable/openSUSE_13.2/OBS:Server:Unstable.repo
do
zypper -q ar -f $repo
done


echo -e "\ninstalling required software packages...\n"
zypper -q --gpg-auto-import-keys refresh
zypper -q -n install update-alternatives ruby-devel make gcc gcc-c++ patch cyrus-sasl-devel openldap2-devel libmysqld-devel libxml2-devel zlib-devel libxslt-devel nodejs mariadb memcached sphinx screen sphinx obs-server phantomjs mysql apache2

echo -e "\nsetup ruby binaries...\n"
for bin in rake rdoc ri; do
/usr/sbin/update-alternatives --set $bin /usr/bin/$bin.ruby.ruby2.2
done

echo -e "\ndisabling versioned gem binary names...\n"
echo 'install: --no-format-executable' >> /etc/gemrc

echo -e "\ninstalling bundler...\n"
gem install bundler

echo -e "\ninstalling your bundle...\n"
su - vagrant -c "cd /vagrant/src/api/; bundle install --quiet"

[ -d /srv/www/obs/api/config/ ] || mkdir -p /srv/www/obs/api/config/
cp /vagrant/src/api/config/database.yml.example /srv/www/obs/api/config/database.yml
cp /vagrant/src/api/config/options.yml.example /srv/www/obs/api/config/options.yml

echo -e "\nChanging mysql password and settings\n"

systemctl start mysql.service
mysqladmin -u $MYSQL_USER password "$MYSQL_PASSWD"
cat <<EOF >/root/.my.cnf
[client]
password=$MYSQL_PASSWD
user=$MYSQL_USER
[mysqladmin]
password=$MYSQL_PASSWD
user=$MYSQL_USER
EOF


echo -e "\nInstalling backend components\n"
cp -a /vagrant/src/backend /usr/lib/obs/server

echo -e "\nEnabling backend services\n"
for srv in obsapidelayed obsapisetup obsdispatcher obspublisher obsrepserver obsscheduler obssrcserver;do
cp /vagrant/dist/$srv /etc/init.d
systemctl enable $srv.service
done

for dir in /srv/obs /srv/www/obs /srv/www/obs/overview/ /usr/lib/obs /srv/www/obs/api/log/ /srv/www/obs/api/tmp;do
[ -d $dir ] || mkdir -p $dir
done

for srv in apache2 mysql memcached;do
systemctl enable $srv.service
done

echo -e "\nInstalling api components\n"
cp -a /vagrant/src/api /srv/www/obs
cp -a /vagrant/dist/obs-apache24.conf /etc/apache2/vhosts.d/obs.conf
cp /vagrant/dist/overview.html.TEMPLATE /srv/www/obs/overview/
cd /srv/www/obs/api/
echo "" | sha256sum|awk '{print $1}' > config/secret.key
chown wwwrun:www -R /srv/www/obs/api/log/
chown wwwrun:www -R /srv/www/obs/api/tmp

echo -e "\nInstalling obsapisetup components\n"
make -C /vagrant/dist install

echo -e "\nConfiguring BS_API_AUTOSETUP\n"
perl -p -i -e 's#BS_API_AUTOSETUP=.*#BS_API_AUTOSETUP="yes"#' /etc/sysconfig/obs-server

prepare_apache2

cd /srv/www/obs/api

bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets 2>/dev/null

touch /srv/www/obs/api/config/production.sphinx.conf
chown wwwrun:www /srv/www/obs/api/config/production.sphinx.conf


exit 0

20 changes: 11 additions & 9 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ echo -e "\nsetting up memcached...\n"
systemctl start memcached
systemctl enable memcached

# Configure the app if it isn't
if [ ! -f /vagrant/src/api/config/options.yml ] && [ -f /vagrant/src/api/config/options.yml.example ]; then
echo "Configuring your app in config/options.yml..."
sed 's/source_port: 5352/source_port: 3200/' /vagrant/src/api/config/options.yml.example > /vagrant/src/api/config/options.yml
else
echo -e "\n\nWARNING: You have already configured your app in config/options.yml."
echo -e "WARNING: Please make sure this configuration works in this vagrant box!\n\n"
fi

# Configure the database if it isn't
if [ ! -f /vagrant/src/api/config/database.yml ] && [ -f /vagrant/src/api/config/database.yml.example ]; then
echo -e "\nSetting up your database from config/database.yml...\n"
Expand All @@ -43,22 +52,15 @@ else
echo -e "WARNING: Please make sure this configuration works in this vagrant box!\n\n"
fi

# Configure the app if it isn't
if [ ! -f /vagrant/src/api/config/options.yml ] && [ -f /vagrant/src/api/config/options.yml.example ]; then
echo "Configuring your app in config/options.yml..."
sed 's/source_port: 5352/source_port: 3200/' /vagrant/src/api/config/options.yml.example > /vagrant/src/api/config/options.yml
else
echo -e "\n\nWARNING: You have already configured your app in config/options.yml."
echo -e "WARNING: Please make sure this configuration works in this vagrant box!\n\n"
fi

echo "Setting up your OBS test backend..."
# Put the backend data dir outside the shared folder so it can use hardlinks
# which isn't possible with VirtualBox shared folders...
mkdir /tmp/vagrant_tmp
chown vagrant:users /tmp/vagrant_tmp
chown vagrant:users -R /vagrant/src/api/log/*
echo -e "/tmp/vagrant_tmp /vagrant/src/api/tmp none bind 0 0" >> /etc/fstab

echo -e "\nProvisioning of your OBS API rails app done!"
echo -e "To start your development OBS backend run: vagrant exec ./script/start_test_backend\n"
echo -e "To start your development OBS backend run: vagrant exec RAILS_ENV=development ./script/start_test_backend\n"
echo -e "To start your development OBS frontend run: vagrant exec rails s\n"

0 comments on commit 60deb31

Please sign in to comment.