如何在gitlab-ci中缓存

问题描述 投票:3回答:1

我应该如何在gitlab-ci中缓存scala项目的coursier依赖项。我正在使用docker executor。

*去 - 8.4.2

Gitlab亚军 - 1.0.4 *

我的/etc/gitlab-runner/config.toml

  [runners.docker]
    image = "docker.**.com/docker:latest"
    privileged = false
    disable_cache = false
    volumes = [
      "/cache",
      "/var/run/docker.sock:/var/run/docker.sock",
      "/data/gitlab-runner/ansible_vault_password.txt:/etc/ansible_vault_password.txt:ro",
    ]

gitlab-ci.yml文件包含

stages:
  - build
  - test
  - publish
  - cleanup

create:
  type: build
  script:
    - docker build --rm --pull -t docker.**.com/sbt:latest -f Dockerfile .
    - docker images

lint:
  type: test
  image: docker.***.com/sbt
  script:
    - sbt scalastyle
    - sbt scalafmtTest

unit tests:
  type: test
  image: docker.**.com/sbt
  script:
    - sbt test

publish jar:
  type: publish
  image: docker.**.com/sbt
  script:
    - sbt assembly
    - sbt publish
  only:
    - master

remove containers:
  type: cleanup
  script:
    - docker rmi -f docker.**.com/sbt:latest
  when: always

插件文件包含

addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.4.8")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M14")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.1")

有任何建议或提示吗?

scala gitlab-ci gitlab-ci-runner
1个回答
3
投票

你需要在你的Gitlab Runner上启用缓存(看起来你已经有了)。从那里,您需要在cache文件中添加.gitlab-ci.yml密钥。我不确定sbt默认放置缓存目录的位置,但你几乎肯定要更改它以便它在工作区目录中。

请参阅https://docs.gitlab.com/ce/ci/yaml/#cache获取完整指南,但我想你会做类似的事情:

stages:
  - build
  - test
  - publish
  - cleanup

cache:
  paths:
  - cache/sbt

create:
  type: build
  script:
    - docker build --rm --pull -t docker.xxx.com/sbt:latest -f Dockerfile .
    - docker images
...

其中cache/sbt是相对于包含sbt缓存的源文件夹的路径。您只能使用项目工作区内的路径进行缓存。

© www.soinside.com 2019 - 2024. All rights reserved.