From f3549a21d923bdaabbb649866755139f7285a7c3 Mon Sep 17 00:00:00 2001 From: Christian Bruckmayer Date: Mon, 7 Dec 2015 11:40:27 +0100 Subject: [PATCH] Setup vagrant file for development --- .gitignore | 1 + INSTALL.md | 63 +++++++++++++++++++++------------------------ Vagrantfile | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bootstrap.sh | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 34 deletions(-) create mode 100644 Vagrantfile create mode 100644 bootstrap.sh diff --git a/.gitignore b/.gitignore index b4c82f7a..ea3e8de3 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ pickle-email-*.html /bundle /doc/app .ruby-version +.vagrant/ diff --git a/INSTALL.md b/INSTALL.md index 79d46f75..7ef120ac 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -3,54 +3,49 @@ You can run rails apps in different modes (development, production). For more in about rails and what it can do, see the [rails guides.](http://guides.rubyonrails.org/getting_started.html) ### Run OSEM in development -1. Clone the git repository to the directory you want Apache to serve the content from. +We are using [Vagrant](https://www.vagrantup.com/) to create our development environments. - ``` - git clone https://github.com/openSUSE/osem.git - ``` +1. Install [Vagrant](https://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads). Both tools support Linux, MacOS and Windows. -2. Install all the ruby gems. +2. Install [vagrant-exec](https://github.com/p0deje/vagrant-exec): - ``` - bundle install - ``` + ``` + vagrant plugin install vagrant-exec + vagrant plugin install vagrant-reload + ``` -3. Install [ImageMagick](http://imagemagick.org/script/binary-releases.php) +3. Clone this code repository: -4. Generate secret key for devise and the rails app with + ``` + git clone https://github.com/openSUSE/osem.git + ``` - ``` - rake secret - ``` +4. Execute Vagrant: -5. Copy the sample configuration files and adapt them + ``` + vagrant up + ``` - ``` - cp config/config.yml.example config/config.yml - cp config/database.yml.example config/database.yml - cp config/secrets.yml.example config/secrets.yml - ``` +7. Start your OSEM rails app: -6. Setup the database + ``` + vagrant exec rails s + ``` - ``` - bundle exec rake db:setup - ``` +8. Check out your OSEM rails app: +You can access the app [localhost:3000](http://localhost:3000). Whatever you change in your cloned repository will have effect in the development environment. Sign up, the first user will be automatically assigned the admin role. -7. Run OSEM +9. Changed something? Test your changes!: - ``` - rails server - ``` + ``` + vagrant exec rake test + ``` -8. Visit the APP at +10. Explore the development environment: - ``` - http://localhost:3000 - ``` -9. Sign up, the first user will be automatically assigned the admin role. - -10. Hack! + ``` + vagrant ssh + ``` ### Run OSEM in production We recommend to run OSEM in production with [mod_passenger](https://www.phusionpassenger.com/download/#open_source) diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..45c04c4c --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,72 @@ +# -*- 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 = "webhippie/opensuse-13.2" + + # 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. + config.vm.network "forwarded_port", guest: 3000, host: 3000 + + # 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" + + # 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 = "1024" + # 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 + + # 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. + config.vm.provision :shell, path: "bootstrap.sh" + # config.vm.provision "shell", inline: <<-SHELL + # sudo apt-get update + # sudo apt-get install -y apache2 + # SHELL +end diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100644 index 00000000..06ff0b19 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,45 @@ +#!/bin/bash +echo -e "\ninstalling required software packages...\n" +zypper -q -n install update-alternatives ruby-devel make gcc gcc-c++ libxml2-devel libxslt-devel nodejs screen mariadb libmysqld-devel sqlite3-devel imagemagick + +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/; bundle install --quiet" + +# Configure the app if it isn't +if [ ! -f /vagrant/config/options.yml ] && [ -f /vagrant/config/options.yml.example ]; then + echo "Configuring your app in config/options.yml..." + cp config/config.yml.example config/config.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 app if it isn't +if [ ! -f /vagrant/config/secrets.yml ] && [ -f /vagrant/config/secrets.yml.example ]; then + echo "Configuring your app in config/secrets.yml..." + echo -e "\n\nWARNING: The keys in the generated secrets.yml are NOT secure!" + echo -e "\n\nWARNING: Please generate new secret keys with 'rake secret' and copy them to the secrets.yml if you run this app in production." + cp config/secrets.yml.example config/secrets.yml +else + echo -e "\n\nWARNING: You have already configured your app in config/secrets.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/config/database.yml ] && [ -f /vagrant/config/database.yml.example ]; then + echo -e "\nSetting up your database from config/database.yml...\n" + cp config/database.yml.example config/database.yml + bundle exec rake db:setup +else + echo -e "\nnWARNING: You have already configured your database in config/database.yml." + echo -e "WARNING: Please make sure this configuration works in this vagrant box!\n\n" +fi + +echo -e "\nProvisioning of your OSEM rails app done!" +echo -e "To start your development OSEM run: vagrant exec rails s\n" \ No newline at end of file