diff --git a/lib/gitlab/qa/component/selenoid.rb b/lib/gitlab/qa/component/selenoid.rb index ceff6a5fafe770dde1f531976922615bc1d0fb3b..20b8dafe338cd1a64c6f651236b322ad1634b95b 100644 --- a/lib/gitlab/qa/component/selenoid.rb +++ b/lib/gitlab/qa/component/selenoid.rb @@ -29,11 +29,15 @@ module Gitlab pull_images docker.run(image: image, tag: tag, args: ['-video-recorder-image', - QA::Runtime::Env.video_recorder_image, + Runtime::Env.video_recorder_image, + '-log-output-dir', + '/opt/selenoid/logs', '-container-network', network, '-timeout', - '10m0s'] + '10m0s', + '-save-all-logs', + 'true'] ) do |command| set_command_args(command) set_volumes(command) @@ -52,6 +56,22 @@ module Gitlab raise "Retried #{max_attempts} times. Selenoid is not responding. Aborting." end + def teardown! + names = [get_video_container_name, get_browser_container_name] + + names.each do |name| + next if name.blank? && !docker.running?(name) + + begin + docker.remove(name) + rescue StandardError => e + QA::Runtime::Logger.warn("Selenoid teardown error: #{e}") + end + end + + super + end + private def grid_healthy? @@ -63,8 +83,8 @@ module Gitlab end def pull_images - docker.pull(image: QA::Runtime::Env.selenoid_browser_image, tag: Runtime::Env.selenoid_browser_version) - docker.pull(image: QA::Runtime::Env.video_recorder_image, tag: QA::Runtime::Env.video_recorder_version) + docker.pull(image: Runtime::Env.selenoid_browser_image, tag: Runtime::Env.selenoid_browser_version) + docker.pull(image: Runtime::Env.video_recorder_image, tag: Runtime::Env.video_recorder_version) end # Set custom run command arguments @@ -72,7 +92,7 @@ module Gitlab # @param [Docker::Command] command # @return [void] def set_command_args(command) - command << '-d ' + command << '-d' command << "--name #{name}" command << "--net #{network}" command << "--hostname #{hostname}" @@ -88,6 +108,21 @@ module Gitlab command.volume('/var/run/docker.sock', '/var/run/docker.sock') command.volume("#{__dir__}/../../../../fixtures/selenoid", "/etc/selenoid") command.volume("#{Runtime::Env.selenoid_directory}/video", '/opt/selenoid/video') + command.volume("#{Runtime::Env.selenoid_directory}/logs", '/opt/selenoid/logs') + end + + def get_video_container_name + docker.ps("-f ancestor='#{Runtime::Env.video_recorder_image}' --format '{{.Names}}'") + end + + def get_browser_container_name + command = <<~CMD.tr("\n", ' ') + -f + ancestor='#{Runtime::Env.selenoid_browser_image}:#{Runtime::Env.selenoid_browser_version}' + --format '{{.Names}}' + CMD + + docker.ps(command) end end end diff --git a/spec/gitlab/qa/component/selenoid_spec.rb b/spec/gitlab/qa/component/selenoid_spec.rb index f4e04439fffac73d869bd5149d7a9277fdb65de6..fa31d7fac57cab5d441a151a940427bf189a87f2 100644 --- a/spec/gitlab/qa/component/selenoid_spec.rb +++ b/spec/gitlab/qa/component/selenoid_spec.rb @@ -51,10 +51,14 @@ module Gitlab expect(docker_engine).to have_received(:run).with({ args: ["-video-recorder-image", video_recorder_image, + '-log-output-dir', + '/opt/selenoid/logs', "-container-network", subject.network, - "-timeout", - "10m0s"], image: "aerokube/selenoid", tag: "latest-release" }) + '-timeout', + '10m0s', + '-save-all-logs', + 'true'], image: "aerokube/selenoid", tag: "latest-release" }) end it 'sets name' do