class Gitlab::QA::Component::InternetTunnel

Constants

DOCKER_IMAGE
DOCKER_IMAGE_TAG

Attributes

gitlab_hostname[W]

Public Class Methods

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

  key_dir = ENV['CI_PROJECT_DIR'] || Dir.tmpdir
  @ssh_key = Tempfile.new('tunnel-ssh-private-key', key_dir)
  @ssh_key.write(ENV.fetch('TUNNEL_SSH_PRIVATE_KEY'))
  @ssh_key.close

  File.chmod(0o600, @ssh_key.path)

  @volumes['/root/.ssh/id_rsa'] = @ssh_key.path
end

Public Instance Methods

instance() click to toggle source
Calls superclass method Gitlab::QA::Component::Base#instance
# File lib/gitlab/qa/component/internet_tunnel.rb, line 25
def instance
  raise 'Please provide a block!' unless block_given?

  super
end
url() click to toggle source
# File lib/gitlab/qa/component/internet_tunnel.rb, line 31
def url
  "https://#{subdomain}.#{tunnel_server_hostname}"
end

Private Instance Methods

name() click to toggle source
# File lib/gitlab/qa/component/internet_tunnel.rb, line 37
def name
  @name ||= "ssh-tunnel-#{SecureRandom.hex(4)}"
end
start() click to toggle source
# File lib/gitlab/qa/component/internet_tunnel.rb, line 49
def start
  raise "Must set gitlab_hostname" unless @gitlab_hostname

  @docker.run(
    image: DOCKER_IMAGE,
    tag: DOCKER_IMAGE_TAG,
    args: ["-o StrictHostKeyChecking=no -N -R #{subdomain}:#{@gitlab_hostname}:80 #{ENV.fetch('TUNNEL_SSH_USER')}@#{tunnel_server_hostname}"]) do |command|
    command << '-d '
    command << "--name #{name}"
    command << "--net #{network}"

    @volumes.to_h.each do |to, from|
      command.volume(from, to, 'Z')
    end
  end
end
subdomain() click to toggle source
# File lib/gitlab/qa/component/internet_tunnel.rb, line 45
def subdomain
  @subdomain ||= rand(30_000..49_000)
end
teardown() click to toggle source
Calls superclass method Gitlab::QA::Component::Base#teardown
# File lib/gitlab/qa/component/internet_tunnel.rb, line 66
def teardown
  super

  @ssh_key.unlink
end
tunnel_server_hostname() click to toggle source
# File lib/gitlab/qa/component/internet_tunnel.rb, line 41
def tunnel_server_hostname
  ENV.fetch("TUNNEL_SERVER_HOSTNAME")
end