2016-07-19 48 views
4

我想爲我的Ruby on Rails項目設置Gitlab CI,但遇到了一個我不知道如何解決的錯誤。Gitlab CI設置錯誤 - 無法找到JavaScript運行時

該應用程序運行於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)>' 
+0

已安裝在系統上不過的NodeJS?這是什麼系統? – miccet

+0

@miccet這是系統:https://about.gitlab.com/gitlab-ci/ – Severin

回答

4

您需要javascript運行時(nodejs),安裝它們。

Ubuntu用戶

sudo apt-get install nodejs 

的CentOS/RedHat的用戶

sudo yum install nodejs 

如果您不能安裝nodejs可以使用therubyracer寶石。從庫中說明:

Embed the V8 JavaScript interpreter into Ruby.

此行添加到Gemfile

gem 'therubyracer', platforms: :ruby 
+0

一切都必須在此文件中定義。正如你所看到的,它使用docker包來設置環境。以上內容適用於您有實際訪問權限的系統,但對於此CI服務器(https://about.gitlab.com/gitlab-ci/)並非如此。 – Severin

+0

@Severin,據我瞭解,「碼頭服務」是一個自包含的實例,但是你需要帶有rails的實例'nodejs' –

+0

是的。問題在於,你不能像上面顯示的那樣在Gitlab CI上運行這些設置命令。所以簡單地將它添加到'before_script'部分會給你一個錯誤。你認爲它可以在這個環境中安裝嗎? – Severin

相關問題