--- a/bitbucket/loader.go Sat Jul 22 13:29:17 2017 -0500
+++ b/bitbucket/loader.go Sat Jul 22 14:02:29 2017 -0500
@@ -66,11 +66,43 @@
for idx, pipeline := range pipelines {
if pipeline.Steps.Image.Name != "" {
image = pipeline.Steps.Image
+ // if the step has an image with a username, we need to add the tasks to login and logout + if image.Username != "" { + registry, _, _ := docker.ParseImage(image.Name) + // create and add the login task to the stage + loginTask = fmt.Sprintf("%s-%d-login", name, idx) + cfg.Tasks[loginTask] = &docker.Login{ + Username: image.Username, + Password: image.Password, + // create the logout task, but store the name so we can add it after the other tasks + logoutTask = fmt.Sprintf("%s-%d-logout", name, idx) + cfg.Tasks[logoutTask] = &docker.Logout{ + } else if image.Username != "" { + // if we're using the global image and it has a username, we need to add the tasks to the stage + // if we have a login task, add it to the tasks for this stage + plan.Stages[idx].Tasks = append(plan.Stages[idx].Tasks, loginTask) + // now figure out how to parse the script in the config currentScript := []string{}
@@ -114,6 +146,12 @@
name := fmt.Sprintf("%s-step-%d-%d", name, idx, last+1)
addScript(name, image, currentScript, plan, cfg)
+ // if we have a logout task, add it to the tasks for this stage + plan.Stages[idx].Tasks = append(plan.Stages[idx].Tasks, logoutTask) @@ -135,8 +173,6 @@
- defImage := pipeline.Image
Tasks: map[string]tasks.Task{
"import": &docker.Import{
@@ -146,6 +182,23 @@
Plans: map[string]plans.Plan{},
+ // store the default image + defImage := pipeline.Image + // if the default image has a username, add a login/logout task + if defImage.Username != "" { + registry, _, _ := docker.ParseImage(defImage.Name) + cfg.Tasks["login"] = &docker.Login{ + Username: defImage.Username, + Password: defImage.Password, + cfg.Tasks["logout"] = &docker.Logout{ // add the default pipelines
if len(pipeline.Pipelines.Default) > 0 {
addPipeline("default", defImage, pipeline.Pipelines.Default, cfg)
--- a/bitbucket/loader_test.go Sat Jul 22 13:29:17 2017 -0500
+++ b/bitbucket/loader_test.go Sat Jul 22 14:02:29 2017 -0500
@@ -86,6 +86,259 @@
Expect(cfg).To(Equal(expected))
+func (b *bitbucketSuite) TestLoaderComplexGlobalImage(t *testing.T) { + - find . -type f -iname "*.pyc" -exec rm -f {} \; || true + - find . -type d -iname __pycache__ -exec rm -rf {} \; || true + - pip install -r dev-requirements.txt + - PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`) + cfg, err := l.Load("", "", data) + Expect(err).To(BeNil()) + expected := &config.Config{ + Tasks: map[string]tasks.Task{ + "import": &docker.Import{ + "default-step-0-0": &docker.Run{ + "find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true", + "find . -type d -iname __pycache__ -exec rm -rf {} \\; || true", + "pip install -r dev-requirements.txt", + "PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests", + Plans: map[string]plans.Plan{ + Stages: []stages.Stage{ + Tasks: []string{"import", "default-step-0-0"}, + Expect(cfg).To(Equal(expected)) +func (b *bitbucketSuite) TestLoaderComplexGlobalImageWithLogin(t *testing.T) { + name: registry.docker.io/python:3 + - find . -type f -iname "*.pyc" -exec rm -f {} \; || true + - find . -type d -iname __pycache__ -exec rm -rf {} \; || true + - pip install -r dev-requirements.txt + - PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`) + cfg, err := l.Load("", "", data) + Expect(err).To(BeNil()) + expected := &config.Config{ + Tasks: map[string]tasks.Task{ + "import": &docker.Import{ + "login": &docker.Login{ + Server: "registry.docker.io", + "default-step-0-0": &docker.Run{ + Image: "registry.docker.io/python:3", + "find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true", + "find . -type d -iname __pycache__ -exec rm -rf {} \\; || true", + "pip install -r dev-requirements.txt", + "PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests", + "logout": &docker.Logout{ + Server: "registry.docker.io", + Plans: map[string]plans.Plan{ + Stages: []stages.Stage{ + Tasks: []string{"import", "login", "default-step-0-0", "logout"}, + Expect(cfg).To(Equal(expected)) +func (b *bitbucketSuite) TestLoaderComplexStepImage(t *testing.T) { + data := []byte(`pipelines: + - find . -type f -iname "*.pyc" -exec rm -f {} \; || true + - find . -type d -iname __pycache__ -exec rm -rf {} \; || true + - pip install -r dev-requirements.txt + - PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`) + cfg, err := l.Load("", "", data) + Expect(err).To(BeNil()) + expected := &config.Config{ + Tasks: map[string]tasks.Task{ + "import": &docker.Import{ + "default-step-0-0": &docker.Run{ + "find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true", + "find . -type d -iname __pycache__ -exec rm -rf {} \\; || true", + "pip install -r dev-requirements.txt", + "PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests", + Plans: map[string]plans.Plan{ + Stages: []stages.Stage{ + Tasks: []string{"import", "default-step-0-0"}, + Expect(cfg).To(Equal(expected)) +func (b *bitbucketSuite) TestLoaderComplexStepImageWithLogin(t *testing.T) { + data := []byte(`pipelines: + name: registry.docker.io/python:3 + - find . -type f -iname "*.pyc" -exec rm -f {} \; || true + - find . -type d -iname __pycache__ -exec rm -rf {} \; || true + - pip install -r dev-requirements.txt + - PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`) + cfg, err := l.Load("", "", data) + Expect(err).To(BeNil()) + expected := &config.Config{ + Tasks: map[string]tasks.Task{ + "import": &docker.Import{ + "default-0-login": &docker.Login{ + Server: "registry.docker.io", + "default-step-0-0": &docker.Run{ + Image: "registry.docker.io/python:3", + "find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true", + "find . -type d -iname __pycache__ -exec rm -rf {} \\; || true", + "pip install -r dev-requirements.txt", + "PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests", + "default-0-logout": &docker.Logout{ + Server: "registry.docker.io", + Plans: map[string]plans.Plan{ + Stages: []stages.Stage{ + Tasks: []string{"import", "default-0-login", "default-step-0-0", "default-0-logout"}, + Expect(cfg).To(Equal(expected)) func (b *bitbucketSuite) TestLoaderDockerMixed(t *testing.T) {