Fix ExternallyStoredField with file_store = 2 (REMOTE)

What does this MR do and why?

Fix ExternallyStoredField with file_store = 2 (REMOTE).

Because we're avoiding CarrierWave's on_mount machinery to avoid wasted databased columns, we need to redo some bits carefully ourselves.

References

Closes Agent plan storage doesn't work when file_store... (#600373 - closed).

How to set up and validate locally

We need to use object storage locally to test, so we'll enable it in our GDK. Disable after if you don't want to keep running MinIO.

  1. gdk config set object_store.enabled true && gdk reconfigure && gdk restart
  2. GDK won't create the agent-plan-content bucket for you automatically (yet: #600508 (closed)), so create it manually. Go to http://gdk.test:9002/ (login minio / gdk-minio) and create a new bucket called agent-plan-content; no other special adjustments necessary.
  3. GDK also doesn't know how to template the config for it, so now we manually edit config/gitlab.yml and add a block like this (under the production: block):
    agent_plan_content:
      object_store:
        enabled: true
        direct_upload: true
        remote_directory: agent-plan-content
        connection:
          provider: AWS
          aws_access_key_id: minio
          aws_secret_access_key: gdk-minio
          region: gdk
          endpoint: 'http://gdk.test:9000'
          path_style: true
  4. Validate with rails runner or at rails console:
    user = User.first
    project = Project.first
    wi = WorkItems::CreateService.new(
      container: project,
      current_user: user,
      params: {
        title: 'agent plan host',
        work_item_type: WorkItems::TypesFramework::Provider.new.find_by_base_type(:issue)
      }
    ).execute[:work_item]
    
    ap = WorkItems::AgentPlan.create!(work_item: wi, content: 'hello from remote')
    puts "file_store after save: #{ap.reload[:file_store]} (expect 2)"
    puts "content after reload:  #{ap.content.inspect} (expect 'hello from remote')"
  5. You should see:
    file_store after save: 2 (expect 2)
    content after reload:  "hello from remote" (expect 'hello from remote')
    You can also look in the MinIO console and see the created object!
    image

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Asherah Connor

Merge request reports

Loading