Merge branch 'imp/11.0/attachment_minio_config_file' into '11.0-test'

imp/11.0/attachment_minio_config_file into 11.0-test

See merge request hibou-io/hibou-odoo/suite!164
This commit is contained in:
Hibou Bot
2019-10-11 21:28:42 +00:00
3 changed files with 98 additions and 25 deletions

View File

@@ -0,0 +1,52 @@
# Use MinIO (or Amazon S3) for Attachment/filestore
MinIO provides S3 API compatible storage to scale out without a shared filesystem like NFS.
This module will store the bucket used in the attachment database object, thus allowing
you to retain read-only access to the filestore by simply overriding the bucket.
## Setup details
Before installing this app, you should add several System Parameters (the most important of
which is `ir_attachment.location`), OR set them through the config file as described later.
**The in database System Parameters will act as overrides to the Config File versions.**
| Key | Example Value | Default Value |
|-----------------------------------|---------------|---------------|
| ir_attachment.location | s3 | |
| ir_attachment.location.host | minio:9000 | |
| ir_attachment.location.bucket | odoo | |
| ir_attachment.location.region | us-west-1 | us-west-1 |
| ir_attachment.location.access_key | minio | |
| ir_attachment.location.secret_key | minio_secret | |
| ir_attachment.location.secure | 1 | |
**Config File:**
```
attachment_minio_host = minio:9000
attachment_minio_region = us-west-1
attachment_minio_access_key = minio
attachment_minio_secret_key = minio_secret
attachment_minio_bucket = odoo
attachment_minio_secure = False
```
In general, they should all be specified other than "region" (if you are not using AWS S3)
and "secure" which should be set if the "host" needs to be accessed over SSL/TLS.
Install `attachment_minio` and during the installation `base_attachment_object_storage` should move
your existing filestore attachment files into the database or object storage.
For example, you can run a shell command like the following to set the parameter:
```
env['ir.config_parameter'].set_param('ir_attachment.location', 's3')
# If already installed...
# env['ir.attachment'].force_storage()
env.cr.commit()
```
If `attachment_minio` is not already installed, you can then install it and the migration
should be noted in the logs. **Ensure that the timeouts are long enough that the migration can finish.**

View File

@@ -7,40 +7,59 @@
"author": "Hibou Corp.", "author": "Hibou Corp.",
"license": "AGPL-3", "license": "AGPL-3",
"description": """ "description": """
################################################# # Use MinIO (or Amazon S3) for Attachment/filestore
Use MinIO (or Amazon S3) for Attachment/filestore
#################################################
MinIO provides S3 API compatible storage to scale out without a shared filesystem like NFS. MinIO provides S3 API compatible storage to scale out without a shared filesystem like NFS.
This module will store the bucket used in the attachment database object, thus allowing
you to retain read-only access to the filestore by simply overriding the bucket.
Setup details ## Setup details
#############
Before installing this app, you should add several System Parameters. Before installing this app, you should add several System Parameters (the most important of
which is `ir_attachment.location`), OR set them through the config file as described later.
Key : Example Value : Default Value **The in database System Parameters will act as overrides to the Config File versions.**
ir_attachment.location : s3 : _ | Key | Example Value | Default Value |
|-----------------------------------|---------------|---------------|
| ir_attachment.location | s3 | |
| ir_attachment.location.host | minio:9000 | |
| ir_attachment.location.bucket | odoo | |
| ir_attachment.location.region | us-west-1 | us-west-1 |
| ir_attachment.location.access_key | minio | |
| ir_attachment.location.secret_key | minio_secret | |
| ir_attachment.location.secure | 1 | |
ir_attachment.location.host : minio.yourdomain.com : _ **Config File:**
ir_attachment.location.bucket : odoo-prod : _
ir_attachment.location.region : us-west-1 : us-west-1
ir_attachment.location.access_key : odoo : _
ir_attachment.location.secret_key : 123456 : _
ir_attachment.location.secure : 1 : _
```
attachment_minio_host = minio:9000
attachment_minio_region = us-west-1
attachment_minio_access_key = minio
attachment_minio_secret_key = minio_secret
attachment_minio_bucket = odoo
attachment_minio_secure = False
```
In general, they should all be specified other than "region" (if you are not using AWS S3) In general, they should all be specified other than "region" (if you are not using AWS S3)
and "secure" which should be set if the "host" needs to be accessed over SSL/TLS. and "secure" which should be set if the "host" needs to be accessed over SSL/TLS.
Install `attachment_minio` and during the installation `base_attachment_object_storage` should move Install `attachment_minio` and during the installation `base_attachment_object_storage` should move
your existing filestore attachment files into the database or object storage. your existing filestore attachment files into the database or object storage.
For example, you can run a shell command like the following to set the parameter:
```
env['ir.config_parameter'].set_param('ir_attachment.location', 's3')
# If already installed...
# env['ir.attachment'].force_storage()
env.cr.commit()
```
If `attachment_minio` is not already installed, you can then install it and the migration
should be noted in the logs. **Ensure that the timeouts are long enough that the migration can finish.**
""", """,
"summary": "", "summary": "",
"website": "", "website": "",

View File

@@ -15,12 +15,13 @@ class MinioAttachment(models.Model):
@api.model @api.model
def _get_minio_client(self): def _get_minio_client(self):
config = tools.config
params = self.env['ir.config_parameter'].sudo() params = self.env['ir.config_parameter'].sudo()
host = params.get_param('ir_attachment.location.host') host = params.get_param('ir_attachment.location.host') or config.get('attachment_minio_host')
region = params.get_param('ir_attachment.location.region', 'us-west-1') region = params.get_param('ir_attachment.location.region') or config.get('attachment_minio_region', 'us-west-1')
access_key = params.get_param('ir_attachment.location.access_key') access_key = params.get_param('ir_attachment.location.access_key') or config.get('attachment_minio_access_key')
secret_key = params.get_param('ir_attachment.location.secret_key') secret_key = params.get_param('ir_attachment.location.secret_key') or config.get('attachment_minio_secret_key')
secure = params.get_param('ir_attachment.location.secure') secure = params.get_param('ir_attachment.location.secure') or config.get('attachment_minio_secure')
if not all((host, access_key, secret_key)): if not all((host, access_key, secret_key)):
raise exceptions.UserError('Incorrect configuration of attachment_minio.') raise exceptions.UserError('Incorrect configuration of attachment_minio.')
return Minio(host, return Minio(host,
@@ -31,8 +32,9 @@ class MinioAttachment(models.Model):
@api.model @api.model
def _get_minio_bucket(self, client, name=None): def _get_minio_bucket(self, client, name=None):
config = tools.config
params = self.env['ir.config_parameter'].sudo() params = self.env['ir.config_parameter'].sudo()
bucket = name or params.get_param('ir_attachment.location.bucket') bucket = name or params.get_param('ir_attachment.location.bucket') or config.get('attachment_minio_bucket')
if not bucket: if not bucket:
raise exceptions.UserError('Incorrect configuration of attachment_minio -- Missing bucket.') raise exceptions.UserError('Incorrect configuration of attachment_minio -- Missing bucket.')
if not client.bucket_exists(bucket): if not client.bucket_exists(bucket):