class Gitlab::QA::Component::Minio

Constants

AWS_ACCESS_KEY

These are secrets used in a local Minio container, they're not used for any online S3 server.

AWS_SECRET_KEY
DATA_DIR
DEFAULT_PORT
DOCKER_IMAGE
DOCKER_IMAGE_TAG

Public Class Methods

new() click to toggle source
Calls superclass method Gitlab::QA::Component::Base::new
# File lib/gitlab/qa/component/minio.rb, line 19
def initialize
  super

  @environment = { MINIO_ACCESS_KEY: AWS_ACCESS_KEY, MINIO_SECRET_KEY: AWS_SECRET_KEY }
  @volumes = { host_data_dir => DATA_DIR }
  @buckets = []
end

Public Instance Methods

add_bucket(name) click to toggle source
# File lib/gitlab/qa/component/minio.rb, line 27
def add_bucket(name)
  @buckets << name
end
to_config() click to toggle source
# File lib/gitlab/qa/component/minio.rb, line 31
        def to_config
          YAML.safe_load <<~CFG
            provider: AWS
            aws_access_key_id: #{AWS_ACCESS_KEY}
            aws_secret_access_key: #{AWS_SECRET_KEY}
            aws_signature_version: 4
            host: #{hostname}
            endpoint: http://#{hostname}:#{port}
            path_style: true
          CFG
        end

Private Instance Methods

host_data_dir() click to toggle source
# File lib/gitlab/qa/component/minio.rb, line 45
def host_data_dir
  base_dir = ENV['CI_PROJECT_DIR'] || '/tmp'

  File.join(base_dir, 'minio')
end
name() click to toggle source
# File lib/gitlab/qa/component/minio.rb, line 51
def name
  @name ||= "minio-#{SecureRandom.hex(4)}"
end
port() click to toggle source
# File lib/gitlab/qa/component/minio.rb, line 55
def port
  DEFAULT_PORT
end
prepare() click to toggle source
Calls superclass method Gitlab::QA::Component::Base#prepare
# File lib/gitlab/qa/component/minio.rb, line 59
def prepare
  super

  FileUtils.mkdir_p(host_data_dir)

  @buckets.each do |bucket|
    puts "Creating Minio bucket: #{bucket}"
    FileUtils.mkdir_p(File.join(host_data_dir, bucket))
  end
end
start() click to toggle source
# File lib/gitlab/qa/component/minio.rb, line 70
def start # rubocop:disable Metrics/AbcSize
  # --compat needed until https://gitlab.com/gitlab-org/gitlab-workhorse/issues/210
  # is resolved
  docker.run(image: image, tag: tag, args: ["server", "--compat", DATA_DIR]) do |command|
    command << '-d '
    command << "--name #{name}"
    command << "--net #{network}"
    command << "--hostname #{hostname}"

    @volumes.to_h.each do |to, from|
      command.volume(to, from, 'Z')
    end

    @environment.to_h.each do |key, value|
      command.env(key, value)
    end

    @network_aliases.to_a.each do |network_alias|
      command << "--network-alias #{network_alias}"
    end
  end
end