.github | ||
app | ||
bin | ||
config | ||
db | ||
doc | ||
docker | ||
lib | ||
log | ||
plugins | ||
provision | ||
public | ||
scripts | ||
test | ||
vendor/assets | ||
.dockerignore | ||
.eslintignore | ||
.eslintrc | ||
.gemrc | ||
.gitignore | ||
.nvmrc | ||
.rspec | ||
.rubocop.yml | ||
.ruby-gemset | ||
.ruby-version | ||
3rd-PARTY-LICENSES.md | ||
Capfile | ||
CHANGELOG.md | ||
Cheffile | ||
coffeeerb.list | ||
config.ru | ||
CONTRIBUTING.md | ||
Dockerfile | ||
Gemfile | ||
Gemfile.lock | ||
Guardfile | ||
LICENSE.md | ||
package.json | ||
Procfile | ||
Rakefile | ||
README.md | ||
Vagrantfile | ||
yarn.lock |
FabManager
FabManager is the Fab Lab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.
Table of Contents
- Software stack
- Contributing
- Setup a production environment
- Setup a development environment
4.1. General Guidelines
4.2. Virtual Machine Instructions - PostgreSQL
5.1. Install PostgreSQL 9.4
5.2. Run the PostgreSQL command line interface
5.3. PostgreSQL Limitations - ElasticSearch
6.1. Install ElasticSearch
6.2. Rebuild statistics
6.3. Backup and Restore - Internationalization (i18n)
7.1. Translation
7.1.1. Front-end translations
7.1.2. Back-end translations
7.2. Configuration
7.2.1. Settings
7.2.2. Applying changes - Open Projects
- Plugins
- Single Sign-On
- Known issues
- Related Documentation
Software stack
FabManager is a Ruby on Rails / AngularJS web application that runs on the following software:
- Ubuntu LTS 14.04+ / Debian 8+
- Ruby 2.3
- Redis 2.8.4+
- Sidekiq 3.3.4+
- Elasticsearch 5.6
- PostgreSQL 9.4
Contributing
Contributions are welcome. Please read the contribution guidelines for more information about the contribution process.
Setup a production environment
To run fab-manager as a production application, this is highly recommended to use Docker-compose. The procedure to follow is described in the docker-compose readme.
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. 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.
General Guidelines
-
Install RVM, with the ruby version specified in the .ruby-version file. For more details about the process, please read the official RVM documentation. If you're using ArchLinux, you may have to read this before.
-
Install NVM, with the node.js version specified in the .nvmrc file. For instructions about installing NVM, please refer to the NVM readme.
-
Install Yarn, the front-end package manager. Depending on your system, the installation process may differ, please read the official Yarn documentation.
-
Install docker. Your system may provide a pre-packaged version of docker in its repositories, but this version may be outdated. Please refer to ubuntu, debian or MacOS documentation to setup a recent version of docker.
-
Add your current user to the docker group, to allow using docker without
sudo
.# add the docker group if it doesn't already exist sudo groupadd doker # add the current user to the docker group sudo usermod -aG docker $(whoami) # restart to validate changes sudo reboot
-
Create a docker network for fab-manager. You may have to change the network address if it is already in use.
docker network create --subnet=172.18.0.0/16 fabmanager
-
Retrieve the project from Git
git clone https://github.com/sleede/fab-manager.git
-
Install the software dependencies. First install PostgreSQL and ElasticSearch as specified in their respective documentations. Then install the other dependencies:
- For Ubuntu/Debian:
# on Ubuntu 18.04 server, you may have to enable the "universe" repository sudo add-apt-repository universe # then, install the dependencies sudo apt-get install libpq-dev redis-server imagemagick
- For MacOS X:
brew install redis imagemagick
-
Init the RVM and NVM instances and check they were correctly configured
cd fab-manager rvm current | grep -q `cat .ruby-version`@fab-manager && echo "ok" # Must print ok nvm use node --version | grep -q `cat .nvmrc` && echo "ok" # Must print ok
-
Install bundler in the current RVM gemset
gem install bundler --version=1.17.3
- Install the required ruby gems and javascript plugins
bundle install
yarn install
- Create the default configuration files and configure them! (see the environment configuration documentation)
cp config/database.yml.default config/database.yml
cp config/application.yml.default config/application.yml
vi config/application.yml
# or use your favorite text editor instead of vi (nano, ne...)
- Build the databases.
- Warning: DO NOT run
rake db:setup
instead of these commands, as this will not run some required raw SQL instructions. - Please note: Your password length must be between 8 and 128 characters, otherwise db:seed will be rejected. This is configured in config/initializers/devise.rb
# for dev
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
- Create the pids folder used by Sidekiq. If you want to use a different location, you can configure it in
config/sidekiq.yml
mkdir -p tmp/pids
- Start the development web server
foreman s -p 3000
-
You should now be able to access your local development FabManager instance by accessing
http://localhost:3000
in your web browser. -
You can login as the default administrator using the credentials defined previously.
-
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.
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.
-
Install Vagrant and Virtual Box (with the extension package).
-
Retrieve the project from Git
git clone https://github.com/sleede/fab-manager
-
From the project directory, run:
vagrant up
-
Once the virtual machine finished building, reload it with:
vagrant reload
-
Log into the virtual machine with:
vagrant ssh
-
While logged in, navigate to the project folder and install the Gemfile dependencies:
cd /vagrant bundle install
-
Set a directory for Sidekick pids:
mkdir -p tmp/pids
-
Copy the default configuration files:
cp config/database.yml.virtual config/database.yml cp config/application.yml.default config/application.yml
-
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):
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
- Start the application and visit
localhost:3000
on your browser to check that it works:
foreman s -p 3000
PostgreSQL
Install PostgreSQL 9.4
We will use docker to easily install the required version of PostgreSQL.
-
Create the docker binding folder
mkdir -p .docker/postgresql
-
Start the PostgreSQL container.
docker run --restart=always -d --name fabmanager-postgres \ -v $(pwd)/.docker/postgresql:/var/lib/postgresql/data \ --network fabmanager --ip 172.18.0.2 \ -p 5432:5432 \ postgres:9.4
-
Configure fab-manager to use it. On linux systems, PostgreSQL will be available at 172.18.0.2. On MacOS, you'll have to set the host to 127.0.0.1 (or localhost). See environment.md for more details.
-
Finally, have a look at the PostgreSQL Limitations section or some errors will occurs preventing you from finishing the installation procedure.
Run the PostgreSQL command line interface
You may want to access the psql command line tool to check the content of the database, or to run some maintenance routines. This can be achieved doing the following:
-
Enter into the PostgreSQL container
docker exec -it fabmanager-postgres bash
-
Run the PostgreSQL administration command line interface, logged as the postgres user
su postgres psql
PostgreSQL Limitations
- While setting up the database, we'll need to activate two PostgreSQL extensions: unaccent and trigram.
This can only be achieved if the user, configured in
config/database.yml
, was granted the SUPERUSER role OR if these extensions were white-listed. So here's your choices, mainly depending on your security requirements:-
Use the default PostgreSQL super-user (postgres) as the database user. This is the default behavior in fab-manager.
-
Set your user as SUPERUSER; run the following command in
psql
(after replacingusername
with you user name):ALTER USER username WITH SUPERUSER;
-
Install and configure the PostgreSQL extension pgextwlist. Please follow the instructions detailed on the extension website to whitelist
unaccent
andtrigram
for the user configured inconfig/database.yml
.
-
- Some users may want to use another DBMS than PostgreSQL.
This is currently not supported, because of some PostgreSQL specific instructions that cannot be efficiently handled with the ActiveRecord ORM:
app/controllers/api/members_controllers.rb@list
is usingILIKE
app/controllers/api/invoices_controllers.rb@list
is usingILIKE
anddate_trunc()
db/migrate/20160613093842_create_unaccent_function.rb
is using unaccent and trigram modules and defines a PL/pgSQL function (f_unaccent()
)app/controllers/api/members_controllers.rb@search
is usingf_unaccent()
(see above) andregexp_replace()
db/migrate/20150604131525_add_meta_data_to_notifications.rb
is using jsonb, a PostgreSQL 9.4+ datatype.db/migrate/20160915105234_add_transformation_to_o_auth2_mapping.rb
is using jsonb, a PostgreSQL 9.4+ datatype.db/migrate/20181217103441_migrate_settings_value_to_history_values.rb
is usingSELECT DISTINCT ON
.db/migrate/20190107111749_protect_accounting_periods.rb
is usingCREATE RULE
andDROP RULE
.
- If you intend to contribute to the project code, you will need to run the test suite with
rake test
. This also requires your user to have the SUPERUSER role. Please see the known issues section for more information about this.
ElasticSearch
ElasticSearch is a powerful search engine based on Apache Lucene combined with a NoSQL database used as a cache to index data and quickly process complex requests on it.
In FabManager, it is used for the admin's statistics module and to perform searches in projects.
Install ElasticSearch
-
Create the docker binding folders
mkdir -p .docker/elasticsearch/config mkdir -p .docker/elasticsearch/plugins mkdir -p .docker/elasticsearch/backups
-
Copy the default configuration files
cp docker/elasticsearch.yml .docker/elasticsearch/config cp docker/log4j2.properties .docker/elasticsearch/config
-
Start the ElasticSearch container.
docker run --restart=always -d --name fabmanager-elastic \ -v $(pwd)/.docker/elasticsearch/config:/usr/share/elasticsearch/config \ -v $(pwd)/.docker/elasticsearch:/usr/share/elasticsearch/data \ -v $(pwd)/.docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \ -v $(pwd)/.docker/elasticsearch/backups:/usr/share/elasticsearch/backups \ --network fabmanager --ip 172.18.0.3 \ -p 9200:9200 -p 9300:9300 \ elasticsearch:5.6
-
Configure fab-manager to use it. On linux systems, ElasticSearch will be available at 172.18.0.3. On MacOS, you'll have to set the host to 127.0.0.1 (or localhost). See environment.md for more details.
Rebuild statistics
Every nights, the statistics for the day that just ended are built automatically at 01:00 (AM) and stored in ElastricSearch. See schedule.yml to modify this behavior. If the scheduled task wasn't executed for any reason (eg. you are in a dev environment and your computer was turned off at 1 AM), you can force the statistics data generation in ElasticSearch, running the following command.
# Here for the 50 last days
rake fablab:es:generate_stats[50]
Backup and Restore
To backup and restore the ElasticSearch database, use the elasticsearch-dump tool.
Dump the database with: elasticdump --input=http://localhost:9200/stats --output=fablab_stats.json
.
Restore it with: elasticdump --input=fablab_stats.json --output=http://localhost:9200/stats
.
Internationalization (i18n)
The FabManager application can only run in a single language but this language can easily be changed.
Translation
Check the files located in config/locales
:
- Front app translations (angular.js) are located in
config/locales/app.scope.XX.yml
. Where scope has one the following meaning :- admin: translations of the administrator views (manage and configure the FabLab).
- logged: translations of the end-user's views accessible only to connected users.
- public: translation of end-user's views publicly accessible to anyone.
- shared: translations shared by many views (like forms or buttons).
- Back app translations (Ruby on Rails) are located in
config/locales/XX.yml
. - Emails translations are located in
config/locales/mails.XX.yml
. - Messages related to the authentication system are located in
config/locales/devise.XX.yml
.
If you plan to translate the application to a new locale, please consider that the reference translation is French. Indeed, in some cases, the English texts/sentences can seems confuse or lack of context as they were originally translated from French.
To prevent syntax mistakes while translating locale files, we STRONGLY advise you to use a text editor witch support syntax coloration for YML and Ruby.
Front-end translations
Front-end translations uses angular-translate with some interpolations interpreted by angular.js and other interpreted by MessageFormat. These two kinds of interpolation use a near but different syntax witch SHOULD NOT be confused. Please refer to the official angular-translate documentation before translating.
Back-end translations
Back-end translations uses the Ruby on Rails syntax but some complex interpolations are interpreted by MessageFormat and are marked as it in comments. DO NOT confuse the syntaxes.
In each cases, some inline comments are included in the localisation files. They can be recognized as they start with the sharp character (#). These comments are not required to be translated, they are intended to help the translator to have some context information about the sentence to translate.
Configuration
Locales configurations are made in config/application.yml
.
If you are in a development environment, your can keep the default values, otherwise, in production, values must be configured carefully.
Settings
Please refer to the environment configuration documentation
Applying changes
After modifying any values concerning the localisation, restart the application (ie. web server) to apply these changes in the i18n configuration.
Open Projects
This configuration is optional.
You can configure your fab-manager to synchronize every project with the Open Projects platform. It's very simple and straightforward and in return, your users will be able to search over projects from all fab-manager instances from within your platform. The deal is fair, you share your projects and as reward you benefits from projects of the whole community.
If you want to try it, you can visit this fab-manager and see projects from different fab-managers.
To start using this awesome feature, there are a few steps:
- send a mail to contact@fab-manager.com asking for your Open Projects client's credentials and giving them the name of your fab-manager, they will give you an
OPENLAB_APP_ID
and anOPENLAB_APP_SECRET
- fill in the value of the keys in your environment file
- start your fab-manager app
- export your projects to open-projects (if you already have projects created on your fab-manager, unless you can skip that part) executing this command:
bundle exec rake fablab:openlab:bulk_export
IMPORTANT: please run your server in production mode.
Go to your projects gallery and enjoy seeing your projects available from everywhere ! That's all.
Plugins
Fab-manager has a system of plugins mainly inspired by Discourse architecture.
It enables you to write plugins which can:
- have its proper models and database tables
- have its proper assets (js & css)
- override existing behaviours of Fab-manager
- add features by adding views, controllers, ect...
To install a plugin, you just have to copy the plugin folder which contains its code into the folder plugins
of Fab-manager.
You can see an example on the repo of navinum gamification plugin
Single Sign-On
Fab-manager can be connected to a Single Sign-On server which will provide its own authentication for the platform's users. Currently OAuth 2 is the only supported protocol for SSO authentication.
For an example of how to use configure a SSO in Fab-manager, please read sso_with_github.md. Developers may find information on how to implement their own authentication protocol in sso_authentication.md.
Known issues
-
When browsing a machine page, you may encounter an "InterceptError" in the console and the loading bar will stop loading before reaching its ending. This may happen if the machine was created through a seed file without any image. To solve this, simply add an image to the machine's profile and refresh the web page.
-
When starting the Ruby on Rails server (eg.
foreman s
) you may receive the following error:worker.1 | invalid url: redis::6379 web.1 | Exiting worker.1 | ...lib/redis/client.rb...:in `_parse_options'
This may happen when the
application.yml
file is missing. To solve this issue copyconfig/application.yml.default
toconfig/application.yml
. This is required before the first start. -
Due to a stripe limitation, you won't be able to create plans longer than one year.
-
When running the tests suite with
rake test
, all tests may fail with errors similar to the following:Error: ... ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "..." violates foreign key constraint "fk_rails_..." DETAIL: Key (group_id)=(1) is not present in table "...". : ... test_after_commit (1.0.0) lib/test_after_commit/database_statements.rb:11:in `block in transaction' test_after_commit (1.0.0) lib/test_after_commit/database_statements.rb:5:in `transaction'
This is due to an ActiveRecord behavior witch disable referential integrity in PostgreSQL to load the fixtures. PostgreSQL will prevent any users to disable referential integrity on the fly if they doesn't have the
SUPERUSER
role. To fix that, logon as thepostgres
user and run the PostgreSQL shell (see the dedicated section for instructions). Then, run the following command (replacesleede
with your test database user, as specified in your database.yml):ALTER ROLE sleede WITH SUPERUSER;
DO NOT do this in a production environment, unless you know what you're doing: this could lead to a serious security issue.
-
With Ubuntu 16.04, ElasticSearch may refuse to start even after having configured the service with systemd. To solve this issue, you may have to set
START_DAEMON
totrue
in/etc/default/elasticsearch
. Then reload ElasticSearch with:sudo systemctl restart elasticsearch.service