要求在带有CI的Docker中运行幻影?

时间:2019-08-15 10:03:39

标签: ruby docker capybara apparition

我正在尝试在CI中的docker中使用水豚和幻影运行rspec测试。我已经安装了google-chrome-stable,但收到疯狂的错误。

如果我只是运行我的rspec,它将启动puma来执行测试,然后再进行10分钟以上的操作。

疯狂的是,如果我添加rspec过滤器或排除模式,我的所有测试规范都会失败,并出现以下错误。

我正在使用最新版本的Rails 6.0.0rc2(rspec-rails,capybara,幽灵)

如果我在CI上运行测试而没有完整的测试,则一切正常。

我搜索了Could not load native IDN implementation.,并试图清除我的CI工作者的缓存,但这没有帮助。

我使用此docker文件构建映像

FROM ruby:2.6-stretch

ENV LANG C.UTF-8

ARG PG_MAJOR=11
ARG NODE_MAJOR=10
ARG BUNDLER_VERSION=2.0.2
ARG YARN_VERSION=1.17.3

# Add PostgreSQL to sources list
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
  && echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list

# Add NodeJS to sources list
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -

# Add Yarn to the sources list
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
  && echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list

# Add chrome keys
RUN curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list

RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
    DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    build-essential \
    ca-certificates \
    curl \
    gnupg \
    gnupg1 \
    patch \
    google-chrome-stable \
    postgresql-client-$PG_MAJOR \
    nodejs \
    xz-utils \
    yarn=$YARN_VERSION-1 \
    zlib1g-dev && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
    truncate -s 0 /var/log/*log && \
    gem update --system && \
    groupadd --gid 1000 node && \
    useradd --uid 1000 --gid node --shell /bin/bash --create-home node

RUN gem update --system && \
    gem install bundler:$BUNDLER_VERSION

RUN mkdir -p /app

WORKDIR /app

这是我的配置项日志

bundle exec rspec --color --tty --tag "~js" .[0;m
Could not load native IDN implementation.

An error occurred while loading ./vendor/ruby/2.6.0/gems/addressable-2.6.0/spec/addressable/rack_mount_compat_spec.rb.
[31mFailure/Error: raise(Bootsnap::LoadPathCache::CoreExt.make_load_error(path))[0m
[31m[0m
[31mLoadError:[0m
[31m  cannot load such file -- rack/mount[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:33:in `require'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/kernel.rb:23:in `require'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/addressable-2.6.0/spec/addressable/rack_mount_compat_spec.rb:23:in `<main>'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/configuration.rb:2053:in `load_file_handling_errors'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/configuration.rb:1560:in `block in load_spec_files'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/configuration.rb:1558:in `each'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/configuration.rb:1558:in `load_spec_files'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/runner.rb:98:in `setup'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/runner.rb:86:in `run'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/runner.rb:71:in `run'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/runner.rb:45:in `invoke'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/exe/rspec:4:in `<top (required)>'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/bin/rspec:23:in `load'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/bin/rspec:23:in `<top (required)>'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:74:in `load'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:74:in `kernel_load'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:28:in `run'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:463:in `exec'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:27:in `dispatch'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:18:in `start'[0m
[36m# /usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'[0m
[36m# /usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'[0m
[36m# /usr/local/bundle/bin/bundle:23:in `load'[0m
[36m# /usr/local/bundle/bin/bundle:23:in `<main>'[0m
[36m# [0m
[36m#   Showing full backtrace because every line was filtered out.[0m
[36m#   See docs for RSpec::Configuration#backtrace_exclusion_patterns and[0m
[36m#   RSpec::Configuration#backtrace_inclusion_patterns for more information.[0m

这是我的配置项日志

bundle exec rspec --color --tty --tag "~js" .[0;m
Could not load native IDN implementation.

An error occurred while loading ./vendor/ruby/2.6.0/gems/addressable-2.6.0/spec/addressable/rack_mount_compat_spec.rb.
[31mFailure/Error: raise(Bootsnap::LoadPathCache::CoreExt.make_load_error(path))[0m
[31m[0m
[31mLoadError:[0m
[31m  cannot load such file -- rack/mount[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:33:in `require'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/zeitwerk-2.1.9/lib/zeitwerk/kernel.rb:23:in `require'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/addressable-2.6.0/spec/addressable/rack_mount_compat_spec.rb:23:in `<main>'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/configuration.rb:2053:in `load_file_handling_errors'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/configuration.rb:1560:in `block in load_spec_files'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/configuration.rb:1558:in `each'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/configuration.rb:1558:in `load_spec_files'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/runner.rb:98:in `setup'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/runner.rb:86:in `run'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/runner.rb:71:in `run'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/lib/rspec/core/runner.rb:45:in `invoke'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/gems/rspec-core-3.8.2/exe/rspec:4:in `<top (required)>'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/bin/rspec:23:in `load'[0m
[36m# /builds/prj/prj/vendor/ruby/2.6.0/bin/rspec:23:in `<top (required)>'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:74:in `load'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:74:in `kernel_load'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli/exec.rb:28:in `run'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:463:in `exec'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:27:in `dispatch'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/cli.rb:18:in `start'[0m
[36m# /usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'[0m
[36m# /usr/local/lib/ruby/site_ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'[0m
[36m# /usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'[0m
[36m# /usr/local/bundle/bin/bundle:23:in `load'[0m
[36m# /usr/local/bundle/bin/bundle:23:in `<main>'[0m
[36m# [0m
[36m#   Showing full backtrace because every line was filtered out.[0m
[36m#   See docs for RSpec::Configuration#backtrace_exclusion_patterns and[0m
[36m#   RSpec::Configuration#backtrace_inclusion_patterns for more information.[0m
...
Run options: exclude {:js=>true}

Randomized with seed 1270


Finished in 6.04 seconds (files took 5.89 seconds to load)
0 examples, 0 failures, 188 errors occurred outside of examples

我只有5个测试示例,所以看起来失败的测试是来自内部的

有什么想法找出为什么我会遇到所有这些疯狂的错误吗?

1 个答案:

答案 0 :(得分:5)

为幻影驱动程序添加browser_options后修复的问题。如果没有--no-sandbox选项,Chrome将无法以root用户身份运行。要添加它,只需像这样初始化驱动程序

Capybara.register_driver :apparition do |app|
  opts = {
    headless: true,
    browser_options: [
      :no_sandbox,
      { disable_features: 'VizDisplayCompositor' },
      :disable_gpu
    ]
  }
  Capybara::Apparition::Driver.new(app, opts)
end