1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/README.md

444 lines
19 KiB
Markdown
Raw Normal View History

2016-03-23 18:39:41 +01:00
# FabManager
2015-05-05 03:10:25 +02:00
2019-03-27 11:49:01 +01:00
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.
2015-05-05 03:10:25 +02:00
[![Coverage Status](https://coveralls.io/repos/github/sleede/fab-manager/badge.svg)](https://coveralls.io/github/sleede/fab-manager)
2018-12-18 10:55:28 +01:00
[![Docker pulls](https://img.shields.io/docker/pulls/sleede/fab-manager.svg)](https://hub.docker.com/r/sleede/fab-manager/)
[![Docker Build Status](https://img.shields.io/docker/build/sleede/fab-manager.svg)](https://hub.docker.com/r/sleede/fab-manager/builds)
2015-05-05 03:10:25 +02:00
##### Table of Contents
2016-03-23 18:39:41 +01:00
1. [Software stack](#software-stack)
2. [Contributing](#contributing)
3. [Setup a production environment](#setup-a-production-environment)
2016-04-11 20:24:09 +02:00
4. [Setup a development environment](#setup-a-development-environment)<br/>
4.1. [General Guidelines](#general-guidelines)<br/>
5. [PostgreSQL](#postgresql)<br/>
5.1. [Install PostgreSQL 9.4](#setup-postgresql)
2016-04-11 20:24:09 +02:00
6. [ElasticSearch](#elasticsearch)<br/>
6.1. [Install ElasticSearch](#setup-elasticsearch)<br/>
6.2. [Rebuild statistics](#rebuild-stats)<br/>
6.3. [Backup and Restore](#backup-and-restore-elasticsearch)
2016-04-11 20:24:09 +02:00
7. [Internationalization (i18n)](#i18n)<br/>
7.1. [Translation](#i18n-translation)<br/>
7.1.1. [Front-end translations](#i18n-translation-front)<br/>
7.1.2. [Back-end translations](#i18n-translation-back)<br/>
7.2. [Configuration](#i18n-configuration)<br/>
7.2.1. [Settings](#i18n-settings)<br/>
7.2.2. [Applying changes](#i18n-apply)
2016-05-03 11:27:01 +02:00
8. [Open Projects](#open-projects)
2016-06-16 18:01:45 +02:00
9. [Plugins](#plugins)
2016-09-12 17:29:44 +02:00
10. [Single Sign-On](#sso)
11. [Known issues](#known-issues)
12. [Related Documentation](#related-documentation)
2015-05-05 03:10:25 +02:00
2016-03-23 18:39:41 +01:00
<a name="software-stack"></a>
## Software stack
2015-05-05 03:10:25 +02:00
2016-03-23 18:39:41 +01:00
FabManager is a Ruby on Rails / AngularJS web application that runs on the following software:
2015-05-05 03:10:25 +02:00
- Ubuntu LTS 14.04+ / Debian 8+
2016-03-31 11:56:58 +02:00
- Ruby 2.3
2016-03-23 18:39:41 +01:00
- Redis 2.8.4+
- Sidekiq 3.3.4+
- Elasticsearch 5.6
2016-03-23 18:39:41 +01:00
- PostgreSQL 9.4
2015-05-05 03:10:25 +02:00
2016-03-23 18:39:41 +01:00
<a name="contributing"></a>
## Contributing
2015-05-05 03:10:25 +02:00
2016-03-23 18:39:41 +01:00
Contributions are welcome. Please read [the contribution guidelines](CONTRIBUTING.md) for more information about the contribution process.
2015-05-05 03:10:25 +02:00
2016-04-11 20:24:09 +02:00
<a name="setup-a-production-environment"></a>
## Setup a production environment
2016-04-11 20:24:09 +02:00
2018-11-27 10:40:51 +01:00
To run fab-manager as a production application, this is highly recommended to use [Docker-compose](https://docs.docker.com/compose/overview/).
The procedure to follow is described in the [docker-compose readme](docker/README.md).
2016-04-11 20:24:09 +02:00
2016-03-23 18:39:41 +01:00
<a name="setup-a-development-environment"></a>
## Setup a development environment
2015-05-05 03:10:25 +02:00
2017-12-13 17:51:44 +01:00
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).
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).
2016-03-23 18:39:41 +01:00
<a name="general-guidelines"></a>
### General Guidelines
2015-05-05 03:10:25 +02:00
1. Install RVM, with the ruby version specified in the [.ruby-version file](.ruby-version).
2018-11-22 17:09:14 +01:00
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.
2018-11-27 10:40:51 +01:00
2. Install NVM, with the node.js version specified in the [.nvmrc file](.nvmrc).
For instructions about installing NVM, please refer to [the NVM readme](https://github.com/creationix/nvm#installation).
3. Install Yarn, the front-end package manager.
2018-11-22 17:09:14 +01:00
Depending on your system, the installation process may differ, please read the [official Yarn documentation](https://yarnpkg.com/en/docs/install#debian-stable).
4. 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](https://docs.docker.com/install/linux/docker-ce/ubuntu/), [debian](https://docs.docker.com/install/linux/docker-ce/debian/) or [MacOS](https://docs.docker.com/docker-for-mac/install/) documentation to setup a recent version of docker.
2018-11-27 10:40:51 +01:00
5. Add your current user to the docker group, to allow using docker without `sudo`.
```bash
# add the docker group if it doesn't already exist
2019-09-09 17:54:41 +02:00
sudo groupadd docker
# add the current user to the docker group
sudo usermod -aG docker $(whoami)
# restart to validate changes
sudo reboot
```
6. Create a docker network for fab-manager.
You may have to change the network address if it is already in use.
```bash
docker network create --subnet=172.18.0.0/16 fabmanager
```
2016-05-03 11:27:01 +02:00
7. Retrieve the project from Git
2015-05-05 03:10:25 +02:00
2016-03-23 18:39:41 +01:00
```bash
2019-03-25 17:14:26 +01:00
git clone https://github.com/sleede/fab-manager.git
2016-03-23 18:39:41 +01:00
```
8. Install the software dependencies.
First install [PostgreSQL](#postgresql) and [ElasticSearch](#elasticsearch) as specified in their respective documentations.
Then install the other dependencies:
2016-03-23 18:39:41 +01:00
- For Ubuntu/Debian:
2016-05-03 11:27:01 +02:00
2016-03-23 18:39:41 +01:00
```bash
# 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
2016-03-23 18:39:41 +01:00
```
- For MacOS X:
2016-05-03 11:27:01 +02:00
2016-03-23 18:39:41 +01:00
```bash
brew install redis imagemagick
2016-03-23 18:39:41 +01:00
```
2016-05-03 11:27:01 +02:00
9. Init the RVM and NVM instances and check they were correctly configured
2016-05-03 11:27:01 +02:00
2016-03-23 18:39:41 +01:00
```bash
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
2016-03-23 18:39:41 +01:00
```
2016-05-03 11:27:01 +02:00
10. Install bundler in the current RVM gemset
2016-03-23 18:39:41 +01:00
```bash
gem install bundler --version=1.17.3
2016-03-23 18:39:41 +01:00
```
11. Install the required ruby gems and javascript plugins
2016-03-23 18:39:41 +01:00
```bash
bundle install
2018-11-22 17:09:14 +01:00
yarn install
2016-03-23 18:39:41 +01:00
```
2016-05-03 11:27:01 +02:00
12. Create the default configuration files **and configure them!** (see the [environment configuration documentation](doc/environment.md))
2016-05-03 11:27:01 +02:00
```bash
cp config/database.yml.default config/database.yml
cp config/application.yml.default config/application.yml
2016-05-03 11:27:01 +02:00
vi config/application.yml
# or use your favorite text editor instead of vi (nano, ne...)
```
2016-05-03 11:27:01 +02:00
13. 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](config/initializers/devise.rb)
2016-03-23 18:39:41 +01:00
```bash
2019-01-21 11:49:35 +01:00
# for dev
rake db:create
rake db:migrate
2017-12-21 11:32:13 +01:00
ADMIN_EMAIL='youradminemail' ADMIN_PASSWORD='youradminpassword' rake db:seed
2019-02-13 12:59:28 +01:00
rake fablab:es:build_stats
2019-01-21 11:49:35 +01:00
# for tests
RAILS_ENV=test rake db:create
RAILS_ENV=test rake db:migrate
2016-03-23 18:39:41 +01:00
```
2016-05-03 11:27:01 +02:00
14. Create the pids folder used by Sidekiq. If you want to use a different location, you can configure it in `config/sidekiq.yml`
2016-03-23 18:39:41 +01:00
```bash
mkdir -p tmp/pids
```
2016-05-03 11:27:01 +02:00
15. Start the development web server
2016-03-23 18:39:41 +01:00
```bash
foreman s -p 3000
```
2016-05-03 11:27:01 +02:00
16. You should now be able to access your local development FabManager instance by accessing `http://localhost:3000` in your web browser.
2016-03-23 18:39:41 +01:00
17. You can login as the default administrator using the credentials defined previously.
2016-03-23 18:39:41 +01:00
18. Email notifications will be caught by MailCatcher.
2017-03-02 10:29:17 +01:00
To see the emails sent by the platform, open your web browser at `http://localhost:1080` to access the MailCatcher interface.
2016-03-23 18:39:41 +01:00
<a name="postgresql"></a>
## PostgreSQL
<a name="setup-postgresql"></a>
### Install PostgreSQL 9.4
2016-03-23 18:39:41 +01:00
We will use docker to easily install the required version of PostgreSQL.
2016-03-23 18:39:41 +01:00
1. Create the docker binding folder
2016-03-23 18:39:41 +01:00
```bash
mkdir -p .docker/postgresql
2016-03-23 18:39:41 +01:00
```
2. Start the PostgreSQL container.
2016-03-23 18:39:41 +01:00
```bash
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
2016-03-23 18:39:41 +01:00
```
2016-05-03 11:27:01 +02:00
3. 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](doc/environment.md) for more details.
2016-03-23 18:39:41 +01:00
4 . Finally, you may want to have a look at detailed informations about PostgreSQL usage in fab-manager.
Some information about that is available in the [PostgreSQL Readme](doc/postgresql_readme.md).
2015-05-05 03:10:25 +02:00
2016-03-23 18:39:41 +01:00
<a name="elasticsearch"></a>
## ElasticSearch
2015-05-05 03:10:25 +02:00
2016-03-23 18:39:41 +01:00
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.
2016-05-03 11:27:01 +02:00
In FabManager, it is used for the admin's statistics module and to perform searches in projects.
2016-03-23 18:39:41 +01:00
<a name="setup-elasticsearch"></a>
### Install ElasticSearch
2016-05-03 11:27:01 +02:00
1. Create the docker binding folders
```bash
mkdir -p .docker/elasticsearch/config
mkdir -p .docker/elasticsearch/plugins
mkdir -p .docker/elasticsearch/backups
```
2. Copy the default configuration files
2016-03-23 18:39:41 +01:00
```bash
cp docker/elasticsearch.yml .docker/elasticsearch/config
cp docker/log4j2.properties .docker/elasticsearch/config
2016-03-23 18:39:41 +01:00
```
2016-05-03 11:27:01 +02:00
3. Start the ElasticSearch container.
2016-03-23 18:39:41 +01:00
```bash
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
2016-03-23 18:39:41 +01:00
```
4. 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](doc/environment.md) for more details.
<a name="rebuild-stats"></a>
### Rebuild statistics
2016-03-23 18:39:41 +01:00
Every nights, the statistics for the day that just ended are built automatically at 01:00 (AM) and stored in ElastricSearch.
See [schedule.yml](config/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.
2016-03-23 18:39:41 +01:00
```bash
# Here for the 50 last days
2019-02-13 12:59:28 +01:00
rake fablab:es:generate_stats[50]
2016-03-23 18:39:41 +01:00
```
2016-06-14 16:24:46 +02:00
<a name="backup-and-restore-elasticsearch"></a>
### Backup and Restore
To backup and restore the ElasticSearch database, use the [elasticsearch-dump](https://github.com/taskrabbit/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`.
2016-03-23 18:39:41 +01:00
<a name="i18n"></a>
## Internationalization (i18n)
The FabManager application can only run in a single language but this language can easily be changed.
<a name="i18n-translation"></a>
### 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).
2016-05-03 11:27:01 +02:00
- logged: translations of the end-user's views accessible only to connected users.
2016-03-23 18:39:41 +01:00
- 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.
2019-03-28 12:44:56 +01:00
To prevent syntax mistakes while translating locale files, we **STRONGLY advise** you to use a text editor which support syntax coloration for YML and Ruby.
2016-03-23 18:39:41 +01:00
<a name="i18n-translation-front"></a>
#### Front-end translations
Front-end translations uses [angular-translate](http://angular-translate.github.io) with some interpolations interpreted by angular.js and other interpreted by [MessageFormat](https://github.com/SlexAxton/messageformat.js/).
**These two kinds of interpolation use a near but different syntax witch SHOULD NOT be confused.**
Please refer to the official [angular-translate documentation](http://angular-translate.github.io/docs/#/guide/14_pluralization) before translating.
<a name="i18n-translation-back"></a>
#### Back-end translations
2016-05-03 11:27:01 +02:00
Back-end translations uses the [Ruby on Rails syntax](http://guides.rubyonrails.org/i18n.html) but some complex interpolations are interpreted by [MessageFormat](https://github.com/format-message/message-format-rb) and are marked as it in comments.
**DO NOT confuse the syntaxes.**
2016-03-23 18:39:41 +01:00
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.
2016-03-23 18:39:41 +01:00
You will also need to translate the invoice watermark, located in `app/pdfs/data/`.
You'll find there the [GIMP source of the image](app/pdfs/data/watermark.xcf), which is using [Rubik Mono One](https://fonts.google.com/specimen/Rubik+Mono+One) as font.
Use it to generate a similar localised PNG image which keep the default image size, as PDF are not responsive.
2016-03-23 18:39:41 +01:00
<a name="i18n-configuration"></a>
### Configuration
2016-05-03 11:27:01 +02:00
Locales configurations are made in `config/application.yml`.
2016-03-23 18:39:41 +01:00
If you are in a development environment, your can keep the default values, otherwise, in production, values must be configured carefully.
<a name="i18n-settings"></a>
#### Settings
2016-07-07 15:31:22 +02:00
Please refer to the [environment configuration documentation](doc/environment.md#internationalization-settings)
2016-07-07 15:31:22 +02:00
2016-03-23 18:39:41 +01:00
<a name="i18n-apply"></a>
#### Applying changes
After modifying any values concerning the localisation, restart the application (ie. web server) to apply these changes in the i18n configuration.
2016-05-03 11:27:01 +02:00
<a name="open-projects"></a>
## Open Projects
**This configuration is optional.**
2019-03-25 17:14:26 +01:00
You can configure your fab-manager to synchronize every project with the [Open Projects platform](https://github.com/sleede/openlab-projects).
2018-07-04 16:30:19 +02:00
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.
2016-05-03 11:29:14 +02:00
2016-05-03 11:27:01 +02:00
If you want to try it, you can visit [this fab-manager](https://fablab.lacasemate.fr/#!/projects) 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 an `OPENLAB_APP_SECRET`
- fill in the value of the keys in your environment file
2016-05-03 11:27:01 +02:00
- 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`
2016-06-13 11:34:11 +02:00
**IMPORTANT: please run your server in production mode.**
2016-05-03 11:29:38 +02:00
Go to your projects gallery and enjoy seeing your projects available from everywhere ! That's all.
2016-03-23 18:39:41 +01:00
2016-06-16 18:01:45 +02:00
<a name="plugins"></a>
## Plugins
Fab-manager has a system of plugins mainly inspired by [Discourse](https://github.com/discourse/discourse) architecture.
2016-06-16 18:01:45 +02:00
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.
2019-03-26 14:04:45 +01:00
You can see an example on the [repo of navinum gamification plugin](https://github.com/sleede/navinum-gamification)
2016-06-16 18:01:45 +02:00
2016-09-12 17:29:44 +02:00
<a name="sso"></a>
## Single Sign-On
Fab-manager can be connected to a [Single Sign-On](https://en.wikipedia.org/wiki/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](doc/sso_with_github.md).
Developers may find information on how to implement their own authentication protocol in [sso_authentication.md](doc/sso_authentication.md).
2016-09-12 17:29:44 +02:00
2016-03-23 18:39:41 +01:00
<a name="known-issues"></a>
## 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.
2016-03-23 18:39:41 +01:00
- When starting the Ruby on Rails server (eg. `foreman s`) you may receive the following error:
2016-01-18 15:40:30 +01:00
2016-03-23 18:39:41 +01:00
worker.1 | invalid url: redis::6379
web.1 | Exiting
worker.1 | ...lib/redis/client.rb...:in `_parse_options'
2016-01-18 15:40:30 +01:00
This may happen when the `application.yml` file is missing.
To solve this issue copy `config/application.yml.default` to `config/application.yml`.
This is required before the first start.
2016-05-03 11:27:01 +02:00
2016-11-21 15:00:34 +01:00
- Due to a stripe limitation, you won't be able to create plans longer than one year.
2015-05-05 03:10:25 +02:00
- 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 the `postgres` user and run the PostgreSQL shell (see [the dedicated section](#run-postgresql-cli) for instructions).
Then, run the following command (replace `sleede` with your test database user, as specified in your database.yml):
2016-05-03 11:27:01 +02:00
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` to `true` in `/etc/default/elasticsearch`.
Then reload ElasticSearch with:
```bash
sudo systemctl restart elasticsearch.service
```
2016-03-23 18:39:41 +01:00
<a name="related-documentation"></a>
## Related Documentation
2016-01-18 15:40:30 +01:00
2016-04-11 20:24:09 +02:00
- [Ruby 2.3.0](http://ruby-doc.org/core-2.3.0/)
2016-03-23 18:39:41 +01:00
- [Ruby on Rails](http://api.rubyonrails.org)
- [AngularJS](https://docs.angularjs.org/api)
- [Angular-Bootstrap](http://angular-ui.github.io/bootstrap/)
- [ElasticSearch 5.6](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index.html)