mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
Merge pull request #101 from MakerNetwork/feature/vagrant-virtual-environment
Feature/vagrant virtual environment
This commit is contained in:
commit
a077263035
@ -1 +1 @@
|
||||
ruby-2.3.0
|
||||
ruby-2.3.6
|
||||
|
83
README.md
83
README.md
@ -10,6 +10,7 @@ FabManager is the FabLab management solution. It is web-based, open-source and t
|
||||
4. [Setup a development environment](#setup-a-development-environment)<br/>
|
||||
4.1. [General Guidelines](#general-guidelines)<br/>
|
||||
4.2. [Environment Configuration](#environment-configuration)
|
||||
4.3. [Virtual Machine Instructions](#virtual-machine-instructions)<br/>
|
||||
5. [PostgreSQL](#postgresql)<br/>
|
||||
5.1. [Install PostgreSQL 9.4 on Ubuntu/Debian](#postgresql-on-debian)<br/>
|
||||
5.2. [Install and launch PostgreSQL on MacOS X](#postgresql-on-macosx)<br/>
|
||||
@ -70,7 +71,7 @@ This procedure is not easy to follow so if you don't need to write some code for
|
||||
|
||||
1. Install RVM with the ruby version specified in the [.ruby-version file](.ruby-version).
|
||||
For more details about the process, Please read the [official RVM documentation](http://rvm.io/rvm/install).
|
||||
If you're using ArchLinux, you may have to [read this](doc/archlinux_readme.md) before.
|
||||
If you're using ArchLinux, you may have to [read this](doc/archlinux_readme.md) before.
|
||||
|
||||
2. Retrieve the project from Git
|
||||
|
||||
@ -290,6 +291,81 @@ See the [Open Projects](#open-projects) section for a detailed description of th
|
||||
See the [Settings](#i18n-settings) section of the [Internationalization (i18n)](#i18n) paragraph for a detailed description of these parameters.
|
||||
|
||||
|
||||
<a name="virtual-machine-instructions"></a>
|
||||
### Virtual Machine Instructtions
|
||||
|
||||
These instructions allow to deploy a testing or development instance of Fab Manager inside a virtual
|
||||
machine, with most of the software dependencies installed automatically and avoiding to install a lot
|
||||
of software and services directly on the host computer.
|
||||
|
||||
**Note:** The provision scripts configure the sofware dependencies to play nice with each other while
|
||||
they are inside the same virtual environment but said configuration is not optimized for a production
|
||||
environment.
|
||||
|
||||
1. Install [Vagrant][vagrant] and [Virtual Box][virtualbox] (with the extension package).
|
||||
|
||||
2. Retrieve the project from Git
|
||||
|
||||
```bash
|
||||
git clone https://github.com/LaCasemate/fab-manager
|
||||
```
|
||||
|
||||
3. From the project directory, run:
|
||||
|
||||
```bash
|
||||
vagrant up
|
||||
```
|
||||
|
||||
4. Once the virtual machine finished building, reload it with:
|
||||
|
||||
```bash
|
||||
vagrant reload
|
||||
```
|
||||
|
||||
5. Log into the virtual machine with:
|
||||
|
||||
```bash
|
||||
vagrant ssh
|
||||
```
|
||||
|
||||
6. While logged in, navigate to the project folder and install the Gemfile
|
||||
dependencies:
|
||||
|
||||
```bash
|
||||
cd /vagrant
|
||||
bundle install
|
||||
```
|
||||
|
||||
7. Set a directory for Sidekick pids:
|
||||
|
||||
```bash
|
||||
mkdir -p tmp/pids
|
||||
```
|
||||
|
||||
8. Copy the default configuration files:
|
||||
|
||||
```bash
|
||||
cp config/database.yml.virtual config/database.yml
|
||||
cp config/application.yml.default config/application.yml
|
||||
```
|
||||
|
||||
10. Set up the databases. (Note that you should provide the desired admin credentials and that these
|
||||
specific set of commands must be used to set up the database as some raw SQL instructions are
|
||||
included in the migrations):
|
||||
|
||||
```bash
|
||||
rake db:create
|
||||
rake db:migrate
|
||||
ADMIN_EMAIL='youradminemail' ADMIN_PASSWORD='youradminpassword' rake db:seed
|
||||
rake fablab:es_build_stats
|
||||
```
|
||||
|
||||
11. Start the application and visit `localhost:3000` on your browser to check that it works:
|
||||
|
||||
```bash
|
||||
foreman s -p 3000
|
||||
```
|
||||
|
||||
<a name="postgresql"></a>
|
||||
## PostgreSQL
|
||||
|
||||
@ -734,3 +810,8 @@ Developers may find information on how to implement their own authentication pro
|
||||
- [AngularJS](https://docs.angularjs.org/api)
|
||||
- [Angular-Bootstrap](http://angular-ui.github.io/bootstrap/)
|
||||
- [ElasticSearch 1.7](https://www.elastic.co/guide/en/elasticsearch/reference/1.7/index.html)
|
||||
|
||||
|
||||
---
|
||||
[vagrant]: https://www.vagrantup.com/downloads.html
|
||||
[virtualbox]: https://www.virtualbox.org/wiki/Downloads
|
||||
|
96
Vagrantfile
vendored
96
Vagrantfile
vendored
@ -1,73 +1,41 @@
|
||||
# -*- 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.
|
||||
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
||||
VAGRANTFILE_API_VERSION = '2'
|
||||
|
||||
# Every Vagrant development environment requires a box. You can search for
|
||||
# boxes at https://atlas.hashicorp.com/search.
|
||||
config.vm.box = "ubuntu/trusty64"
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
config.vm.box = 'ubuntu/xenial64'
|
||||
config.vm.define 'fabmanager-devbox'
|
||||
|
||||
# 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 # rails/puma
|
||||
config.vm.network "forwarded_port", guest: 9200, host: 9200 # elasticsearch
|
||||
config.vm.network "forwarded_port", guest: 5432, host: 5432 # postgreSQL
|
||||
|
||||
# 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 = 512
|
||||
# Port forwarding
|
||||
[
|
||||
3000, # rails/puma
|
||||
9200, # elasticsearch
|
||||
5432, # postgres
|
||||
1080, # mailcatcher web ui
|
||||
4040 # ngrok web ui
|
||||
].each do |port|
|
||||
config.vm.network "forwarded_port", guest: port, host: port
|
||||
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
|
||||
# Provider-specific configuration
|
||||
config.vm.provider 'virtualbox' do |vb|
|
||||
vb.customize ['modifyvm', :id, '--memory', '2048']
|
||||
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", inline: <<-SHELL
|
||||
# sudo apt-get update
|
||||
# sudo apt-get install -y apache2
|
||||
# SHELL
|
||||
# If you are using Windows o Linux with an encrypted volume
|
||||
config.vm.synced_folder '.', '/vagrant', type: 'virtualbox'
|
||||
|
||||
# Provisioning
|
||||
config.vm.provision "shell", privileged: true, run: "once" do |s|
|
||||
s.inline = "export LC_ALL=en_US.UTF-8\n" \
|
||||
"export LANG=en_US.UTF-8\n" \
|
||||
"export LANGUAGE=en_US.UTF-8"
|
||||
end
|
||||
|
||||
config.vm.provision "shell", privileged: false, run: "once",
|
||||
path: "provision/zsh_setup.sh"
|
||||
config.vm.provision "shell", privileged: false, run: "once",
|
||||
path: "provision/box_setup.zsh"
|
||||
end
|
||||
|
28
config/database.yml.virtual
Normal file
28
config/database.yml.virtual
Normal file
@ -0,0 +1,28 @@
|
||||
development: &development
|
||||
adapter: postgresql
|
||||
host: localhost
|
||||
encoding: unicode
|
||||
database: fabmanager_development
|
||||
pool: 25
|
||||
username: ubuntu
|
||||
password: ubuntu
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
<<: *development
|
||||
database: fabmanager_test
|
||||
|
||||
production: &production
|
||||
adapter: postgresql
|
||||
host: ENV['DATABASE_HOST']
|
||||
encoding: unicode
|
||||
database: fabmanager_production
|
||||
pool: 25
|
||||
username: ENV['DATABASE_USER']
|
||||
password: ENV['DATABASE_PASS']
|
||||
|
||||
staging:
|
||||
<<: *production
|
||||
database: fabmanager_staging
|
@ -25,7 +25,8 @@ Rails.application.configure do
|
||||
# Debug mode disables concatenation and preprocessing of assets.
|
||||
# This option may cause significant delays in view rendering with a large
|
||||
# number of complex assets.
|
||||
config.assets.debug = true
|
||||
# Set to false when running with Vagrant to speed up response time.
|
||||
config.assets.debug = ENV['VIRTUAL_DEV_ENV'] ? false : true
|
||||
|
||||
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
|
||||
# yet still be able to expire them through the digest params.
|
||||
|
187
provision/box_setup.zsh
Executable file
187
provision/box_setup.zsh
Executable file
@ -0,0 +1,187 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Set environmen values #######################################################
|
||||
|
||||
# Virtual environment flag
|
||||
echo '# Set virtual environment flag' >> ~/.profile
|
||||
echo 'export VIRTUAL_DEV_ENV=true' >> ~/.profile
|
||||
echo "\n" >> ~/.profile
|
||||
|
||||
# Language configuration
|
||||
echo '# Set locale configuration' >> ~/.profile
|
||||
echo 'export LC_ALL=en_US.UTF-8' >> ~/.profile
|
||||
echo 'export LANG=en_US.UTF-8' >> ~/.profile
|
||||
echo 'export LANGUAGE=en_US.UTF-8' >> ~/.profile
|
||||
echo "\n" >> ~/.profile
|
||||
|
||||
# Install and setup PostgreSQL ################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo "Checking Postgres installation..."
|
||||
echo "***************************************************"
|
||||
if ! dpkg -s postgresql; then
|
||||
echo "Installing PostgreSQL"
|
||||
sudo apt update
|
||||
sudo apt install -y postgresql postgresql-contrib
|
||||
|
||||
echo "Setting up user"
|
||||
sudo -u postgres bash -c "psql -c \"CREATE USER ubuntu WITH PASSWORD 'ubuntu';\""
|
||||
sudo -u postgres bash -c "psql -c \"ALTER USER ubuntu WITH SUPERUSER;\""
|
||||
|
||||
echo "Setting up extensions to all schemas"
|
||||
sudo -u postgres bash -c "psql -c \"CREATE EXTENSION unaccent SCHEMA pg_catalog;\""
|
||||
sudo -u postgres bash -c "psql -c \"CREATE EXTENSION pg_trgm SCHEMA pg_catalog;\""
|
||||
fi
|
||||
|
||||
echo "***************************************************"
|
||||
echo " Starting Postgres server "
|
||||
echo "***************************************************"
|
||||
sudo service postgresql start
|
||||
|
||||
|
||||
# Install Redis ###############################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo "Checking Redis installation..."
|
||||
echo "***************************************************"
|
||||
if ! dpkg -s redis-server; then
|
||||
echo "Instalating Redis"
|
||||
sudo apt install -y redis-server
|
||||
fi
|
||||
|
||||
|
||||
# Install Imagemagick #########################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo "Checking Imagemagik installation..."
|
||||
echo "***************************************************"
|
||||
if ! dpkg -s imagemagick; then
|
||||
sudo apt install -y imagemagick
|
||||
else
|
||||
echo 'OK'
|
||||
fi
|
||||
|
||||
|
||||
# Install Elastic Search ######################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo "Checking ElasticSearch installation..."
|
||||
echo "***************************************************"
|
||||
if ! dpkg -s elasticsearch; then
|
||||
sudo apt install -y openjdk-8-jre apt-transport-https
|
||||
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
|
||||
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
|
||||
sudo apt update && sudo apt install -y elasticsearch
|
||||
|
||||
# This configuration limits ElasticSearch memory use inside the virtual machine
|
||||
sudo echo "node.master: true" >> /etc/elasticsearch/elasticsearch.yml
|
||||
sudo echo "node.data: false" >> /etc/elasticsearch/elasticsearch.yml
|
||||
sudo sed -i 's/#bootstrap.memory_lock: true/bootstrap.memory_lock: true/g' /etc/elasticsearch/elasticsearch.yml
|
||||
sudo sed -i 's/#ES_JAVA_OPTS=/ES_JAVA_OPTS="-Xms256m -Xmx256m"/g' /etc/default/elasticsearch
|
||||
|
||||
sudo /bin/systemctl daemon-reload
|
||||
sudo /bin/systemctl enable elasticsearch.service
|
||||
else
|
||||
echo 'OK'
|
||||
fi
|
||||
|
||||
|
||||
# Install Ngrok exposer ######################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo "Checking for Ngrok... "
|
||||
echo "***************************************************"
|
||||
if ! ngrok; then
|
||||
sudo apt install -y unzip
|
||||
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
|
||||
sudo unzip ngrok-stable-linux-amd64.zip -d /usr/local/bin
|
||||
rm -rf ngrok-stable-linux-amd64.zip
|
||||
else
|
||||
echo "OK"
|
||||
fi
|
||||
|
||||
|
||||
# Install Node Version Manager ################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo "Checking for NVM... "
|
||||
echo "***************************************************"
|
||||
if [[ ! -x "$HOME/.nvm" ]]; then
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
|
||||
|
||||
echo '# Node Version Manager' >> ~/.profile
|
||||
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.profile
|
||||
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.profile
|
||||
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> ~/.profile
|
||||
echo "\n" >> ~/.profile
|
||||
echo 'autoload -U add-zsh-hook' >> ~/.profile
|
||||
echo 'load-nvmrc() {' >> ~/.profile
|
||||
echo ' local node_version="$(nvm version)"' >> ~/.profile
|
||||
echo ' local nvmrc_path="$(nvm_find_nvmrc)"' >> ~/.profile
|
||||
echo "\n" >> ~/.profile
|
||||
echo ' if [ -n "$nvmrc_path" ]; then' >> ~/.profile
|
||||
echo ' local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")' >> ~/.profile
|
||||
echo "\n" >> ~/.profile
|
||||
echo ' if [ "$nvmrc_node_version" = "N/A" ]; then' >> ~/.profile
|
||||
echo ' nvm install' >> ~/.profile
|
||||
echo ' elif [ "$nvmrc_node_version" != "$node_version" ]; then' >> ~/.profile
|
||||
echo ' nvm use' >> ~/.profile
|
||||
echo ' fi' >> ~/.profile
|
||||
echo ' elif [ "$node_version" != "$(nvm version default)" ]; then' >> ~/.profile
|
||||
echo ' echo "Reverting to nvm default version"' >> ~/.profile
|
||||
echo ' nvm use default' >> ~/.profile
|
||||
echo ' fi' >> ~/.profile
|
||||
echo '}' >> ~/.profile
|
||||
echo 'add-zsh-hook chpwd load-nvmrc' >> ~/.profile
|
||||
echo 'load-nvmrc' >> ~/.profile
|
||||
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
||||
else
|
||||
echo "OK"
|
||||
fi
|
||||
|
||||
|
||||
# Install Node.js #############################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo "Checking for Node.js... "
|
||||
echo "***************************************************"
|
||||
if ! node --version; then
|
||||
nvm install stable
|
||||
nvm alias default stable
|
||||
nvm use default
|
||||
else
|
||||
echo 'OK'
|
||||
fi
|
||||
|
||||
|
||||
# Ruby and Version Manager ####################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo 'Cheking for Ruby... '
|
||||
echo "***************************************************"
|
||||
if ! ruby -v; then
|
||||
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
||||
sudo apt install -y libxml2 libxml2-dev libxslt1-dev libpq-dev
|
||||
\curl -sSL https://get.rvm.io | bash
|
||||
source /home/vagrant/.rvm/scripts/rvm
|
||||
rvm get head
|
||||
rvm install ruby-2.3.6
|
||||
rvm use ruby-2.3.6@global
|
||||
gem update --system --no-ri --no-rdoc
|
||||
gem update --no-ri --no-rdoc
|
||||
rvm use ruby-2.3.6 --default
|
||||
else
|
||||
echo 'OK'
|
||||
fi
|
||||
|
||||
|
||||
# Cleaning up #################################################################
|
||||
|
||||
echo "***************************************************"
|
||||
echo 'Removing unused software... '
|
||||
echo "***************************************************"
|
||||
rvm cleanup all
|
||||
sudo apt autoremove
|
36
provision/zsh_setup.sh
Executable file
36
provision/zsh_setup.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "***************************************************"
|
||||
echo 'Updating system packages... '
|
||||
echo "***************************************************"
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
|
||||
echo "***************************************************"
|
||||
echo 'Checking Zsh installation... '
|
||||
echo "***************************************************"
|
||||
if ! dpkg -s zsh; then
|
||||
# Install and set Zsh as shell
|
||||
sudo apt install -y zsh
|
||||
|
||||
# Install Oh-My-Zsh!
|
||||
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
|
||||
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
|
||||
|
||||
# Change the Oh-My-Zsh! default configuration.
|
||||
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="blinks"/g' ~/.zshrc
|
||||
sed -i 's/# CASE_SENSITIVE="true"/CASE_SENSITIVE="true"/g' ~/.zshrc
|
||||
sed -i 's/# COMPLETION_WAITING_DOTS="true"/COMPLETION_WAITING_DOTS="true"/g' ~/.zshrc
|
||||
sed -i 's/# DISABLE_UNTRACKED_FILES_DIRTY="true"/DISABLE_UNTRACKED_FILES_DIRTY="true"/g' ~/.zshrc
|
||||
sed -i 's/# HIST_STAMPS="mm/dd/yyyy"/HIST_STAMPS="yyyy-mm-dd"/g' ~/.zshrc
|
||||
sed -i 's/plugins=(git)/plugins=(git dirhistory common-aliases command-not-found ruby)/g' ~/.zshrc
|
||||
|
||||
# Include .profile settings
|
||||
echo ' ' >> ~/.zshrc
|
||||
echo '# Include .profile settings' >> ~/.zshrc
|
||||
echo 'source ~/.profile' >> ~/.zshrc
|
||||
echo ' ' >> ~/.zshrc
|
||||
|
||||
# Change shell to Zsh for the vagrant user
|
||||
sudo chsh -s /bin/zsh vagrant
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user