Commit 6d124010 authored by Kamil Trzciński's avatar Kamil Trzciński

Remove commands/register.go changes as they are unneeded

parent f4645bfb
......@@ -107,10 +107,6 @@ func (s *RegisterCommand) askDocker() {
}
s.Docker.Image = s.ask("docker-image", "Please enter the default Docker image (e.g. ruby:2.1):")
s.CustomBuildDir = &common.CustomBuildDir{
Enable: true,
}
for _, volume := range s.Docker.Volumes {
parts := strings.Split(volume, ":")
if parts[len(parts)-1] == "/cache" {
......@@ -199,9 +195,6 @@ func (s *RegisterCommand) askExecutorOptions() {
switch s.Executor {
case "kubernetes":
s.Kubernetes = kubernetes
s.CustomBuildDir = &common.CustomBuildDir{
Enable: true,
}
case "docker+machine":
s.Machine = machine
s.Docker = docker
......
......@@ -15,9 +15,6 @@ import (
"gitlab.com/ayufan/golang-cli-helpers"
"gitlab.com/gitlab-org/gitlab-runner/common"
_ "gitlab.com/gitlab-org/gitlab-runner/executors/docker/machine" // Register docker+machine as executor
_ "gitlab.com/gitlab-org/gitlab-runner/executors/kubernetes" // Register kubernetes as executor
"gitlab.com/gitlab-org/gitlab-runner/helpers/ssh"
)
func setupDockerRegisterCommand(dockerConfig *common.DockerConfig) *RegisterCommand {
......@@ -192,220 +189,3 @@ func TestRegisterCacheDeprecatedOptions_EnvVariables(t *testing.T) {
assert.Contains(t, output, "S3_BUCKET_LOCATION environment variables is deprecated and will be removed in GitLab Runner 12.0. Please use CACHE_S3_BUCKET_LOCATION instead")
assert.Contains(t, output, "S3_CACHE_INSECURE environment variables is deprecated and will be removed in GitLab Runner 12.0. Please use CACHE_S3_INSECURE instead")
}
func TestDefaultExecutorConfiguration(t *testing.T) {
tests := []struct {
executor string
expectedConfig common.RunnerConfig
}{
{
executor: "kubernetes",
expectedConfig: common.RunnerConfig{
Name: "ci-test",
RunnerCredentials: common.RunnerCredentials{
URL: "https://gitlab.com/",
Token: "test-token",
},
RunnerSettings: common.RunnerSettings{
Executor: "kubernetes",
CustomBuildDir: &common.CustomBuildDir{
Enable: true,
},
},
},
},
{
executor: "docker+machine",
expectedConfig: common.RunnerConfig{
Name: "ci-test",
RunnerCredentials: common.RunnerCredentials{
URL: "https://gitlab.com/",
Token: "test-token",
},
RunnerSettings: common.RunnerSettings{
Executor: "docker+machine",
CustomBuildDir: &common.CustomBuildDir{
Enable: true,
},
Docker: &common.DockerConfig{
Image: "ruby:2.1",
Volumes: []string{"/cache"},
},
},
},
},
{
executor: "docker-ssh+machine",
expectedConfig: common.RunnerConfig{
Name: "ci-test",
RunnerCredentials: common.RunnerCredentials{
URL: "https://gitlab.com/",
Token: "test-token",
},
RunnerSettings: common.RunnerSettings{
Executor: "docker-ssh+machine",
CustomBuildDir: &common.CustomBuildDir{
Enable: true,
},
Docker: &common.DockerConfig{
Image: "ruby:2.1",
Volumes: []string{"/cache"},
},
SSH: &ssh.Config{
User: "user",
Password: "password",
IdentityFile: "/home/user/.ssh/id_rsa",
},
},
},
},
{
executor: "docker",
expectedConfig: common.RunnerConfig{
Name: "ci-test",
RunnerCredentials: common.RunnerCredentials{
URL: "https://gitlab.com/",
Token: "test-token",
},
RunnerSettings: common.RunnerSettings{
Executor: "docker",
CustomBuildDir: &common.CustomBuildDir{
Enable: true,
},
Docker: &common.DockerConfig{
Image: "ruby:2.1",
Volumes: []string{"/cache"},
},
},
},
},
{
executor: "docker-ssh",
expectedConfig: common.RunnerConfig{
Name: "ci-test",
RunnerCredentials: common.RunnerCredentials{
URL: "https://gitlab.com/",
Token: "test-token",
},
RunnerSettings: common.RunnerSettings{
Executor: "docker-ssh",
CustomBuildDir: &common.CustomBuildDir{
Enable: true,
},
Docker: &common.DockerConfig{
Image: "ruby:2.1",
Volumes: []string{"/cache"},
},
SSH: &ssh.Config{
User: "user",
Password: "password",
IdentityFile: "/home/user/.ssh/id_rsa",
},
},
},
},
{
executor: "ssh",
expectedConfig: common.RunnerConfig{
Name: "ci-test",
RunnerCredentials: common.RunnerCredentials{
URL: "https://gitlab.com/",
Token: "test-token",
},
RunnerSettings: common.RunnerSettings{
Executor: "ssh",
SSH: &ssh.Config{
User: "user",
Password: "password",
Host: "my.server.com",
Port: "22",
IdentityFile: "/home/user/.ssh/id_rsa",
},
CustomBuildDir: nil,
},
},
},
{
executor: "parallels",
expectedConfig: common.RunnerConfig{
Name: "ci-test",
RunnerCredentials: common.RunnerCredentials{
URL: "https://gitlab.com/",
Token: "test-token",
},
RunnerSettings: common.RunnerSettings{
Executor: "parallels",
SSH: &ssh.Config{
Host: "my.server.com",
Port: "22",
},
Parallels: &common.ParallelsConfig{
BaseName: "my-parallels-vm",
},
CustomBuildDir: nil,
},
},
},
{
executor: "virtualbox",
expectedConfig: common.RunnerConfig{
Name: "ci-test",
RunnerCredentials: common.RunnerCredentials{
URL: "https://gitlab.com/",
Token: "test-token",
},
RunnerSettings: common.RunnerSettings{
Executor: "virtualbox",
SSH: &ssh.Config{
User: "user",
Password: "password",
IdentityFile: "/home/user/.ssh/id_rsa",
},
VirtualBox: &common.VirtualBoxConfig{
BaseName: "my-virtualbox-vm",
},
CustomBuildDir: nil,
},
},
},
}
for _, test := range tests {
t.Run(test.executor, func(t *testing.T) {
fs := flag.NewFlagSet("", flag.ExitOnError)
ctx := cli.NewContext(cli.NewApp(), fs, nil)
fs.String("url", "https://gitlab.com/", "")
fs.String("registration-token", "test-registration-token", "")
fs.String("name", "ci-test", "")
fs.String("tag-list", "ci,test", "")
fs.String("executor", test.executor, "")
fs.String("docker-image", "ruby:2.1", "")
fs.String("ssh-user", "user", "")
fs.String("ssh-password", "password", "")
fs.String("ssh-identity-file", "/home/user/.ssh/id_rsa", "")
fs.String("ssh-host", "my.server.com", "")
fs.String("ssh-port", "22", "")
fs.String("parallels-base-name", "my-parallels-vm", "")
fs.String("virtualbox-base-name", "my-virtualbox-vm", "")
registerRunnerRep := common.RegisterRunnerResponse{
Token: "test-token",
}
mockNetwork := &common.MockNetwork{}
mockNetwork.On("RegisterRunner", mock.Anything, mock.Anything).Return(&registerRunnerRep, true).Once()
s := &RegisterCommand{
context: ctx,
NonInteractive: true,
}
s.SSH = &ssh.Config{}
s.Parallels = &common.ParallelsConfig{}
s.VirtualBox = &common.VirtualBoxConfig{}
s.network = mockNetwork
s.Execute(ctx)
assert.Equal(t, test.expectedConfig, s.RunnerConfig)
})
}
}
......@@ -160,26 +160,25 @@ func (b *Build) TmpProjectDir() string {
return helpers.ToSlash(b.BuildDir) + ".tmp"
}
func (b *Build) getCustomBuildDir(rootDir, overrideKey string, customDirAllowed, sharedDir bool) (string, error) {
func (b *Build) getCustomBuildDir(rootDir, overrideKey string, customBuildDirEnabled, sharedDir bool) (string, error) {
dir := b.GetAllVariables().Get(overrideKey)
if dir != "" {
if !customDirAllowed {
return "", MakeBuildError("setting %s is not allowed, enable `custom_build_dir` feature", overrideKey)
}
if dir == "" {
return path.Join(rootDir, b.ProjectUniqueDir(sharedDir)), nil
}
if !strings.HasPrefix(dir, rootDir) {
return "", MakeBuildError("the %s=%q has to be within %q",
overrideKey, dir, rootDir)
}
if !customBuildDirEnabled {
return "", MakeBuildError("setting %s is not allowed, enable `custom_build_dir` feature", overrideKey)
}
if dir == "" {
dir = path.Join(rootDir, b.ProjectUniqueDir(sharedDir))
if !strings.HasPrefix(dir, rootDir) {
return "", MakeBuildError("the %s=%q has to be within %q",
overrideKey, dir, rootDir)
}
return dir, nil
}
func (b *Build) StartBuild(rootDir, cacheDir string, customDirAllowed, sharedDir bool) error {
func (b *Build) StartBuild(rootDir, cacheDir string, customBuildDirEnabled, sharedDir bool) error {
var err error
// We set RootDir and invalidate variables
......@@ -188,7 +187,7 @@ func (b *Build) StartBuild(rootDir, cacheDir string, customDirAllowed, sharedDir
b.CacheDir = path.Join(cacheDir, b.ProjectUniqueDir(false))
b.refreshAllVariables()
b.BuildDir, err = b.getCustomBuildDir(b.RootDir, "GIT_CLONE_PATH", customDirAllowed, sharedDir)
b.BuildDir, err = b.getCustomBuildDir(b.RootDir, "GIT_CLONE_PATH", customBuildDirEnabled, sharedDir)
if err != nil {
return err
}
......
......@@ -903,10 +903,10 @@ func TestIsFeatureFlagOn(t *testing.T) {
func TestStartBuild(t *testing.T) {
type startBuildArgs struct {
rootDir string
cacheDir string
customBuildDir bool
sharedDir bool
rootDir string
cacheDir string
customBuildDirEnabled bool
sharedDir bool
}
tests := map[string]struct {
......@@ -918,10 +918,10 @@ func TestStartBuild(t *testing.T) {
}{
"no job specific build dir with no shared dir": {
args: startBuildArgs{
rootDir: "/build",
cacheDir: "/cache",
customBuildDir: true,
sharedDir: false,
rootDir: "/build",
cacheDir: "/cache",
customBuildDirEnabled: true,
sharedDir: false,
},
jobVariables: JobVariables{},
expectedBuildDir: "/build/test-namespace/test-repo",
......@@ -930,10 +930,10 @@ func TestStartBuild(t *testing.T) {
},
"no job specified build dir with shared dir": {
args: startBuildArgs{
rootDir: "/builds",
cacheDir: "/cache",
customBuildDir: true,
sharedDir: true,
rootDir: "/builds",
cacheDir: "/cache",
customBuildDirEnabled: true,
sharedDir: true,
},
jobVariables: JobVariables{},
expectedBuildDir: "/builds/1234/0/test-namespace/test-repo",
......@@ -942,10 +942,10 @@ func TestStartBuild(t *testing.T) {
},
"valid GIT_CLONE_PATH was specified": {
args: startBuildArgs{
rootDir: "/builds",
cacheDir: "/cache",
customBuildDir: true,
sharedDir: false,
rootDir: "/builds",
cacheDir: "/cache",
customBuildDirEnabled: true,
sharedDir: false,
},
jobVariables: JobVariables{
{Key: "GIT_CLONE_PATH", Value: "/builds/go/src/gitlab.com/test-namespace/test-repo", Public: true},
......@@ -956,10 +956,10 @@ func TestStartBuild(t *testing.T) {
},
"valid GIT_CLONE_PATH using CI_BUILDS_DIR was specified": {
args: startBuildArgs{
rootDir: "/builds",
cacheDir: "/cache",
customBuildDir: true,
sharedDir: false,
rootDir: "/builds",
cacheDir: "/cache",
customBuildDirEnabled: true,
sharedDir: false,
},
jobVariables: JobVariables{
{Key: "GIT_CLONE_PATH", Value: "$CI_BUILDS_DIR/go/src/gitlab.com/test-namespace/test-repo", Public: true},
......@@ -970,10 +970,10 @@ func TestStartBuild(t *testing.T) {
},
"custom build disabled": {
args: startBuildArgs{
rootDir: "/builds",
cacheDir: "/cache",
customBuildDir: false,
sharedDir: false,
rootDir: "/builds",
cacheDir: "/cache",
customBuildDirEnabled: false,
sharedDir: false,
},
jobVariables: JobVariables{
{Key: "GIT_CLONE_PATH", Value: "/builds/go/src/gitlab.com/test-namespace/test-repo", Public: true},
......@@ -984,10 +984,10 @@ func TestStartBuild(t *testing.T) {
},
"invalid GIT_CLONE_PATH was specified": {
args: startBuildArgs{
rootDir: "/builds",
cacheDir: "/cache",
customBuildDir: true,
sharedDir: false,
rootDir: "/builds",
cacheDir: "/cache",
customBuildDirEnabled: true,
sharedDir: false,
},
jobVariables: JobVariables{
{Key: "GIT_CLONE_PATH", Value: "/go/src/gitlab.com/test-namespace/test-repo", Public: true},
......@@ -1012,7 +1012,7 @@ func TestStartBuild(t *testing.T) {
},
}
err := build.StartBuild(test.args.rootDir, test.args.cacheDir, test.args.customBuildDir, test.args.sharedDir)
err := build.StartBuild(test.args.rootDir, test.args.cacheDir, test.args.customBuildDirEnabled, test.args.sharedDir)
if test.expectedError {
assert.Error(t, err)
return
......
......@@ -323,7 +323,7 @@ type Config struct {
}
type CustomBuildDir struct {
Enable bool `toml:"enable,omitempty" json:"enable" long:"enable" env:"CUSTOM_BUILD_DIR_ENABLE" description:"Enable job specific build directories"`
Enabled bool `toml:"enabled,omitempty" json:"enabled" long:"enabled" env:"CUSTOM_BUILD_DIR_ENABLED" description:"Enable job specific build directories"`
}
func getDeprecatedStringSetting(setting string, tomlField string, envVariable string, tomlReplacement string, envReplacement string) string {
......
......@@ -746,7 +746,7 @@ before upgrading the Runner, otherwise the jobs will start failing with a "No su
## The `[runners.custom_build_dir]` section
NOTE: **Note:**
[Introduced][gitlab-runner-1267] in Gitlab Runner 11.10
[Introduced][https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/1267] in Gitlab Runner 11.10
This section defines [custom build directories][https://docs.gitlab.com/ee/ci/yaml/README.html#custom-build-directories] parameters.
......@@ -766,13 +766,13 @@ with executors that share `builds_dir` and have `concurrent > 1`.
| Parameter | Type | Description |
|-----------|---------|-------------|
| `enable` | boolean | Allow user to define a custom build directory for a job |
| `enabled` | boolean | Allow user to define a custom build directory for a job |
Example:
```bash
[runners.custom_build_dir]
enable = true
enabled = true
```
## Note
......@@ -790,4 +790,3 @@ It depends on what you'd like to do.
[priv-example]: https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#define-an-image-from-a-private-container-registry
[variable]: https://docs.gitlab.com/ee/ci/variables/#variables
[cronvendor]: https://github.com/gorhill/cronexpr#implementation
[gitlab-runner-876]: https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/876
......@@ -65,13 +65,13 @@ func (e *AbstractExecutor) startBuild() error {
if cacheDir == "" {
cacheDir = e.DefaultCacheDir
}
customBuildDir := e.DefaultCustomBuildsDirEnabled
customBuildDirEnabled := e.DefaultCustomBuildsDirEnabled
if e.Config.CustomBuildDir != nil {
customBuildDir = e.Config.CustomBuildDir.Enable
customBuildDirEnabled = e.Config.CustomBuildDir.Enabled
}
return e.Build.StartBuild(rootDir, cacheDir,
customBuildDir, e.SharedBuildsDir)
customBuildDirEnabled, e.SharedBuildsDir)
}
func (e *AbstractExecutor) Shell() *common.ShellScriptInfo {
......
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