用npm设置Rails的GitLab CI
这些天,我正在为我的项目而苦恼于GitLab CI设置。 这个设置并不像Travis CI那么简单。 我花了很多时间debugging这个,所有我发现不符合我的要求
上下文
我有一个使用rvm
和npm
和postgresql
的Rails项目。 我用rvm
和npm
安装了一个定制的Docker镜像。 但是,在运行之前,我必须得到我的.gitlab-ci.yml
相应的ruby
和node
版本:
image: "my-rvm-npm-image" services: - postgres:9.3-alpine variables: POSTGRES_DB: db POSTGRES_USER: user POSTGRES_PASSWORD: cache: untracked: true key: "$CI_BUILD_REF_NAME" paths: - node_modules/ stages: - build - rspec - npm build: stage: build script: - sudo chown -R $(whoami) /cache - /bin/bash -l -c "rvm install $(cat .ruby-version) && rvm use $(cat .ruby-version) && gem install bundle && bundle install --jobs $(nproc) --path /cache && source ~/.nvm/nvm.sh && nvm install && npm install npm -g && npm install && bundle exec rake db:test:prepare" rspec: stage: rspec script: - bundle exec rake npm: stage: npm script: - npm test
请注意,这个.gitlab-ci.yml
文件仍然failed
。 在GitLab运行器configuration中, bundle install
将位于/cache
中:
[[runners]] name = "xxxx" url = "URLabc.com" token = "myprojectoken" executor = "docker" [runners.docker] tls_verify = false image = "my-rvm-npm-image" privileged = true disable_cache = false volumes = ["/home/ci/cache:/cache", "/home/ci/builds:/builds"] [runners.cache]
builds
和cache
文件夹是主机绑定的。 这样我可以保留下一个版本的bundle install
cache。
我的问题
build
工作通行证,但是rspec
和npm
失败/bin/bash: bundle: command not found
。 看来这个bundle
不会传递给其他工作。 我知道我应该使用artifacts
传递给其他工作,但我已经把它作为caching,我应该有
我想实现这些目标:
- 每次运行caching
bundle install
,因为从头开始需要rspec
分钟的时间来重build,并传递给rspec
作业来运行testing。 - 还从
npm install
cachingnode_modules
并传递给npm
作业。 - 任何关于
rvm
和npm
安装的build议,因为我不想在每个命令之前使用丑陋的方式bash -l -c
。
- Gitlab docker执行程序 – 在before_script之后caching图像
- 在Docker上使用caching的Gitlab CI runnerconfiguration
- Maven安装文件在GitLab / Docker中无效:“无法parsing项目的依赖关系”
- GitLab CI – 无法从映像中连接到Docker守护进程
- 使用Gitlab CD和Docker
- GitLab使用gitlab-runner进行本地构build
- 我如何使用git客户端来访问gitlab docker?
- 将环境variables从Gitlab docker执行程序传递到image
- 什么是特殊的gitlab-ci-token用户?