1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/doc/production_readme.md

258 lines
10 KiB
Markdown
Raw Normal View History

2020-02-26 10:19:43 +01:00
# Install Fab-manager in production with docker-compose
2016-03-23 18:39:41 +01:00
2020-02-26 10:19:43 +01:00
This document will guide you through all the steps needed to set up your Fab-manager app on a production server, based on a solution using Docker and Docker-compose.
2017-07-20 19:54:37 +02:00
2020-02-26 10:19:43 +01:00
In order to make it work, please use the same directories structure as described in this guide in your Fab-manager app folder.
2017-07-20 19:54:37 +02:00
You will need to be root through the rest of the setup.
2016-03-23 18:39:41 +01:00
2017-07-20 17:14:02 +02:00
##### Table of contents
2017-07-20 17:18:19 +02:00
1. [Preliminary steps](#preliminary-steps)<br/>
2019-12-30 17:34:15 +01:00
1.1. [Setup the server](#setup-the-server)<br/>
1.2. [Setup the domain name](#setup-the-domain-name)<br/>
1.3. [Connect through SSH](#connect-through-ssh)<br/>
1.4. [Prepare the server](#prepare-the-server)<br/>
2. [Install Fab-manager](#install-fab-manager)<br/>
2021-10-07 17:41:38 +02:00
3. [Useful commands](#useful-commands)
2021-06-10 17:09:09 +02:00
4. [Update Fab-manager](#update-fab-manager)<br/>
4.1. [Scripted update](#scripted-update)<br/>
4.2. [Update manually](#update-manually)<br/>
4.2.2. [Manual update steps](#manual-update-steps)<br/>
4.3. [Upgrade to the last version](#upgrade-to-the-last-version)<br/>
4.4. [Upgrade to a specific version](#upgrade-to-a-specific-version)<br/>
4.4.1. [With scripted update](#with-scripted-update)<br/>
4.4.2. [With manual update](#with-manual-update)<br/>
2017-07-20 17:14:02 +02:00
2017-12-13 17:51:44 +01:00
<a name="preliminary-steps"></a>
2017-07-20 17:37:03 +02:00
## Preliminary steps
2017-07-20 16:48:34 +02:00
2017-12-14 14:33:49 +01:00
<a name="setup-the-server"></a>
2017-12-13 17:51:44 +01:00
### Setup the server
2021-10-07 17:41:38 +02:00
There are [many hosting providers](https://duckduckgo.com/?q=vps+hosting) on the internet, providing affordable virtual private serveurs (VPS).
2017-12-13 17:51:44 +01:00
Choose one, depending on your budget, on the server's location, on the uptime guarantee, etc.
2021-10-07 17:41:38 +02:00
#### System requirements
##### Memory
2022-08-24 11:13:41 +02:00
To install or upgrade Fab-manager you need at least 4 GB of RAM + 2 GB of swap to be able to compile the assets.
Once installed, if you do not plan to use the statistics module, you will need at least 2 GB of addressable memory (RAM + swap) to use Fab-manager.
2021-10-07 17:41:38 +02:00
We recommend 4 GB of RAM to take full advantage of Fab-manager and be able to use the statistics module.
If you have a large community (~ 200 active membres), we recommend 4 GB of RAM, even without the statistics module.
During the installation and the upgrades, the assets' compilation phase may fail if you do not have sufficient available memory.
##### CPU and Operating system
2016-04-11 20:24:09 +02:00
2021-06-08 09:44:34 +02:00
Supported operating systems are Ubuntu LTS 16.04+ and Debian 8+ with an x86 64-bits architecture.
This might work on other linux systems, and CPU architectures but this is untested for now, and we do not recommend for production purposes.
2021-10-07 17:41:38 +02:00
#### Software requirements
2022-08-24 11:13:41 +02:00
`curl` and `bash` are needed to retrieve and run the automated deployment scripts.
Then the various scripts will check for their own dependencies.
2017-12-14 14:41:43 +01:00
2022-08-24 11:13:41 +02:00
Moreover, the main software dependencies to run fab-manager are [Docker](https://docs.docker.com/engine/installation/linux/docker-ce/debian/) v20.10 or above and [Docker Compose](https://docs.docker.com/compose/install/)
They can be easily installed using the [`prepare-vps.sleede.com` script below](#prepare-the-server).
2017-12-13 17:51:44 +01:00
2019-12-30 17:34:15 +01:00
<a name="setup-the-domain-name"></a>
2021-04-27 09:24:42 +02:00
### Set up the domain name
2016-04-11 20:24:09 +02:00
2021-10-07 17:41:38 +02:00
There are [many domain name registrars](https://duckduckgo.com/?q=register+domain+name) on the internet, choose one that fit your needs.
2017-12-13 17:51:44 +01:00
2019-12-03 17:32:27 +01:00
1. Once done, buy a domain name on it
2021-04-27 09:24:42 +02:00
2. Replace the IP address of the domain with the IP address of your VPS (This is a DNS record of **type A**)
2019-12-03 17:32:27 +01:00
3. **Do not** try to access your domain name right away, DNS are not aware of the change yet so **WAIT** and be patient.
2021-04-27 09:24:42 +02:00
4. You may want to bind the subdomain `www.` to your main domain name. You can achieve this by creating a DNS record of **type CNAME**.
2016-04-11 20:24:09 +02:00
2019-12-30 17:34:15 +01:00
<a name="connect-through-ssh"></a>
2017-12-13 17:51:44 +01:00
### Connect through SSH
2016-04-11 20:24:09 +02:00
2017-07-20 19:54:37 +02:00
You can already connect to the server with this command: `ssh root@server-ip`. When DNS propagation will be done, you will be able to
connect to the server with `ssh root@your-domain-name`.
2016-03-23 18:39:41 +01:00
2019-12-30 17:34:15 +01:00
<a name="prepare-the-server"></a>
2017-12-13 17:51:44 +01:00
### Prepare the server
2020-02-26 10:19:43 +01:00
Before installing Fab-manager, we recommend you to:
2017-12-13 17:51:44 +01:00
- Upgrade your system
2021-04-27 09:24:42 +02:00
- Set up the server timezone
- Add at least 2 GB of swap memory
- Protect your SSH connection by forcing it through an RSA key
2016-04-11 20:24:09 +02:00
2017-12-14 14:33:49 +01:00
You can run the following script as root to easily perform all these operations:
2016-04-11 20:24:09 +02:00
2016-03-23 18:39:41 +01:00
```bash
2017-12-14 14:33:49 +01:00
\curl -sSL prepare-vps.sleede.com | bash
2016-03-23 18:39:41 +01:00
```
<a name="install-fab-manager"></a>
2020-02-26 10:19:43 +01:00
## Install Fab-manager
2017-07-20 19:54:37 +02:00
2020-02-26 10:19:43 +01:00
Run the following command to install Fab-manager.
This script will guide you through the installation process by checking the requirements and asking you the configuration elements.
2016-03-23 18:39:41 +01:00
```bash
2021-05-17 15:46:42 +02:00
\curl -sSL setup.fab.mn | bash
2016-03-23 18:39:41 +01:00
```
2020-02-26 10:19:43 +01:00
**OR**, if you don't want to install Fab-manager in `/apps/fabmanager`, use the following instead:
2016-03-23 18:39:41 +01:00
```bash
2021-05-17 15:46:42 +02:00
\curl -sSL setup.fab.mn | bash -s "/my/custom/path"
2016-03-23 18:39:41 +01:00
```
## Fab-manager for small configurations
If your server machine is not powerful, you can lower the system requirements by uninstalling ElasticSearch.
In order to remove ElasticSearch, you must **first** disable the statistics module from Customization > General > Modules.
Then, you can remove the `elasticsearch` service from the [docker-compose.yml](../setup/docker-compose.yml) file and restart the whole application:
```bash
docker compose down && docker compose up -d
```
2022-08-24 11:13:41 +02:00
Disabling ElasticSearch will save up to 800 Mb of memory.
2021-10-07 17:41:38 +02:00
<a name="useful-commands"></a>
## Useful commands
Below, you'll find a collection of useful commands to control your instance with docker-compose.
Before using any of these commands, you must first `cd` into the app directory.
2020-06-23 12:21:35 +02:00
- Read again the environment variables and restart
```bash
docker compose down && docker compose up -d
```
2021-10-07 17:41:38 +02:00
- Open a bash prompt inside the app container
2019-12-24 16:19:44 +01:00
```bash
docker compose exec fabmanager bash
```
2021-10-07 17:41:38 +02:00
- Open the ruby console in the application
```bash
\curl -sSL run.fab.mn | bash
```
- Show services status
```bash
docker compose ps
```
2021-10-07 17:41:38 +02:00
- Run a command and provide it environment variables
```bash
docker compose run --rm -e VAR1=xxx -e VAR2=xxx fabmanager bundle exec rails my:command
```
2021-06-10 17:09:09 +02:00
<a name="update-fab-manager"></a>
## Update Fab-manager
When a new version is available, follow this procedure to update Fab-manager in a production environment.
You can subscribe to [this atom feed](https://github.com/sleede/fab-manager/releases.atom) to get notified when a new release comes out.
2021-06-10 17:09:09 +02:00
<a name="scripted-update"></a>
2022-08-24 11:13:41 +02:00
### Scripted update
2021-06-10 17:09:09 +02:00
Starting with Fab-manager v4.5.0, you can upgrade Fab-manager in one single easy command, specified in the GitHub releases notes.
To upgrade multiple versions at once, read the GitHub release notes of all versions between your current version, and the target version.
2021-06-10 17:09:09 +02:00
**You MUST append all the arguments** of the upgrade commands, for **each version**, to the command you run.
2021-04-27 09:24:42 +02:00
E.g.
2021-06-10 17:09:09 +02:00
If you upgrade from 1.2.3 to 1.2.6, with the following release notes:
```markdown
## 1.2.4
2021-05-17 15:46:42 +02:00
\curl -sSL upgrade.fab.mn | bash -s -- -e "VAR=value"
## 1.2.5
2021-05-17 15:46:42 +02:00
\curl -sSL upgrade.fab.mn | bash -s -- -c "rails fablab:setup:command"
2021-06-10 17:09:09 +02:00
## 1.2.6
\curl -sSL upgrade.fab.mn | bash -s -- -p "rails fablab:do:things"
```
Then, you'll need to perform the upgrade with the following command:
```bash
2021-06-10 17:09:09 +02:00
\curl -sSL upgrade.fab.mn | bash -s -- -e "VAR=value" -p "rails fablab:do:things" -c "rails fablab:setup:command"
```
2022-08-24 11:13:41 +02:00
> ⚠ Do not confuse commands prefixed with `-p` and with `-c` because they are not intended to run at the same moment of the upgrade process.
2021-06-10 17:09:09 +02:00
<a name="update-manually"></a>
### Update manually
2017-07-20 17:14:02 +02:00
2021-06-10 17:09:09 +02:00
**If you upgrade Fab-manager from a version >= 4.5.0, we recommend using the upgrade script above.**
2021-06-10 17:09:09 +02:00
> ⚠ If you are upgrading from a very outdated version, you must first upgrade to these versions in order:
> - v2.8.3
> - v3.1.2
> - v4.0.4
> - v4.4.6
> - v4.7.13
2021-06-10 17:09:09 +02:00
> After that, you can finally update to the last version
> ⚠ With versions < 4.3.3, you must replace `bundle exec rails` with `bundle exec rake` in all the commands above
2017-07-20 17:14:02 +02:00
2021-06-10 17:09:09 +02:00
<a name="manual-update-steps"></a>
#### Manual update steps
2017-07-20 17:14:02 +02:00
2021-06-10 17:09:09 +02:00
0. Read carefully the changelog of the last version you are upgrading to. It will contain important instructions about the upgrade process.
2016-06-14 14:33:57 +02:00
2021-06-10 17:09:09 +02:00
1. Go to your app folder
2016-06-14 14:33:57 +02:00
2017-07-20 19:54:37 +02:00
`cd /apps/fabmanager`
2016-06-14 14:33:57 +02:00
2022-08-24 11:13:41 +02:00
2. Pull last docker images
2016-06-14 14:33:57 +02:00
`docker compose pull`
2021-06-10 17:09:09 +02:00
3. Stop the app
2016-06-14 14:33:57 +02:00
`docker compose stop fabmanager`
2016-06-14 14:33:57 +02:00
2021-06-10 17:09:09 +02:00
4. Remove old assets
2016-06-14 14:33:57 +02:00
2021-04-27 09:24:42 +02:00
`rm -Rf public/packs/ public/assets/`
2016-06-14 14:33:57 +02:00
2021-06-10 17:09:09 +02:00
5. Compile new assets
2016-06-14 14:33:57 +02:00
`docker compose run --rm fabmanager bundle exec rails assets:precompile`
2016-06-14 14:33:57 +02:00
2021-06-10 17:09:09 +02:00
6. Run specific commands
2016-06-14 14:33:57 +02:00
2022-08-24 11:13:41 +02:00
**Do not forget** to check if there are commands to run for your upgrade. Those commands
2021-06-10 17:09:09 +02:00
are always specified in the [CHANGELOG](https://github.com/sleede/fab-manager/blob/master/CHANGELOG.md) and prefixed by **[TODO DEPLOY]**.
2022-08-24 11:13:41 +02:00
2021-04-27 09:24:42 +02:00
Those commands execute specific tasks and have to be run manually.
You must prefix the commands starting by `rails...` or `rake...` with: `docker compose run --rm fabmanager bundle exec`.
2020-10-23 16:05:05 +02:00
In any other cases, the other commands (like those invoking curl `\curl -sSL... | bash`) must not be prefixed.
2019-03-27 17:44:19 +01:00
You can also ignore commands only applicable to development environnement, which are prefixed by `(dev)` in the CHANGELOG.
2016-06-14 14:33:57 +02:00
2021-06-10 17:09:09 +02:00
7. Restart all containers
2016-06-14 14:33:57 +02:00
```bash
docker compose down
docker compose up -d
```
2016-06-14 14:33:57 +02:00
You can check that all containers are running with `docker compose ps`.
2016-06-14 14:33:57 +02:00
<a name="upgrade-to-the-last-version"></a>
### Upgrade to the last version
2016-06-14 14:33:57 +02:00
2022-08-24 11:13:41 +02:00
It's the default behaviour as `docker compose pull` command will fetch the latest versions of the docker images.
Be sure to run all the specific commands listed in the [CHANGELOG](https://github.com/sleede/fab-manager/blob/master/CHANGELOG.md) between your actual, and the new version in sequential order.
2021-06-10 17:09:09 +02:00
__Example:__ to update from v2.4.0 to v2.4.3, you will run the specific commands for the v2.4.1, v2.4.2 and v2.4.3.
<a name="upgrade-to-a-specific-version"></a>
### Upgrade to a specific version
<a name="with-scripted-update"></a>
#### With scripted update
The easiest way to proceed is to provide the target version to the upgrade script, with the `-t` parameter, like this:
```bash
\curl -sSL upgrade.fab.mn | bash -s -- -t 4.7.13
```
<a name="with-manual-update"></a>
#### With manual update
If you are upgrading manually, edit your [/apps/fabmanager/docker-compose.yml](../setup/docker-compose.yml#L4) file and change the following line:
```yaml
image: sleede/fab-manager
```
For example, here we want to use the v3.1.2:
```yaml
image: sleede/fab-manager:release-v3.1.2
```
2022-08-24 11:13:41 +02:00
Then run the normal upgrade procedure.