【发布时间】:2020-10-10 22:23:50
【问题描述】:
我正在使用npm 在我的项目中安装 Node.js 依赖项。我想在部署到 Heroku 时全局缓存 Node.js 包 (node_modules) 以加快管道中的作业。来自GitLab官方docs的例子:
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .npm/
before_script:
- npm ci --cache .npm --prefer-offline
这是 GitLab 中的另一个 example:
cache:
paths:
- node_modules/
找到了一些使用上述第二种配置的文章(Deploy Node.js App with GitLab CI/CD、Continuous Integration with Node.js, Heroku and GitLab CI/CD -Part 2)。我确实试了一下,我能够使用这些设置成功地将我的应用程序部署到 Heroku。但我不确定缓存机制是否正常工作。
这些配置有什么区别?哪种缓存 Node.js 包最方便?
我当前对gitlab-ci.yml 文件的设置:
image: node:latest
cache:
paths:
- node_modules/
stages:
- build
- deploy
build:
stage: build
script:
- npm i
- npm i -g gulp-cli
- gulp build
deploy:
image: ruby:latest
stage: deploy
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_API_KEY
only:
- master
不确定我的做法是否正确。
【问题讨论】:
标签: node.js npm gitlab gitlab-ci gitlab-ci-runner