Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add. Optional MinIO Service for File Storage #40

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
config.cache_store = :memory_store

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
config.active_storage.service = ENV.fetch("STORAGE_SERVICE", "local")

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# config.asset_host = "http://assets.example.com"

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :amazon
config.active_storage.service = ENV.fetch("STORAGE_SERVICE", "local")

# Assume all access to the app is happening through a SSL-terminating reverse proxy.
config.assume_ssl = true
Expand Down
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
config.action_controller.allow_forgery_protection = false

# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test
config.active_storage.service = ENV.fetch("STORAGE_SERVICE", "local")

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
Expand Down
11 changes: 11 additions & 0 deletions config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ amazon:
secret_access_key: <%= ENV.fetch('AWS_SECRET_ACCESS_KEY') %>
region: <%= ENV.fetch('AWS_REGION') %>
bucket: <%= ENV.fetch('AWS_BUCKET') %>

# Use bin/rails credentials:edit to set the MinIO secrets (as minio:access_key_id|secret_access_key)
minio:
service: S3
bucket: <%= ENV.fetch('MINIO_BUCKET') || 'application' %>
endpoint: <%= ENV.fetch('MINIO_ENDPOINT') || 'https://localhost:9000' %>
access_key_id: <%= ENV.fetch('MINIO_ACCESS_KEY_ID') || 'minioadmin' %>
secret_access_key: <%= ENV.fetch('MINIO_SECRET_ACCESS_KEY') || 'minioadmin' %>
region: <%= ENV.fetch('MINIO_REGION') || 'us-east-1' %>
force_path_style: true

# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
Expand Down
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ services:
AWS_REGION: ${AWS_REGION}
AWS_BUCKET: ${AWS_BUCKET}
PLUGIN_BASE_URL: ${PLUGIN_BASE_URL}
MINIO_BUCKET: ${MINIO_BUCKET}
MINIO_ACCESS_KEY_ID: ${MINIO_ACCESS_KEY_ID}
MINIO_SECRET_ACCESS_KEY: ${MINIO_SECRET_ACCESS_KEY}
MINIO_ENDPOINT: ${MINIO_ENDPOINT}
MINIO_REGION: ${MINIO_REGION}
volumes:
- .:/app:cached
ports:
Expand All @@ -49,6 +54,22 @@ services:
medispeak_db:
condition: service_healthy
restart: unless-stopped

minio:
profiles:
- "minio"
image: bitnami/minio
ports:
- '9000:9000'
- '9001:9001'
volumes:
- 'minio:/bitnami/minio/data'
environment:
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin
- MINIO_DEFAULT_BUCKETS=application
volumes:
medispeak_data:
driver: local
minio:
driver: local
43 changes: 43 additions & 0 deletions docs/docker_setup_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,49 @@ For production deployments, ensure the following:

---

## 7. Optional MinIO Setup for File Storage

In addition to using AWS S3 for file storage, Medispeak can be configured to use MinIO as an alternative. MinIO is an open-source object storage service that is fully compatible with the AWS S3 API. This section will guide you through setting up MinIO as the file storage service for the Medispeak backend using Docker Compose.

### 7.1 Environment Variables for MinIO

To configure MinIO as the file storage service, you'll need to update your `.env` file with the following environment variables:

```bash
# MinIO credentials for file storage (required only for production)
# These are needed to configure Active Storage with MinIO, an S3-compatible object storage service.
MINIO_ACCESS_KEY_ID=your_minio_access_key_id
MINIO_SECRET_ACCESS_KEY=your_minio_secret_access_key
MINIO_ENDPOINT=https://your_minio_endpoint.com
MINIO_BUCKET=your_minio_bucket_name
MINIO_REGION=your_minio_region
```

> **Note**: Replace `your_minio_access_key_id`, `your_minio_secret_access_key`, and `your_minio_bucket_name` with the actual credentials for your MinIO instance. The `MINIO_ENDPOINT` should point to the local MinIO service running on port 9000.

### 7.2 Switching Between AWS and MinIO

You can switch between AWS and MinIO by modifying the `STORAGE_SERVICE` environment variable in the `.env` file:

```bash
# Default Storage Service
STORAGE_SERVICE=minio # Set to 'amazon' for AWS S3 or 'local' for local storage
```

When `STORAGE_SERVICE=minio`, the application will use MinIO for file storage. If you'd like to switch back to AWS S3, simply change the value to `amazon`.

### 7.3 Running the Application with MinIO

After configuring MinIO, you can bring up the services, including the MinIO service, by running:

```bash
docker-compose --profile minio up -d
```

> **Note**: The `--profile minio` flag ensures that the MinIO service is only brought up when needed, and the environment variables are properly set.

---

## Conclusion

By following this guide, you can get the Medispeak backend and its PostgreSQL database up and running using Docker Compose. The environment is flexible, allowing you to adjust configurations via environment variables and scale for both development and production needs.
44 changes: 29 additions & 15 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
# Docker Compose Variables (e.g., minio)
COMPOSE_PROFILES=

# Credentials for using Open AI
OPENAI_ACCESS_TOKEN=token_from_open_ai
OPENAI_ORGANIZATION_ID=org_id_for_open_ai

# Base URL for pulling the plugin
PLUGIN_BASE_URL=https://medispeak-app.pages.dev

# Rails Environment Variables
RAILS_ENV=
BUNDLE_DEPLOYMENT=
BUNDLE_PATH=
BUNDLE_WITHOUT=
RAILS_MASTER_KEY=
BACKEND_PORT=
# Essential configuration variables for running the Rails application.
RAILS_ENV= # The environment in which the app is running (e.g., development, production)
BUNDLE_DEPLOYMENT= # Ensures gems are only installed via bundle in deployment mode
BUNDLE_PATH= # Path where bundled gems are installed
BUNDLE_WITHOUT= # Exclude certain groups when installing gems
RAILS_MASTER_KEY= # The key used for decrypting Rails credentials
BACKEND_PORT= # Port where the Rails backend will be running

# Default Storage Service
STORAGE_SERVICE= # This specifies the storage service to be used (minio, amazon, local, etc.).

# AWS credentials for file storage (required only for production)
# These variables are used to configure Active Storage with AWS S3 for file storage in production.
AWS_ACCESS_KEY_ID=your_aws_access_key_id
AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
AWS_REGION=your_aws_region
AWS_BUCKET=your_aws_s3_bucket_name

# AWS credentials for file storage, required only for production
# https://guides.rubyonrails.org/active_storage_overview.html
AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY
AWS_REGION=AWS_REGION
AWS_BUCKET=AWS_BUCKET
# MinIO credentials for file storage (required only for production)
# These are needed to configure Active Storage with MinIO, an S3-compatible object storage service.
MINIO_ACCESS_KEY_ID=your_minio_access_key_id
MINIO_SECRET_ACCESS_KEY=your_minio_secret_access_key
MINIO_ENDPOINT=https://your_minio_endpoint.com
MINIO_BUCKET=your_minio_bucket_name
MINIO_REGION=your_minio_region

# Database Configuration (Required)
# Essential for configuring the PostgreSQL database connection for the Rails app.
POSTGRES_IMAGE_TAG=14.2-alpine
DB_NAME=medispeak
DB_NAME_TEST=medispeak_test
DB_HOST=medispeak_db
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_PORT=5432
DB_PORT=5432
Loading