class Gitlab::QA::Component::MailHog
def hostname
def hostname "#{name}.#{network}" end
def initialize
def initialize @docker = Docker::Engine.new @environment = {} end
def instance
def instance raise 'Please provide a block!' unless block_given? prepare start yield self ensure teardown end
def name
def name @name ||= "mailhog" end
def prepare
def prepare @docker.pull(MAILHOG_IMAGE, MAILHOG_IMAGE_TAG) return if @docker.network_exists?(network) @docker.network_create(network) end
def restart
def restart @docker.restart(name) end
def set_mailhog_hostname
def set_mailhog_hostname ::Gitlab::QA::Runtime::Env.mailhog_hostname = hostname end
def start
def start docker.run(MAILHOG_IMAGE, MAILHOG_IMAGE_TAG) do |command| command << '-d ' command << "--name #{name}" command << "--net #{network}" command << "--hostname #{hostname}" command << "--publish 1025:1025" command << "--publish 8025:8025" end end
def teardown
def teardown raise 'Invalid instance name!' unless name @docker.stop(name) @docker.remove(name) end