mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
Merge branch 'sca' of github.com:sleede/fab-manager into sca
This commit is contained in:
commit
7ef3cf65c8
86
README.md
86
README.md
@ -12,7 +12,6 @@ FabManager is the Fab Lab management solution. It provides a comprehensive, web-
|
|||||||
3. [Setup a production environment](#setup-a-production-environment)
|
3. [Setup a production environment](#setup-a-production-environment)
|
||||||
4. [Setup a development environment](#setup-a-development-environment)<br/>
|
4. [Setup a development environment](#setup-a-development-environment)<br/>
|
||||||
4.1. [General Guidelines](#general-guidelines)<br/>
|
4.1. [General Guidelines](#general-guidelines)<br/>
|
||||||
4.2. [Virtual Machine Instructions](#virtual-machine-instructions)
|
|
||||||
5. [PostgreSQL](#postgresql)<br/>
|
5. [PostgreSQL](#postgresql)<br/>
|
||||||
5.1. [Install PostgreSQL 9.4](#setup-postgresql)
|
5.1. [Install PostgreSQL 9.4](#setup-postgresql)
|
||||||
6. [ElasticSearch](#elasticsearch)<br/>
|
6. [ElasticSearch](#elasticsearch)<br/>
|
||||||
@ -61,8 +60,11 @@ The procedure to follow is described in the [docker-compose readme](docker/READM
|
|||||||
## Setup a development environment
|
## Setup a development environment
|
||||||
|
|
||||||
In you intend to run fab-manager on your local machine to contribute to the project development, you can set it up with the following procedure.
|
In you intend to run fab-manager on your local machine to contribute to the project development, you can set it up with the following procedure.
|
||||||
|
|
||||||
This procedure is not easy to follow so if you don't need to write some code for Fab-manager, please prefer the [docker-compose installation method](docker/README.md).
|
This procedure is not easy to follow so if you don't need to write some code for Fab-manager, please prefer the [docker-compose installation method](docker/README.md).
|
||||||
|
|
||||||
|
Optionally, you can use a virtual development environment that relies on Vagrant and Virtual Box by following the [virtual machine instructions](doc/virtual-machine.md).
|
||||||
|
|
||||||
<a name="general-guidelines"></a>
|
<a name="general-guidelines"></a>
|
||||||
### General Guidelines
|
### General Guidelines
|
||||||
|
|
||||||
@ -186,83 +188,6 @@ This procedure is not easy to follow so if you don't need to write some code for
|
|||||||
18. Email notifications will be caught by MailCatcher.
|
18. Email notifications will be caught by MailCatcher.
|
||||||
To see the emails sent by the platform, open your web browser at `http://localhost:1080` to access the MailCatcher interface.
|
To see the emails sent by the platform, open your web browser at `http://localhost:1080` to access the MailCatcher interface.
|
||||||
|
|
||||||
<a name="virtual-machine-instructions"></a>
|
|
||||||
### Virtual Machine Instructions
|
|
||||||
|
|
||||||
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/sleede/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. Password minimal length is 8 characters):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
rake db:create
|
|
||||||
rake db:migrate
|
|
||||||
ADMIN_EMAIL='youradminemail' ADMIN_PASSWORD='youradminpassword' rake db:seed
|
|
||||||
rake fablab:es:build_stats
|
|
||||||
# for tests
|
|
||||||
RAILS_ENV=test rake db:create
|
|
||||||
RAILS_ENV=test rake db:migrate
|
|
||||||
```
|
|
||||||
|
|
||||||
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>
|
<a name="postgresql"></a>
|
||||||
## PostgreSQL
|
## PostgreSQL
|
||||||
@ -516,8 +441,3 @@ Developers may find information on how to implement their own authentication pro
|
|||||||
- [AngularJS](https://docs.angularjs.org/api)
|
- [AngularJS](https://docs.angularjs.org/api)
|
||||||
- [Angular-Bootstrap](http://angular-ui.github.io/bootstrap/)
|
- [Angular-Bootstrap](http://angular-ui.github.io/bootstrap/)
|
||||||
- [ElasticSearch 5.6](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index.html)
|
- [ElasticSearch 5.6](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index.html)
|
||||||
|
|
||||||
|
|
||||||
---
|
|
||||||
[vagrant]: https://www.vagrantup.com/downloads.html
|
|
||||||
[virtualbox]: https://www.virtualbox.org/wiki/Downloads
|
|
||||||
|
31
Vagrantfile
vendored
31
Vagrantfile
vendored
@ -5,10 +5,11 @@
|
|||||||
VAGRANTFILE_API_VERSION = '2'
|
VAGRANTFILE_API_VERSION = '2'
|
||||||
|
|
||||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||||
config.vm.box = 'ubuntu/xenial64'
|
config.vm.box = 'ubuntu/bionic64'
|
||||||
config.vm.define 'fabmanager-devbox'
|
config.vm.define 'fabmanager-devbox'
|
||||||
|
|
||||||
# Port forwarding
|
# Forward ports so services running in the virtual machine can be accessed by
|
||||||
|
# the host
|
||||||
[
|
[
|
||||||
3000, # rails/puma
|
3000, # rails/puma
|
||||||
9200, # elasticsearch
|
9200, # elasticsearch
|
||||||
@ -19,23 +20,31 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|||||||
config.vm.network "forwarded_port", guest: port, host: port
|
config.vm.network "forwarded_port", guest: port, host: port
|
||||||
end
|
end
|
||||||
|
|
||||||
# Provider-specific configuration
|
# Configuration to allocate resources fro the virtual machine
|
||||||
config.vm.provider 'virtualbox' do |vb|
|
config.vm.provider 'virtualbox' do |vb|
|
||||||
vb.customize ['modifyvm', :id, '--memory', '2048']
|
vb.customize ['modifyvm', :id, '--memory', '2048']
|
||||||
end
|
end
|
||||||
|
|
||||||
# If you are using Windows o Linux with an encrypted volume
|
# If you are using Windows o Linux with an encrypted volume stick with the
|
||||||
|
# configuration below for file syncronization
|
||||||
config.vm.synced_folder '.', '/vagrant', type: 'virtualbox'
|
config.vm.synced_folder '.', '/vagrant', type: 'virtualbox'
|
||||||
|
|
||||||
# Provisioning
|
# Copy default configuration files for the database conenction and the Rails application
|
||||||
config.vm.provision "shell", privileged: true, run: "once" do |s|
|
config.vm.provision "file", source: "./config/database.yml.default", destination: "/vagrant/config/database.yml"
|
||||||
s.inline = "export LC_ALL=en_US.UTF-8\n" \
|
config.vm.provision "file", source: "./config/application.yml.default", destination: "/vagrant/config/application.yml"
|
||||||
"export LANG=en_US.UTF-8\n" \
|
|
||||||
"export LANGUAGE=en_US.UTF-8"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
## Provision software dependencies
|
||||||
config.vm.provision "shell", privileged: false, run: "once",
|
config.vm.provision "shell", privileged: false, run: "once",
|
||||||
path: "provision/zsh_setup.sh"
|
path: "provision/zsh_setup.sh"
|
||||||
|
|
||||||
config.vm.provision "shell", privileged: false, run: "once",
|
config.vm.provision "shell", privileged: false, run: "once",
|
||||||
path: "provision/box_setup.zsh"
|
path: "provision/box_setup.zsh",
|
||||||
|
env: {
|
||||||
|
"LC_ALL" => "en_US.UTF-8",
|
||||||
|
"LANG" => "en_US.UTF-8",
|
||||||
|
"LANGUAGE" => "en_US.UTF-8",
|
||||||
|
}
|
||||||
|
|
||||||
|
config.vm.provision "shell", privileged: true, run: "once",
|
||||||
|
path: "provision/box_tuning.zsh"
|
||||||
end
|
end
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
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
|
|
71
doc/virtual-machine.md
Normal file
71
doc/virtual-machine.md
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# Virtual Machine Instructions
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
**Note 2:** The perfomance of the application under the virtual machine depends on the resources that
|
||||||
|
the host can provide but will usually be much more slower than 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/sleede/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
|
||||||
|
bundle install
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
|
7. 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. Password minimal length is 8 characters):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
rake db:create
|
||||||
|
rake db:migrate
|
||||||
|
# Be sure not to use the default values below in production
|
||||||
|
ADMIN_EMAIL='admin@email' ADMIN_PASSWORD='adminpass' rake db:seed
|
||||||
|
rake fablab:es:build_stats
|
||||||
|
# for tests
|
||||||
|
RAILS_ENV=test rake db:create
|
||||||
|
RAILS_ENV=test rake db:migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
8. Start the application and visit `localhost:3000` on your browser to check that it works:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
foreman s -p 3000
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
[vagrant]: https://www.vagrantup.com/downloads.html
|
||||||
|
[virtualbox]: https://www.virtualbox.org/wiki/Downloads
|
@ -1,127 +1,112 @@
|
|||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
# Set environmen values #######################################################
|
###
|
||||||
|
# Set user configuration
|
||||||
|
set_user_config() {
|
||||||
|
echo "Setting ´vagrant´ user profile configuration"
|
||||||
|
|
||||||
# Virtual environment flag
|
# Virtual environment flag
|
||||||
echo '# Set virtual environment flag' >> ~/.profile
|
echo -e '\n\n# Set virtual environment flag' >> ~/.profile
|
||||||
echo 'export VIRTUAL_DEV_ENV=true' >> ~/.profile
|
echo -e 'export VIRTUAL_DEV_ENV=true\n' >> ~/.profile
|
||||||
echo "\n" >> ~/.profile
|
|
||||||
|
|
||||||
# Language configuration
|
# Language configuration
|
||||||
echo '# Set locale configuration' >> ~/.profile
|
echo -e '\n# Set locale configuration' >> ~/.profile
|
||||||
echo 'export LC_ALL=en_US.UTF-8' >> ~/.profile
|
echo 'export LC_ALL=en_US.UTF-8' >> ~/.profile
|
||||||
echo 'export LANG=en_US.UTF-8' >> ~/.profile
|
echo 'export LANG=en_US.UTF-8' >> ~/.profile
|
||||||
echo 'export LANGUAGE=en_US.UTF-8' >> ~/.profile
|
echo -e 'export LANGUAGE=en_US.UTF-8\n' >> ~/.profile
|
||||||
echo "\n" >> ~/.profile
|
|
||||||
|
|
||||||
# Install and setup PostgreSQL ################################################
|
# Switch to project path after login
|
||||||
|
echo -e '\n# Navigate to /vagrant after login' >> ~/.profile
|
||||||
|
echo -e 'cd /vagrant\n' >> ~/.profile
|
||||||
|
}
|
||||||
|
|
||||||
echo "***************************************************"
|
###
|
||||||
echo "Checking Postgres installation..."
|
# Install and configure PostgreSQL database manager
|
||||||
echo "***************************************************"
|
install_postgres() {
|
||||||
if ! dpkg -s postgresql; then
|
|
||||||
echo "Installing PostgreSQL"
|
echo "Installing PostgreSQL"
|
||||||
sudo apt update
|
sudo apt-get update
|
||||||
sudo apt install -y postgresql postgresql-contrib
|
sudo apt-get install -y postgresql postgresql-contrib
|
||||||
|
|
||||||
echo "Setting up user"
|
# Set up ubuntu user for Postgres
|
||||||
sudo -u postgres bash -c "psql -c \"CREATE USER ubuntu WITH PASSWORD 'ubuntu';\""
|
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;\""
|
sudo -u postgres bash -c "psql -c \"ALTER USER ubuntu WITH SUPERUSER;\""
|
||||||
|
|
||||||
echo "Setting up extensions to all schemas"
|
# Make available useful extensions to the schemas
|
||||||
sudo -u postgres bash -c "psql -c \"CREATE EXTENSION unaccent SCHEMA pg_catalog;\""
|
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;\""
|
sudo -u postgres bash -c "psql -c \"CREATE EXTENSION pg_trgm SCHEMA pg_catalog;\""
|
||||||
fi
|
|
||||||
|
|
||||||
echo "***************************************************"
|
# Start service
|
||||||
echo " Starting Postgres server "
|
sudo service postgresql start
|
||||||
echo "***************************************************"
|
|
||||||
sudo service postgresql start
|
|
||||||
|
|
||||||
|
# Replace default database user in the app database configuration
|
||||||
|
sed -i 's@username: postgres@username: ubuntu@g' /vagrant/config/database.yml
|
||||||
|
sed -i 's@password: postgres@password: ubuntu@g' /vagrant/config/database.yml
|
||||||
|
}
|
||||||
|
|
||||||
# Install Redis ###############################################################
|
###
|
||||||
|
# Install Redis data store
|
||||||
|
install_redis() {
|
||||||
|
echo "Installing Redis"
|
||||||
|
sudo apt-get install -y redis-server
|
||||||
|
}
|
||||||
|
|
||||||
echo "***************************************************"
|
###
|
||||||
echo "Checking Redis installation..."
|
# Install Imagemagick image manipulation utilities
|
||||||
echo "***************************************************"
|
install_imagemagick() {
|
||||||
if ! dpkg -s redis-server; then
|
echo "Installing Imagemagick"
|
||||||
echo "Instalating Redis"
|
sudo apt-get install -y imagemagick
|
||||||
sudo apt install -y redis-server
|
}
|
||||||
fi
|
|
||||||
|
|
||||||
|
###
|
||||||
# Install Imagemagick #########################################################
|
# Install ElasticSearch search engine
|
||||||
|
install_elasticsearch() {
|
||||||
echo "***************************************************"
|
echo "Installing Oracle Java 8 and ElasticSearch"
|
||||||
echo "Checking Imagemagik installation..."
|
sudo apt-get install -y openjdk-8-jre apt-transport-https
|
||||||
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 -
|
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
|
echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
|
||||||
sudo apt update && sudo apt install -y elasticsearch
|
sudo apt-get update && sudo apt-get install -y elasticsearch
|
||||||
|
|
||||||
# This configuration limits ElasticSearch memory use inside the virtual machine
|
# This configuration limits ElasticSearch memory use inside the virtual machine
|
||||||
sudo echo "node.master: true" >> /etc/elasticsearch/elasticsearch.yml
|
sudo bash -c "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/#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 sed -i 's/#ES_JAVA_OPTS=/ES_JAVA_OPTS="-Xms256m -Xmx256m"/g' /etc/default/elasticsearch
|
||||||
|
|
||||||
sudo /bin/systemctl daemon-reload
|
sudo /bin/systemctl daemon-reload
|
||||||
sudo /bin/systemctl enable elasticsearch.service
|
sudo /bin/systemctl enable elasticsearch.service
|
||||||
else
|
|
||||||
echo 'OK'
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Create pids directory for Sidekick
|
||||||
|
sudo mkdir -p /vagrant/tmp/pids
|
||||||
|
}
|
||||||
|
|
||||||
# Install Ngrok exposer ######################################################
|
###
|
||||||
|
# Install Ngrok secure tunnel manager
|
||||||
echo "***************************************************"
|
install_ngrok() {
|
||||||
echo "Checking for Ngrok... "
|
echo 'Installing Ngrok'
|
||||||
echo "***************************************************"
|
sudo apt-get install -y unzip
|
||||||
if ! ngrok; then
|
|
||||||
sudo apt install -y unzip
|
|
||||||
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
|
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
|
||||||
sudo unzip ngrok-stable-linux-amd64.zip -d /usr/local/bin
|
sudo unzip ngrok-stable-linux-amd64.zip -d /usr/local/bin
|
||||||
rm -rf ngrok-stable-linux-amd64.zip
|
rm -rf ngrok-stable-linux-amd64.zip
|
||||||
else
|
}
|
||||||
echo "OK"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Install Node Version Manager
|
||||||
|
install_nvm() {
|
||||||
|
echo "Installing NVM"
|
||||||
|
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
||||||
|
|
||||||
# Install Node Version Manager ################################################
|
echo -e "\n# Node Version Manager" >> ~/.profile
|
||||||
|
|
||||||
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 'export NVM_DIR="$HOME/.nvm"' >> ~/.profile
|
||||||
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.profile
|
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.profile
|
||||||
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> ~/.profile
|
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> ~/.profile
|
||||||
echo "\n" >> ~/.profile
|
echo -e "\n" >> ~/.profile
|
||||||
echo 'autoload -U add-zsh-hook' >> ~/.profile
|
echo 'autoload -U add-zsh-hook' >> ~/.profile
|
||||||
echo 'load-nvmrc() {' >> ~/.profile
|
echo 'load-nvmrc() {' >> ~/.profile
|
||||||
echo ' local node_version="$(nvm version)"' >> ~/.profile
|
echo ' local node_version="$(nvm version)"' >> ~/.profile
|
||||||
echo ' local nvmrc_path="$(nvm_find_nvmrc)"' >> ~/.profile
|
echo ' local nvmrc_path="$(nvm_find_nvmrc)"' >> ~/.profile
|
||||||
echo "\n" >> ~/.profile
|
echo -e "\n" >> ~/.profile
|
||||||
echo ' if [ -n "$nvmrc_path" ]; then' >> ~/.profile
|
echo ' if [ -n "$nvmrc_path" ]; then' >> ~/.profile
|
||||||
echo ' local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")' >> ~/.profile
|
echo ' local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")' >> ~/.profile
|
||||||
echo "\n" >> ~/.profile
|
echo -e "\n" >> ~/.profile
|
||||||
echo ' if [ "$nvmrc_node_version" = "N/A" ]; then' >> ~/.profile
|
echo ' if [ "$nvmrc_node_version" = "N/A" ]; then' >> ~/.profile
|
||||||
echo ' nvm install' >> ~/.profile
|
echo ' nvm install' >> ~/.profile
|
||||||
echo ' elif [ "$nvmrc_node_version" != "$node_version" ]; then' >> ~/.profile
|
echo ' elif [ "$nvmrc_node_version" != "$node_version" ]; then' >> ~/.profile
|
||||||
@ -133,55 +118,73 @@ if [[ ! -x "$HOME/.nvm" ]]; then
|
|||||||
echo ' fi' >> ~/.profile
|
echo ' fi' >> ~/.profile
|
||||||
echo '}' >> ~/.profile
|
echo '}' >> ~/.profile
|
||||||
echo 'add-zsh-hook chpwd load-nvmrc' >> ~/.profile
|
echo 'add-zsh-hook chpwd load-nvmrc' >> ~/.profile
|
||||||
echo 'load-nvmrc' >> ~/.profile
|
echo -e "load-nvmrc\n" >> ~/.profile
|
||||||
|
|
||||||
export NVM_DIR="$HOME/.nvm"
|
export NVM_DIR="$HOME/.nvm"
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
||||||
else
|
}
|
||||||
echo "OK"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
###
|
||||||
# Install Node.js #############################################################
|
# Install stable version of Node.js
|
||||||
|
install_nodejs() {
|
||||||
echo "***************************************************"
|
echo 'Installing Node.js'
|
||||||
echo "Checking for Node.js... "
|
|
||||||
echo "***************************************************"
|
|
||||||
if ! node --version; then
|
|
||||||
nvm install stable
|
nvm install stable
|
||||||
nvm alias default stable
|
nvm alias default stable
|
||||||
nvm use default
|
nvm use default
|
||||||
else
|
}
|
||||||
echo 'OK'
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Install Yarn package manager
|
||||||
|
install_yarn() {
|
||||||
|
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
|
||||||
|
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
|
||||||
|
sudo apt-get update && sudo apt-get -y install yarn
|
||||||
|
}
|
||||||
|
|
||||||
# Ruby and Version Manager ####################################################
|
###
|
||||||
|
# Install Ruby Version Manager
|
||||||
echo "***************************************************"
|
install_rvm() {
|
||||||
echo 'Cheking for Ruby... '
|
echo 'Installing RVM'
|
||||||
echo "***************************************************"
|
|
||||||
if ! ruby -v; then
|
|
||||||
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
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
|
\curl -sSL https://get.rvm.io | bash
|
||||||
source /home/vagrant/.rvm/scripts/rvm
|
source $HOME/.rvm/scripts/rvm
|
||||||
rvm get head
|
rvm get stable
|
||||||
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
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Install Matz Ruby Interpreter
|
||||||
|
install_ruby() {
|
||||||
|
echo 'Installing Ruby'
|
||||||
|
sudo apt-get install -y libxml2-dev libxslt1-dev libpq-dev libidn11-dev
|
||||||
|
rvm install ruby-2.3.8
|
||||||
|
rvm use ruby-2.3.8@global
|
||||||
|
gem update --system --no-doc
|
||||||
|
gem update --no-doc
|
||||||
|
rvm use ruby-2.3.8 --default
|
||||||
|
rvm cleanup all
|
||||||
|
}
|
||||||
|
|
||||||
# Cleaning up #################################################################
|
###
|
||||||
|
# Remove unused software
|
||||||
|
clean_up() {
|
||||||
|
echo "Removing unused software"
|
||||||
|
sudo apt-get -y autoremove && sudo apt-get autoclean
|
||||||
|
}
|
||||||
|
|
||||||
echo "***************************************************"
|
setup() {
|
||||||
echo 'Removing unused software... '
|
set_user_config
|
||||||
echo "***************************************************"
|
install_postgres
|
||||||
rvm cleanup all
|
install_redis
|
||||||
sudo apt autoremove
|
install_imagemagick
|
||||||
|
install_elasticsearch
|
||||||
|
install_ngrok
|
||||||
|
install_nvm
|
||||||
|
install_nodejs
|
||||||
|
install_yarn
|
||||||
|
install_rvm
|
||||||
|
install_ruby
|
||||||
|
clean_up
|
||||||
|
}
|
||||||
|
|
||||||
|
setup "$@"
|
||||||
|
33
provision/box_tuning.zsh
Normal file
33
provision/box_tuning.zsh
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
###
|
||||||
|
# Tune-up the system settings
|
||||||
|
system_tuning()
|
||||||
|
{
|
||||||
|
echo "Tunning up the system"
|
||||||
|
|
||||||
|
# Enable overcomit memmory for Redis
|
||||||
|
sudo echo -e "\n## Redis tune-up" >> /etc/sysctl.conf
|
||||||
|
sudo echo '# Allow background save on low memory conditions' >> /etc/sysctl.conf
|
||||||
|
sudo echo -e "vm.overcommit_memory = 1\n" >> /etc/sysctl.conf
|
||||||
|
|
||||||
|
# Enagle huge pages for Redis
|
||||||
|
sudo touch /etc/rc.local
|
||||||
|
sudo echo '## Redis tune-up' >> /etc/rc.local
|
||||||
|
sudo echo '# Reduce latency and memory usage' >> /etc/rc.local
|
||||||
|
sudo echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
|
||||||
|
sudo echo -e "\n\n"
|
||||||
|
sudo echo -e "exit 0\n" >> /etc/rc.local
|
||||||
|
sudo chmod +x /etc/rc.local
|
||||||
|
|
||||||
|
# Increase virtual memory areas for ElasticSearch
|
||||||
|
sudo echo -e "\n## ElasticSearch tune-up" >> /etc/sysctl.conf
|
||||||
|
sudo echo '# Increase max virtual memory areas' >> /etc/sysctl.conf
|
||||||
|
sudo echo -e "vm.max_map_count = 262144\n" >> /etc/sysctl.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
system_tuning
|
||||||
|
}
|
||||||
|
|
||||||
|
setup "$@"
|
@ -1,36 +1,48 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
echo "***************************************************"
|
###
|
||||||
echo 'Updating system packages... '
|
# Update system packages
|
||||||
echo "***************************************************"
|
update_system() {
|
||||||
sudo apt update && sudo apt upgrade -y
|
echo 'Updating system'
|
||||||
|
sudo apt-get update && sudo apt-get upgrade -y
|
||||||
|
sudo apt-get install -y git curl
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# Install ZSH shell
|
||||||
|
install_zsh() {
|
||||||
|
echo 'Installing ZSH'
|
||||||
|
# Install and set zsh as shell
|
||||||
|
sudo apt-get install -y zsh
|
||||||
|
|
||||||
echo "***************************************************"
|
# Change shell to Zsh for the vagrant user
|
||||||
echo 'Checking Zsh installation... '
|
sudo chsh -s /bin/zsh vagrant
|
||||||
echo "***************************************************"
|
}
|
||||||
if ! dpkg -s zsh; then
|
|
||||||
# Install and set Zsh as shell
|
|
||||||
sudo apt install -y zsh
|
|
||||||
|
|
||||||
# Install Oh-My-Zsh!
|
###
|
||||||
|
# Install Oh My ZSH! plugin framework
|
||||||
|
install_ohmyzsh() {
|
||||||
|
echo "Installing Oh-My-ZSH!"
|
||||||
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.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
|
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
|
||||||
|
|
||||||
# Change the Oh-My-Zsh! default configuration.
|
# Change the Oh-My-Zsh! default configuration.
|
||||||
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="blinks"/g' ~/.zshrc
|
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@# CASE_SENSITIVE="true"@CASE_SENSITIVE="true"@g' ~/.zshrc
|
||||||
sed -i 's/# COMPLETION_WAITING_DOTS="true"/COMPLETION_WAITING_DOTS="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@# 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@# 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
|
sed -i 's@plugins=(git)@plugins=(git dirhistory common-aliases command-not-found ruby)@g' ~/.zshrc
|
||||||
|
|
||||||
# Include .profile settings
|
# Include .profile settings
|
||||||
echo ' ' >> ~/.zshrc
|
echo -e "\n# Include .profile settings" >> ~/.zshrc
|
||||||
echo '# Include .profile settings' >> ~/.zshrc
|
echo -e "source ~/.profile\n" >> ~/.zshrc
|
||||||
echo 'source ~/.profile' >> ~/.zshrc
|
}
|
||||||
echo ' ' >> ~/.zshrc
|
|
||||||
|
|
||||||
# Change shell to Zsh for the vagrant user
|
setup() {
|
||||||
sudo chsh -s /bin/zsh vagrant
|
update_system
|
||||||
fi
|
install_zsh
|
||||||
|
install_ohmyzsh
|
||||||
|
}
|
||||||
|
|
||||||
|
setup "$@"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user