Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Seipel
gitlab-runner
Commits
3932ca2f
Commit
3932ca2f
authored
9 years ago
by
Kamil Trzcinski
Browse files
Options
Downloads
Patches
Plain Diff
By default all volumes are shared between projects
parent
f118acc5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
executors/docker/executor_docker.go
+22
-11
22 additions, 11 deletions
executors/docker/executor_docker.go
with
22 additions
and
11 deletions
executors/docker/executor_docker.go
+
22
−
11
View file @
3932ca2f
...
...
@@ -198,32 +198,44 @@ func (s *DockerExecutor) createCacheVolume(containerName, containerPath string)
return
container
,
nil
}
func
(
s
*
DockerExecutor
)
addCacheVolume
(
binds
,
volumesFrom
*
[]
string
,
containerPath
string
)
error
{
func
(
s
*
DockerExecutor
)
addCacheVolume
(
binds
,
volumesFrom
*
[]
string
,
containerPath
string
,
shared
bool
)
error
{
var
err
error
containerPath
=
s
.
getAbsoluteContainerPath
(
containerPath
)
// disable cache for automatic container cache, but leave it for host volumes (they are shared on purpose)
if
helpers
.
BoolOrDefault
(
s
.
Config
.
Docker
.
DisableCache
,
false
)
{
s
.
Debugln
(
"Container cache for"
,
containerPath
,
"
is disabled."
)
s
.
Debugln
(
"Container cache for"
,
containerPath
,
"is disabled."
)
return
nil
}
hash
:=
md5
.
Sum
([]
byte
(
containerPath
))
hash
:=
fmt
.
Sprintf
(
"%x"
,
md5
.
Sum
([]
byte
(
containerPath
))
)
// use host-based cache
if
cacheDir
:=
helpers
.
StringOrDefault
(
s
.
Config
.
Docker
.
CacheDir
,
""
);
cacheDir
!=
""
{
hostPath
:=
fmt
.
Sprintf
(
"%s/%s/%x"
,
cacheDir
,
s
.
Build
.
ProjectUniqueName
(),
hash
)
hostPath
,
err
:=
filepath
.
Abs
(
hostPath
)
hostPath
,
err
:=
filepath
.
Abs
(
cacheDir
)
if
err
!=
nil
{
return
err
}
// For shared directory
if
shared
{
hostPath
=
filepath
.
Join
(
hostPath
,
"runner-"
+
s
.
Build
.
Runner
.
ShortDescription
())
hostPath
=
filepath
.
Join
(
hostPath
,
"project-"
+
strconv
.
Itoa
(
s
.
Build
.
ProjectID
))
}
else
{
hostPath
=
filepath
.
Join
(
hostPath
,
s
.
Build
.
Runner
.
ShortDescription
())
}
hostPath
=
filepath
.
Join
(
hostPath
,
hash
)
s
.
Debugln
(
"Using path"
,
hostPath
,
"as cache for"
,
containerPath
,
"..."
)
*
binds
=
append
(
*
binds
,
fmt
.
Sprintf
(
"%v:%v"
,
hostPath
,
containerPath
))
return
nil
}
// get existing cache container
containerName
:=
fmt
.
Sprintf
(
"%s-cache-%x"
,
s
.
Build
.
ProjectUniqueName
(),
hash
)
containerName
:=
fmt
.
Sprintf
(
"%s-cache-%s"
,
s
.
Build
.
ProjectUniqueName
(),
hash
)
if
shared
{
containerName
=
fmt
.
Sprintf
(
"runner-%s-project-%d-cache-%s"
,
s
.
Build
.
Runner
.
ShortDescription
(),
s
.
Build
.
ProjectID
,
hash
)
}
container
,
_
:=
s
.
client
.
InspectContainer
(
containerName
)
// check if we have valid cache, if not remove the broken container
...
...
@@ -245,7 +257,7 @@ func (s *DockerExecutor) addCacheVolume(binds, volumesFrom *[]string, containerP
return
nil
}
func
(
s
*
DockerExecutor
)
addVolume
(
binds
,
volumesFrom
*
[]
string
,
volume
string
)
error
{
func
(
s
*
DockerExecutor
)
addVolume
(
binds
,
volumesFrom
*
[]
string
,
volume
string
,
shared
bool
)
error
{
var
err
error
hostVolume
:=
strings
.
SplitN
(
volume
,
":"
,
2
)
switch
len
(
hostVolume
)
{
...
...
@@ -254,7 +266,7 @@ func (s *DockerExecutor) addVolume(binds, volumesFrom *[]string, volume string)
case
1
:
// disable cache disables
err
=
s
.
addCacheVolume
(
binds
,
volumesFrom
,
hostVolume
[
0
])
err
=
s
.
addCacheVolume
(
binds
,
volumesFrom
,
hostVolume
[
0
]
,
shared
)
}
if
err
!=
nil
{
...
...
@@ -265,9 +277,8 @@ func (s *DockerExecutor) addVolume(binds, volumesFrom *[]string, volume string)
func
(
s
*
DockerExecutor
)
createVolumes
()
([]
string
,
[]
string
,
error
)
{
var
binds
,
volumesFrom
[]
string
for
_
,
volume
:=
range
s
.
Config
.
Docker
.
Volumes
{
s
.
addVolume
(
&
binds
,
&
volumesFrom
,
volume
)
s
.
addVolume
(
&
binds
,
&
volumesFrom
,
volume
,
true
)
}
// Cache Git sources:
...
...
@@ -279,7 +290,7 @@ func (s *DockerExecutor) createVolumes() ([]string, []string, error) {
if
filepath
.
IsAbs
(
parentDir
)
&&
parentDir
!=
"/"
{
if
s
.
Build
.
AllowGitFetch
&&
!
helpers
.
BoolOrDefault
(
s
.
Config
.
Docker
.
DisableCache
,
false
)
{
// create persistent cache container
s
.
addVolume
(
&
binds
,
&
volumesFrom
,
parentDir
)
s
.
addVolume
(
&
binds
,
&
volumesFrom
,
parentDir
,
false
)
}
else
{
// create temporary cache container
container
,
_
:=
s
.
createCacheVolume
(
""
,
parentDir
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment