我正试图为Ruby on Rails项目设置Gitlab CI,但遇到了一个我不知道如何修复的错误。
该应用程序在Ruby 2.3.1、Rails 5.0上运行,并使用postgreSQL数据库。
我当前的.gitlab.ci.yml文件如下:
# https://hub.docker.com/r/library/ruby/tags/
image: "ruby:2.3.0"
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service
services:
- redis:latest
- postgres:latest
- node:latest
# This is a basic example for a gem or script which doesn't use
# services such as redis or postgres
before_script:
- gem install bundler # Bundler is not installed with the image
- bundle install -j $(nproc) # Install dependencies
rubocop:
script:
- rubocop
rspec:
script:
- rspec spec
rails:
script:
- rails db:migrate
- rspec spec
所以它应该使用NodeJS作为运行时。然而,我得到以下错误:
$ rails db:migrate
rails aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'uglifier'.
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
Backtrace for gem load error is:
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect'
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:5:in `<module:ExecJS>'
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:4:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `require'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `block in require'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:259:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `require'
/usr/local/bundle/gems/uglifier-3.0.0/lib/uglifier.rb:5:in `<top (required)>'
您需要有一个javascript运行时(例如nodejs)。您可以使用以下命令进行安装:
对于Ubuntu用户
sudo apt-get install nodejs
适用于Cents/ReHat用户
sudo yum install nodejs
如果你不能安装nodejs
,你可以安装然后使用therubyracer
-gem。
存储库中的描述:
将V8 JavaScript解释器嵌入Ruby中。
将此行添加到您的Gemfile
gem 'therubyracer', platforms: :ruby
Gitlab CI可以使用文件.gitlab-ci.yml
进行配置,在这种情况下:
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
可以用于在设置阶段(源)上安装CCD_ 5。
一个完整的带有jekyll的before_script
可以看起来像以下代码(例如,这是jekyll minifier所必需的):
image: ruby:latest
variables:
JEKYLL_ENV: production
LC_ALL: C.UTF-8
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- ruby -v
- which ruby
- gem install bundler
- bundle install
test:
stage: test
script:
- bundle exec jekyll build -d test
artifacts:
paths:
- test
except:
- master
pages:
stage: deploy
script:
- bundle exec jekyll build -d public
artifacts:
paths:
- public
only:
- master