Commit a76df563 authored by Steve Azzopardi's avatar Steve Azzopardi

Merge branch 'add-ff-for-builds-dir' into 'master'

Allow to use FF to configure `/builds` folder

See merge request !1319
parents 20321fe3 af72f109
Pipeline #57469598 passed with stages
in 60 minutes and 58 seconds
......@@ -73,6 +73,7 @@ const (
FFDockerHelperImageV2 string = "FF_DOCKER_HELPER_IMAGE_V2"
FFCmdDisableDelayedErrorLevelExpansion string = "FF_CMD_DISABLE_DELAYED_ERROR_LEVEL_EXPANSION"
FFUseLegacyGitCleanStrategy string = "FF_USE_LEGACY_GIT_CLEAN_STRATEGY"
FFUseLegacyBuildsDirForDocker string = "FF_USE_LEGACY_BUILDS_DIR_FOR_DOCKER"
)
type Build struct {
......@@ -579,6 +580,7 @@ func (b *Build) GetDefaultFeatureFlagsVariables() JobVariables {
{Key: FFDockerHelperImageV2, Value: "false", Public: true, Internal: true, File: false}, // TODO: Remove in 12.0
{Key: FFUseLegacyGitCleanStrategy, Value: "false", Public: true, Internal: true, File: false}, // TODO: Remove in 12.0
{Key: FFCmdDisableDelayedErrorLevelExpansion, Value: "false", Public: true, Internal: true, File: false},
{Key: FFUseLegacyBuildsDirForDocker, Value: "false", Public: true, Internal: true, File: false}, // TODO: Remove in 13.0
}
}
......
......@@ -32,6 +32,7 @@ change hidden behind the feature flag disabled a corresponding environment varia
| `FF_DOCKER_HELPER_IMAGE_V2` | `false` | ✓ | 12.0 | Enable the helper image to use the new commands when [helper_image](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnersdocker-section) is specified. This will start using the new API that will be used in 12.0 and stop showing the warning message in the build log. |
| `FF_CMD_DISABLE_DELAYED_ERROR_LEVEL_EXPANSION` | `false` | ✓ | TBA | Disables [EnableDelayedExpansion](https://ss64.com/nt/delayedexpansion.html) for error checking for when using [Window Batch](https://docs.gitlab.com/runner/shells/#windows-batch) shell. |
| `FF_USE_LEGACY_GIT_CLEAN_STRATEGY` | `false` | ✓ | 12.0 | Enables the new strategy for `git clean` that moves the clean operation after checkout and enables support for `GIT_CLEAN_FLAGS` |
| `FF_USE_LEGACY_BUILDS_DIR_FOR_DOCKER` | `false` | ✓ | 13.0 | Enables the new strategy for Docker executor to cache the content of `/builds` directory instead of `/builds/group-org` |
[mr-1010]: https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/1010
......@@ -506,9 +506,16 @@ func fakeContainer(id string, names ...string) *types.Container {
}
func (e *executor) createBuildVolume() error {
// Cache Git sources:
// use a `BuildsDir`
if !path.IsAbs(e.Build.RootDir) || e.Build.RootDir == "/" {
parentDir := e.Build.RootDir
if e.Build.IsFeatureFlagOn(common.FFUseLegacyBuildsDirForDocker) {
// Cache Git sources:
// take path of the projects directory,
// because we use `rm -rf` which could remove the mounted volume
parentDir = path.Dir(e.Build.FullProjectDir())
}
if !path.IsAbs(parentDir) && parentDir != "/" {
return common.MakeBuildError("build directory needs to be absolute and non-root path")
}
......@@ -518,11 +525,11 @@ func (e *executor) createBuildVolume() error {
if e.Build.GetGitStrategy() == common.GitFetch && !e.Config.Docker.DisableCache {
// create persistent cache container
return e.addVolume(e.Build.RootDir)
return e.addVolume(parentDir)
}
// create temporary cache container
id, err := e.createCacheVolume("", e.Build.RootDir)
id, err := e.createCacheVolume("", parentDir)
if err != nil {
return err
}
......
......@@ -1050,3 +1050,65 @@ func TestDockerCommandWithDoingPruneAndAfterScript(t *testing.T) {
err = build.Run(&common.Config{}, &common.Trace{Writer: os.Stdout})
assert.NoError(t, err)
}
func TestDockerCommandUsingBuildsVolume(t *testing.T) {
if helpers.SkipIntegrationTests(t, "docker", "info") {
return
}
const buildsPath = "/builds"
// the path is taken from `repoRemoteURL`
const buildsGroupPath = "/builds/gitlab-org/ci-cd/tests"
tests := map[string]struct {
validPath string
invalidPath string
variable string
}{
"uses default state of FF_USE_LEGACY_BUILDS_DIR_FOR_DOCKER": {
validPath: buildsPath,
invalidPath: buildsGroupPath,
variable: "",
},
"disables FF_USE_LEGACY_BUILDS_DIR_FOR_DOCKER": {
validPath: buildsPath,
invalidPath: buildsGroupPath,
variable: "FF_USE_LEGACY_BUILDS_DIR_FOR_DOCKER=false",
},
"enables FF_USE_LEGACY_BUILDS_DIR_FOR_DOCKER": {
validPath: buildsGroupPath,
invalidPath: buildsPath,
variable: "FF_USE_LEGACY_BUILDS_DIR_FOR_DOCKER=true",
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
jobResponse, err := common.GetRemoteBuildResponse(
"mountpoint "+test.validPath,
"! mountpoint "+test.invalidPath,
)
require.NoError(t, err)
build := &common.Build{
JobResponse: jobResponse,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
Environment: []string{
"GIT_STRATEGY=none",
test.variable,
},
},
},
}
err = build.Run(&common.Config{}, &common.Trace{Writer: os.Stdout})
assert.NoError(t, err)
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment