Sha256: 15e4ad8b234484a98fa161651e5a925aaf7a9b45a7e09f4b78cb7a21fbd3071c

Contents?: true

Size: 1.72 KB

Versions: 37

Compression:

Stored size: 1.72 KB

Contents

# This component sets up the MailHog (https://github.com/mailhog/MailHog)
# image with the proper configuration for SMTP email delivery from Gitlab

module Gitlab
  module QA
    module Component
      class MailHog
        include Scenario::Actable

        MAILHOG_IMAGE = 'mailhog/mailhog'.freeze
        MAILHOG_IMAGE_TAG = 'v1.0.0'.freeze

        attr_reader :docker
        attr_accessor :environment, :network
        attr_writer :name

        def initialize
          @docker = Docker::Engine.new
          @environment = {}
        end

        def name
          @name ||= "mailhog"
        end

        def hostname
          "#{name}.#{network}"
        end

        def instance
          raise 'Please provide a block!' unless block_given?

          prepare
          start

          yield self
        ensure
          teardown
        end

        def prepare
          @docker.pull(MAILHOG_IMAGE, MAILHOG_IMAGE_TAG)

          return if @docker.network_exists?(network)

          @docker.network_create(network)
        end

        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 restart
          @docker.restart(name)
        end

        def teardown
          raise 'Invalid instance name!' unless name

          @docker.stop(name)
          @docker.remove(name)
        end

        def set_mailhog_hostname
          ::Gitlab::QA::Runtime::Env.mailhog_hostname = hostname
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
gitlab-qa-5.13.6 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.13.3 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.13.2 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.13.1 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.13.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.12.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.10.1 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.10.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.9.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.8.1 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.8.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.7.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.6.1 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.6.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.5.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.4.3 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.4.2 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.4.1 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.4.0 lib/gitlab/qa/component/mail_hog.rb
gitlab-qa-5.3.0 lib/gitlab/qa/component/mail_hog.rb