From ffc0c86f36b25824aa3f6b51f4597c1cbdbe08c6 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 14 Oct 2025 18:52:01 -0400 Subject: [PATCH] Minio support in development for when we need to debug direct upload problems --- bin/minio-setup | 40 ++++++++++++++++++++++++++++++ bin/setup | 6 +++++ config/environments/development.rb | 6 ++++- config/storage.yml | 11 ++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100755 bin/minio-setup diff --git a/bin/minio-setup b/bin/minio-setup new file mode 100755 index 000000000..081db95db --- /dev/null +++ b/bin/minio-setup @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby +# +# Make sure the bucket we rely upon in development exists. +# Configuration and credentials are in config/storage.yml +# +require_relative "../config/environment" +require "aws-sdk-s3" + +# Load storage configuration +storage_config = YAML.load(ERB.new(File.read("config/storage.yml")).result) +minio_config = storage_config["devminio"] + +bucket_name = minio_config["bucket"] +endpoint = minio_config["endpoint"] +access_key = minio_config["access_key_id"] +secret_key = minio_config["secret_access_key"] +region = minio_config["region"] + +# Create S3 client +s3_client = Aws::S3::Client.new( + endpoint: endpoint, + access_key_id: access_key, + secret_access_key: secret_key, + region: region, + force_path_style: minio_config["force_path_style"] +) + +# Check if bucket exists +begin + s3_client.head_bucket(bucket: bucket_name) + puts "Bucket '#{bucket_name}' already exists" +rescue Aws::S3::Errors::NotFound + # Create the bucket + puts "Creating bucket '#{bucket_name}'..." + s3_client.create_bucket(bucket: bucket_name) + puts "Successfully created bucket '#{bucket_name}'" +rescue => e + puts "Error checking/creating bucket: #{e.message}" + exit 1 +end diff --git a/bin/setup b/bin/setup index c1466d58c..f2a2d9737 100755 --- a/bin/setup +++ b/bin/setup @@ -52,6 +52,12 @@ fi bundle config set --local auto_install true step "Installing RubyGems" bundle install +if [ -e tmp/minio-dev.txt ] ; then + step "Starting Docker services" bash -c "[ -d ~/Work/basecamp/docker-dev ] && git -C ~/Work/basecamp/docker-dev pull || gh repo clone basecamp/docker-dev ~/Work/basecamp/docker-dev && ~/Work/basecamp/docker-dev/setup minio" + + step "Configuring MinIO" bin/minio-setup +fi + if [[ $* == *--reset* ]]; then step "Resetting the database" rails db:reset else diff --git a/config/environments/development.rb b/config/environments/development.rb index 4606d6e6d..a87ef7843 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -32,7 +32,11 @@ Rails.application.configure do end # Store uploaded files on the local file system (see config/storage.yml for options). - config.active_storage.service = :local + if Rails.root.join("tmp/minio-dev.txt").exist? + config.active_storage.service = :devminio + else + config.active_storage.service = :local + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false diff --git a/config/storage.yml b/config/storage.yml index 19b48b07f..62fd8b002 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -6,6 +6,17 @@ local: service: Disk root: <%= Rails.root.join("storage", "tenants", Rails.env, "%{tenant}", "files") %> +devminio: + service: S3 + bucket: fizzy-dev-activestorage + endpoint: "http://minio.localhost:39000" + force_path_style: true + request_checksum_calculation: when_required # default is when_supported with CRC64NVME checksum which FlashBlade doesn't support + response_checksum_validation: when_required # default is when_supported with CRC64NVME checksum which FlashBlade doesn't support + region: us-east-1 # default region required for signer + access_key_id: minioadmin + secret_access_key: minioadmin + # We have "development", "staging", and "production" buckets configured. Note that we don't have a # "beta" bucket. (As of 2025-06-01.) purestorage: