Skip to content

Commit 1b1c383

Browse files
authored
Support multi tenancy (#58)
2 parents 3cf4f27 + 4e1e5e3 commit 1b1c383

37 files changed

Lines changed: 696 additions & 180 deletions

File tree

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## Unreleased [major]
6+
7+
> Development of this release was supported by [Reset Tech](https://www.reset.tech).
8+
9+
### Added
10+
11+
- Support multi-tenant deployment on a single server, with isolated PM2 instances, nginx configurations, and SSH keys per collection
12+
- Add configurable rate limiting for API requests through `ota_rate_limit_rate` and `ota_rate_limit_burst` inventory variables
13+
14+
### Changed
15+
16+
- **Breaking:** Rename `ota_source_repository` to `ota_collection_repository`
17+
- **Breaking:** Rename `ota_source_repository_branch` to `ota_collection_repository_branch`
18+
- Scope PM2 home directory per collection (`~/.pm2-{collection_id}`)
19+
- Scope GitHub bot SSH keys per collection (`~/.ssh/ota-github-bot-key-{collection_id}`)
20+
- Scope nginx configuration files per collection
21+
522
## 2.1.1 - 2025-11-28
623

724
_Full changeset and discussions: [#57](https://github.com/OpenTermsArchive/deployment/pull/57)._

README.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ansible-galaxy collection install -r requirements.yml
3030

3131
## Usage
3232

33-
Once installed, the playbook `deploy` allows to set up the two main Open Terms Archive applications: [Engine](https://github.com/OpenTermsArchive/engine) and [Federation API](https://github.com/OpenTermsArchive/federation-api).
33+
Once installed, the playbook `deploy` allows to set up and deploy an Open Terms Archive [collection](https://docs.opentermsarchive.org/#collection) powered by the [Engine](https://github.com/OpenTermsArchive/engine).
3434

3535
The playbook can be executed using the `ansible-playbook` command-line tool:
3636

@@ -65,44 +65,51 @@ deployment/
6565
The `inventory.yml` file defines the hosts and the variables required for the deployment. This file should contain all the necessary variables as described below.
6666

6767
| Variable | Description | Required or default value |
68-
|--------------------------------|----------------------------------------------------------------------------------------------------------------------------|------------------------|
69-
| `ota_source_repository` | URL of the declarations repository to deploy | **required** |
70-
| `ota_source_repository_branch` | [Git branch or tag](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftree-ishatree-ishalsotreeish) of the source repository | `main` |
71-
| `ota_directory` | Directory path where the code will be deployed on the server | Name of the repository |
68+
|--------------------------------|----------------------------------------------------------------------------------------------------------------------------|---------------------------|
69+
| `ota_collection_repository` | URL of the declarations repository to deploy | **required** |
70+
| `ota_collection_repository_branch` | [Git branch or tag](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftree-ishatree-ishalsotreeish) of the source repository | `main` |
7271

7372
These variables are defined in the inventory file, for example:
7473

75-
```yml
74+
```yaml
7675
all:
7776
hosts:
7877
127.0.0.1:
7978
ansible_user: debian
80-
ota_source_repository: https://github.com/OpenTermsArchive/demo-declarations.git
81-
ota_source_repository_branch: master
82-
ota_directory: demo
79+
ota_collection_repository: https://github.com/OpenTermsArchive/demo-declarations.git
80+
ota_collection_repository_branch: main
8381
```
8482
85-
#### Changes on a existing deployment
83+
The playbook will automatically derive:
84+
- `ota_directory`: The directory where the code will be deployed (extracted from the repository URL, e.g., `demo-declarations`)
85+
- `ota_collection_id`: The collection identifier used for PM2 and nginx configuration (directory name without the `-declarations` suffix, e.g., `demo`)
86+
- `ota_pm2_home`: The PM2 home directory for isolating PM2 processes (e.g., `/home/debian/.pm2-demo`)
87+
88+
#### Multi-tenant deployment
89+
90+
Multiple collections can be deployed to the same server. Each collection will have its own isolated PM2 instance and nginx configuration. Simply define multiple hosts with different `ota_collection_repository` values, or deploy collections sequentially to the same host.
8691

87-
If the `ota_source_repository` is changed on an existing target, the application has to be [stopped](#playbook-execution-refinement) before the new configuration is deployed.
92+
#### Changes on an existing deployment
93+
94+
If the `ota_collection_repository` is changed on an existing target, the application has to be [stopped](#playbook-execution-refinement) before the new configuration is deployed.
8895

8996
- ### PM2 Configuration File — `pm2.config.cjs`
9097

9198
**This file is mandatory**
9299

93-
The `pm2.config.cjs` file is used to configure the [PM2](https://pm2.keymetrics.io) process manager, which is used to start the applications.
100+
The `pm2.config.cjs` file is used to configure the [PM2](https://pm2.keymetrics.io) process manager, which is used to start the applications.
94101

95102
- ### GitHub Bot Private Key — `github-bot-private-key`
96103

97-
The `github-bot-private-key` file contains a private SSH key for accessing and pushing to SSH Git URLs. This file is required if `ota_source_repository` is an SSH Git URL or if the URLs for versions and/or snapshots repositories in the `config/production.json` file of the source repository are SSH Git URLs.
104+
The `github-bot-private-key` file contains a private SSH key for accessing and pushing to SSH Git URLs. This file is required if `ota_collection_repository` is an SSH Git URL or if the URLs for versions and/or snapshots repositories in the `config/production.json` file of the source repository are SSH Git URLs.
98105

99-
It is strongly recommended to [encrypt this file](#file-encryption) if is is checked in to a public repository.
106+
It is strongly recommended to [encrypt this file](#file-encryption) if it is checked in to a public repository.
100107

101108
- ### Environment Variables File — `.env`
102109

103110
The `.env` file contains the environment variables for the deployed applications.
104111

105-
It is strongly recommended to [encrypt this file](#file-encryption) if is is checked in to a public repository.
112+
It is strongly recommended to [encrypt this file](#file-encryption) if it is checked in to a public repository.
106113

107114
## File encryption
108115

@@ -150,20 +157,20 @@ Use [tags](https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.htm
150157

151158
1. Install [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html).
152159
2. Install [Vagrant](https://www.vagrantup.com/downloads).
153-
3. Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) to manage virtual machines. If Docker is prefered, or on an Apple Silicon machine, install [Docker](https://docs.docker.com/get-docker/) instead.
160+
3. Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) to manage virtual machines. If Docker is preferred, or on an Apple Silicon machine, install [Docker](https://docs.docker.com/get-docker/) instead.
154161
4. Create a dedicated SSH key with no password: `ssh-keygen -f ~/.ssh/ota-vagrant -q -N ""`. This key will be automatically used by Vagrant.
155162

156163
> VirtualBox is not compatible with Apple Silicon (M1…) processors. To use vagrant on this kind of machine, specifying the Docker provider will be required. Since MongoDB cannot be installed on ARM, it is skipped in the infrastructure installation process. This means the MongoDB storage repository cannot be tested with Vagrant with an Apple Silicon processor.
157164

158-
## Usage
165+
### Usage
159166

160167
For testing this collection, a virtual machine description file is provided, inside the `tests` folder, to be used with [Vagrant](https://www.vagrantup.com).
161168

162169
All following commands must be executed from the `tests` folder:
163170

164171
cd tests
165172

166-
### Launch VM
173+
#### Launch VM
167174

168175
```sh
169176
vagrant up
@@ -173,7 +180,7 @@ vagrant up
173180

174181
Then the code can be deployed to the running machine with all the options described before.
175182

176-
### Test collection
183+
#### Test collection
177184

178185
Testing the Ansible collection locally is crucial to ensure that changes function properly before submitting them as a pull request.
179186

@@ -197,9 +204,9 @@ ansible-playbook ../playbooks/deploy.yml
197204
vagrant ssh # use "vagrant" as password
198205
```
199206

200-
- Check that everything works as intended within the virtual machine. Depending on the nature of changes made, you can monitor logs or execute commands to validate functionality:
207+
- Check that everything works as intended within the virtual machine. Depending on the nature of changes made, you can monitor logs or execute commands to validate functionality. Note that you need to set the `PM2_HOME` environment variable to the collection-specific PM2 home directory:
201208
```sh
202-
pm2 logs
209+
PM2_HOME=~/.pm2-demo pm2 logs
203210
```
204211

205212
#### Troubleshooting

ansible.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[defaults]
2+
roles_path = roles:playbooks/roles

0 commit comments

Comments
 (0)