Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
35f4a00f
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
35f4a00f
编写于
6月 27, 2017
作者:
N
Nick Thomas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce cache policies for CI jobs
上级
98768953
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
120 addition
and
26 deletion
+120
-26
changelogs/unreleased/33772-readonly-gitlab-ci-cache.yml
changelogs/unreleased/33772-readonly-gitlab-ci-cache.yml
+4
-0
doc/ci/yaml/README.md
doc/ci/yaml/README.md
+47
-0
lib/api/entities.rb
lib/api/entities.rb
+1
-1
lib/gitlab/ci/config/entry/cache.rb
lib/gitlab/ci/config/entry/cache.rb
+12
-2
spec/factories/ci/builds.rb
spec/factories/ci/builds.rb
+2
-1
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+6
-3
spec/lib/gitlab/ci/config/entry/cache_spec.rb
spec/lib/gitlab/ci/config/entry/cache_spec.rb
+40
-12
spec/lib/gitlab/ci/config/entry/global_spec.rb
spec/lib/gitlab/ci/config/entry/global_spec.rb
+4
-4
spec/lib/gitlab/ci/config/entry/job_spec.rb
spec/lib/gitlab/ci/config/entry/job_spec.rb
+2
-2
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+2
-1
未找到文件。
changelogs/unreleased/33772-readonly-gitlab-ci-cache.yml
0 → 100644
浏览文件 @
35f4a00f
---
title
:
Introduce cache policies for CI jobs
merge_request
:
12483
author
:
doc/ci/yaml/README.md
浏览文件 @
35f4a00f
...
...
@@ -306,6 +306,53 @@ cache:
untracked
:
true
```
### cache:policy
> Introduced in GitLab 9.4.
The default behaviour of a caching job is to download the files at the start of
execution, and to re-upload them at the end. This allows any changes made by the
job to be persisted for future runs, and is known as the
`pull-push`
cache
policy.
If you know the job doesn't alter the cached files, you can skip the upload step
by setting
`policy: pull`
in the job specification. Typically, this would be
twinned with an ordinary cache job at an earlier stage to ensure the cache
is updated from time to time:
```
yaml
stages
:
-
setup
-
test
prepare
:
stage
:
setup
cache
:
key
:
gems
paths
:
-
vendor/bundle
script
:
-
bundle install --deployment
rspec
:
stage
:
test
cache
:
key
:
gems
paths
:
-
vendor/bundle
policy
:
pull
script
:
-
bundle exec rspec ...
```
This helps to speed up job execution and reduce load on the cache server,
especially when you have a large number of cache-using jobs executing in
parallel.
Additionally, if you have a job that unconditionally recreates the cache without
reference to its previous contents, you can use
`policy: push`
in that job to
skip the download step.
## Jobs
`.gitlab-ci.yml`
allows you to specify an unlimited number of jobs. Each job
...
...
lib/api/entities.rb
浏览文件 @
35f4a00f
...
...
@@ -831,7 +831,7 @@ module API
end
class
Cache
<
Grape
::
Entity
expose
:key
,
:untracked
,
:paths
expose
:key
,
:untracked
,
:paths
,
:policy
end
class
Credentials
<
Grape
::
Entity
...
...
lib/gitlab/ci/config/entry/cache.rb
浏览文件 @
35f4a00f
...
...
@@ -7,11 +7,14 @@ module Gitlab
#
class
Cache
<
Node
include
Configurable
include
Attributable
ALLOWED_KEYS
=
%i[key untracked paths]
.
freeze
ALLOWED_KEYS
=
%i[key untracked paths policy]
.
freeze
DEFAULT_POLICY
=
'pull-push'
.
freeze
validations
do
validates
:config
,
allowed_keys:
ALLOWED_KEYS
validates
:policy
,
inclusion:
{
in:
%w[pull-push push pull]
,
message:
'should be pull-push, push, or pull'
},
allow_blank:
true
end
entry
:key
,
Entry
::
Key
,
...
...
@@ -25,8 +28,15 @@ module Gitlab
helpers
:key
attributes
:policy
def
value
super
.
merge
(
key:
key_value
)
result
=
super
result
[
:key
]
=
key_value
result
[
:policy
]
=
policy
||
DEFAULT_POLICY
result
end
end
end
...
...
spec/factories/ci/builds.rb
浏览文件 @
35f4a00f
...
...
@@ -207,7 +207,8 @@ FactoryGirl.define do
cache:
{
key:
'cache_key'
,
untracked:
false
,
paths:
[
'vendor/*'
]
paths:
[
'vendor/*'
],
policy:
'pull-push'
}
}
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
浏览文件 @
35f4a00f
...
...
@@ -878,7 +878,8 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'key'
key:
'key'
,
policy:
'pull-push'
)
end
...
...
@@ -896,7 +897,8 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'key'
key:
'key'
,
policy:
'pull-push'
)
end
...
...
@@ -915,7 +917,8 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"test/"
],
untracked:
false
,
key:
'local'
key:
'local'
,
policy:
'pull-push'
)
end
end
...
...
spec/lib/gitlab/ci/config/entry/cache_spec.rb
浏览文件 @
35f4a00f
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Cache
do
le
t
(
:entry
)
{
described_class
.
new
(
config
)
}
subjec
t
(
:entry
)
{
described_class
.
new
(
config
)
}
describe
'validations'
do
before
do
...
...
@@ -9,22 +9,44 @@ describe Gitlab::Ci::Config::Entry::Cache do
end
context
'when entry config value is correct'
do
let
(
:policy
)
{
nil
}
let
(
:config
)
do
{
key:
'some key'
,
untracked:
true
,
paths:
[
'some/path/'
]
}
paths:
[
'some/path/'
],
policy:
policy
}
end
describe
'#value'
do
it
'returns hash value'
do
expect
(
entry
.
value
).
to
eq
config
expect
(
entry
.
value
).
to
eq
(
key:
'some key'
,
untracked:
true
,
paths:
[
'some/path/'
],
policy:
'pull-push'
)
end
end
describe
'#valid?'
do
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
it
{
is_expected
.
to
be_valid
}
end
context
'policy is pull-push'
do
let
(
:policy
)
{
'pull-push'
}
it
{
is_expected
.
to
be_valid
}
it
{
expect
(
entry
.
value
).
to
include
(
policy:
'pull-push'
)
}
end
context
'policy is push'
do
let
(
:policy
)
{
'push'
}
it
{
is_expected
.
to
be_valid
}
it
{
expect
(
entry
.
value
).
to
include
(
policy:
'push'
)
}
end
context
'policy is pull'
do
let
(
:policy
)
{
'pull'
}
it
{
is_expected
.
to
be_valid
}
it
{
expect
(
entry
.
value
).
to
include
(
policy:
'pull'
)
}
end
context
'when key is missing'
do
...
...
@@ -44,12 +66,20 @@ describe Gitlab::Ci::Config::Entry::Cache do
context
'when entry value is not correct'
do
describe
'#errors'
do
subject
{
entry
.
errors
}
context
'when is not a hash'
do
let
(
:config
)
{
'ls'
}
it
'reports errors with config value'
do
expect
(
entry
.
errors
)
.
to
include
'cache config should be a hash'
is_expected
.
to
include
'cache config should be a hash'
end
end
context
'when policy is unknown'
do
let
(
:config
)
{
{
policy:
"unknown"
}
}
it
'reports error'
do
is_expected
.
to
include
(
'cache policy should be pull-push, push, or pull'
)
end
end
...
...
@@ -57,8 +87,7 @@ describe Gitlab::Ci::Config::Entry::Cache do
let
(
:config
)
{
{
key:
1
}
}
it
'reports error with descendants'
do
expect
(
entry
.
errors
)
.
to
include
'key config should be a string or symbol'
is_expected
.
to
include
'key config should be a string or symbol'
end
end
...
...
@@ -66,8 +95,7 @@ describe Gitlab::Ci::Config::Entry::Cache do
let
(
:config
)
{
{
invalid:
true
}
}
it
'reports error with descendants'
do
expect
(
entry
.
errors
)
.
to
include
'cache config contains unknown keys: invalid'
is_expected
.
to
include
'cache config contains unknown keys: invalid'
end
end
end
...
...
spec/lib/gitlab/ci/config/entry/global_spec.rb
浏览文件 @
35f4a00f
...
...
@@ -143,7 +143,7 @@ describe Gitlab::Ci::Config::Entry::Global do
describe
'#cache_value'
do
it
'returns cache configuration'
do
expect
(
global
.
cache_value
)
.
to
eq
(
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
])
.
to
eq
(
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
,
policy:
'pull-push'
)
end
end
...
...
@@ -157,7 +157,7 @@ describe Gitlab::Ci::Config::Entry::Global do
image:
{
name:
'ruby:2.2'
},
services:
[{
name:
'postgres:9.1'
},
{
name:
'mysql:5.5'
}],
stage:
'test'
,
cache:
{
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
},
cache:
{
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
,
policy:
'pull-push'
},
variables:
{
'VAR'
=>
'value'
},
ignore:
false
,
after_script:
[
'make clean'
]
},
...
...
@@ -168,7 +168,7 @@ describe Gitlab::Ci::Config::Entry::Global do
image:
{
name:
'ruby:2.2'
},
services:
[{
name:
'postgres:9.1'
},
{
name:
'mysql:5.5'
}],
stage:
'test'
,
cache:
{
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
},
cache:
{
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
,
policy:
'pull-push'
},
variables:
{},
ignore:
false
,
after_script:
[
'make clean'
]
}
...
...
@@ -212,7 +212,7 @@ describe Gitlab::Ci::Config::Entry::Global do
describe
'#cache_value'
do
it
'returns correct cache definition'
do
expect
(
global
.
cache_value
).
to
eq
(
key:
'a'
)
expect
(
global
.
cache_value
).
to
eq
(
key:
'a'
,
policy:
'pull-push'
)
end
end
end
...
...
spec/lib/gitlab/ci/config/entry/job_spec.rb
浏览文件 @
35f4a00f
...
...
@@ -109,7 +109,7 @@ describe Gitlab::Ci::Config::Entry::Job do
it
'overrides global config'
do
expect
(
entry
[
:image
].
value
).
to
eq
(
name:
'some_image'
)
expect
(
entry
[
:cache
].
value
).
to
eq
(
key:
'test'
)
expect
(
entry
[
:cache
].
value
).
to
eq
(
key:
'test'
,
policy:
'pull-push'
)
end
end
...
...
@@ -123,7 +123,7 @@ describe Gitlab::Ci::Config::Entry::Job do
it
'uses config from global entry'
do
expect
(
entry
[
:image
].
value
).
to
eq
'specified'
expect
(
entry
[
:cache
].
value
).
to
eq
(
key:
'test'
)
expect
(
entry
[
:cache
].
value
).
to
eq
(
key:
'test'
,
policy:
'pull-push'
)
end
end
end
...
...
spec/requests/api/runner_spec.rb
浏览文件 @
35f4a00f
...
...
@@ -351,7 +351,8 @@ describe API::Runner do
let
(
:expected_cache
)
do
[{
'key'
=>
'cache_key'
,
'untracked'
=>
false
,
'paths'
=>
[
'vendor/*'
]
}]
'paths'
=>
[
'vendor/*'
],
'policy'
=>
'pull-push'
}]
end
it
'picks a job'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录