DEV Community

Cover image for Setting up Minio as a database for Medusajs
Norbert Fuhs
Norbert Fuhs

Posted on

Setting up Minio as a database for Medusajs

In this blogpost you'll learn howto setup Minio as database for Medusa.

Introduction

MinIO is a High Performance Object Storage released under GNU Affero General Public License v3.0. It is API compatible with the Amazon S3 cloud storage service. It can handle unstructured data such as photos, videos, log files, backups, and container images with a current maximum supported object size of 5TB.

As beeing compatible with Amazon S3 Minio is a hot choice as data-storage.

Setup Medusa

First we gonna setup Medusajs. You can follow this Quickstart Guide to do so.

Setup Minio

Minio provides many install options you can refer the Documentation Page.

In this case we decide to install Minio and Medusa on macOS.

We're going to use Homebrew:

brew install minio/stable/minio
Enter fullscreen mode Exit fullscreen mode

Starting the Minio Server:

export MINIO_CONFIG_ENV_FILE=/etc/default/minio
minio server --console-address :9090
Enter fullscreen mode Exit fullscreen mode

Changing Minios port

Minios and Medusajs backend both us the same port 9000 to avoid a collision we're going to change Minios port to 9001.

minio server ~/minio --console-address :9090 --address :9001
Enter fullscreen mode Exit fullscreen mode

Create a Minio bucket

We're going to create a bucket storing the Medusajs backend files.

  1. Log into the Minio Console
  2. Click on the create bucket button
  3. Enter the name of the bucket in the Bucket Namefield
  4. Click on the create bucket button
  5. on the buckets page click on the cog icon on the the top to configure the bucket.
  6. Click on the edit icon next to Access Policy.
  7. Change the selected value to public and click Set.

Generate Access Keys

  1. Click on Access Keys from the Minio Console
  2. Click on the "Create access key" button
  3. Tihs is will open up a form with generated keys click on Create button.

  4. A pop-up will show Access-Key and Secret-Key copy both as we will use them later.

Plugin installation

In the folder of your Medusa backend run the following command:

npm install medusa-file-minio
Enter fullscreen mode Exit fullscreen mode

Then add the following environment variables in .env :

MINIO_ENDPOINT=<ENDPOINT>
MINIO_BUCKET=<BUCKET>
MINIO_ACCESS_KEY=<ACCESS_KEY>
MINIO_SECRET_KEY=<SECRET_KEY>
Enter fullscreen mode Exit fullscreen mode

Finally configure medusa-config.js to include the plugin with required options:

const plugins = [
  // ...
  {
    resolve: `medusa-file-minio`,
    options: {
        endpoint: process.env.MINIO_ENDPOINT,
        bucket: process.env.MINIO_BUCKET,
        access_key_id: process.env.MINIO_ACCESS_KEY,
        secret_access_key: process.env.MINIO_SECRET_KEY,
    },
  },
]
Enter fullscreen mode Exit fullscreen mode

Thats it I hope you enjoyed this blogpost about using Minio as database for a Medusajs backend.

Feel free to follow me on Twitter

Top comments (0)