From a28e4ed0542e94d080b201a5d47f2abd172dba92 Mon Sep 17 00:00:00 2001 From: Anton Bracke Date: Thu, 28 Oct 2021 12:45:23 +0200 Subject: [PATCH 1/6] fix passing of netrc credentials to clone step --- pipeline/frontend/yaml/compiler/compiler.go | 20 ++++++++------------ pipeline/frontend/yaml/compiler/option.go | 18 +++++------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/pipeline/frontend/yaml/compiler/compiler.go b/pipeline/frontend/yaml/compiler/compiler.go index c574f5444f..10059325e4 100644 --- a/pipeline/frontend/yaml/compiler/compiler.go +++ b/pipeline/frontend/yaml/compiler/compiler.go @@ -42,6 +42,7 @@ type Compiler struct { volumes []string networks []string env map[string]string + cloneEnv map[string]string base string path string metadata frontend.Metadata @@ -54,8 +55,9 @@ type Compiler struct { // New creates a new Compiler with options. func New(opts ...Option) *Compiler { compiler := &Compiler{ - env: map[string]string{}, - secrets: map[string]Secret{}, + env: map[string]string{}, + cloneEnv: map[string]string{}, + secrets: map[string]Secret{}, } for _, opt := range opts { opt(compiler) @@ -108,16 +110,10 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { // add default clone step if !c.local && len(conf.Clone.Containers) == 0 && !conf.SkipClone { container := &yaml.Container{ - Name: "clone", - Image: "woodpeckerci/plugin-git:latest", - Vargs: map[string]interface{}{"depth": "0"}, - } - // TODO: migrate to woodpeckerci/plugin-git:latest (multi arch) - switch c.metadata.Sys.Arch { - case "linux/arm": - container.Image = "plugins/git:linux-arm" - case "linux/arm64": - container.Image = "plugins/git:linux-arm64" + Name: "clone", + Image: "woodpeckerci/plugin-git:latest", + Vargs: map[string]interface{}{"depth": "0"}, + Environment: c.cloneEnv, } name := fmt.Sprintf("%s_clone", c.prefix) step := c.createProcess(name, container, "clone") diff --git a/pipeline/frontend/yaml/compiler/option.go b/pipeline/frontend/yaml/compiler/option.go index 119fb78f3c..d176030b58 100644 --- a/pipeline/frontend/yaml/compiler/option.go +++ b/pipeline/frontend/yaml/compiler/option.go @@ -71,19 +71,11 @@ func WithMetadata(metadata frontend.Metadata) Option { // WithNetrc configures the compiler with netrc authentication // credentials added by default to every container in the pipeline. func WithNetrc(username, password, machine string) Option { - return WithEnviron( - map[string]string{ - "CI_NETRC_USERNAME": username, - "CI_NETRC_PASSWORD": password, - "CI_NETRC_MACHINE": machine, - - // TODO: This is present for backward compatibility and should - // be removed in a future version. - "DRONE_NETRC_USERNAME": username, - "DRONE_NETRC_PASSWORD": password, - "DRONE_NETRC_MACHINE": machine, - }, - ) + return func(compiler *Compiler) { + compiler.cloneEnv["CI_NETRC_USERNAME"] = username + compiler.cloneEnv["CI_NETRC_PASSWORD"] = password + compiler.cloneEnv["CI_NETRC_MACHINE"] = machine + } } // WithWorkspace configures the compiler with the workspace base From 38d90cafd2f3e0a6f06612ee54b67a2a913057e7 Mon Sep 17 00:00:00 2001 From: Anton Bracke Date: Thu, 28 Oct 2021 12:47:11 +0200 Subject: [PATCH 2/6] undo un-related change --- pipeline/frontend/yaml/compiler/compiler.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pipeline/frontend/yaml/compiler/compiler.go b/pipeline/frontend/yaml/compiler/compiler.go index 10059325e4..122060ce52 100644 --- a/pipeline/frontend/yaml/compiler/compiler.go +++ b/pipeline/frontend/yaml/compiler/compiler.go @@ -115,6 +115,13 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { Vargs: map[string]interface{}{"depth": "0"}, Environment: c.cloneEnv, } + // TODO: migrate to woodpeckerci/plugin-git:latest (multi arch) + switch c.metadata.Sys.Arch { + case "linux/arm": + container.Image = "plugins/git:linux-arm" + case "linux/arm64": + container.Image = "plugins/git:linux-arm64" + } name := fmt.Sprintf("%s_clone", c.prefix) step := c.createProcess(name, container, "clone") From fcd59ff76b3f715ad09b20fe819db31f646ba93e Mon Sep 17 00:00:00 2001 From: Anton Bracke Date: Thu, 28 Oct 2021 12:50:01 +0200 Subject: [PATCH 3/6] fix test --- pipeline/frontend/yaml/compiler/option_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pipeline/frontend/yaml/compiler/option_test.go b/pipeline/frontend/yaml/compiler/option_test.go index a2f5254e33..e445890052 100644 --- a/pipeline/frontend/yaml/compiler/option_test.go +++ b/pipeline/frontend/yaml/compiler/option_test.go @@ -139,13 +139,13 @@ func TestWithNetrc(t *testing.T) { "github.com", ), ) - if compiler.env["CI_NETRC_USERNAME"] != "octocat" { + if compiler.cloneEnv["CI_NETRC_USERNAME"] != "octocat" { t.Errorf("WithNetrc should set CI_NETRC_USERNAME") } - if compiler.env["CI_NETRC_PASSWORD"] != "password" { + if compiler.cloneEnv["CI_NETRC_PASSWORD"] != "password" { t.Errorf("WithNetrc should set CI_NETRC_PASSWORD") } - if compiler.env["CI_NETRC_MACHINE"] != "github.com" { + if compiler.cloneEnv["CI_NETRC_MACHINE"] != "github.com" { t.Errorf("WithNetrc should set CI_NETRC_MACHINE") } } From 40ab35ddbd3639932a4b8d19e78f410babe48f45 Mon Sep 17 00:00:00 2001 From: Anton Bracke Date: Thu, 28 Oct 2021 12:52:07 +0200 Subject: [PATCH 4/6] add netrc to own clone steps --- pipeline/frontend/yaml/compiler/compiler.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pipeline/frontend/yaml/compiler/compiler.go b/pipeline/frontend/yaml/compiler/compiler.go index 122060ce52..eb79f35a3f 100644 --- a/pipeline/frontend/yaml/compiler/compiler.go +++ b/pipeline/frontend/yaml/compiler/compiler.go @@ -142,6 +142,9 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { name := fmt.Sprintf("%s_clone_%d", c.prefix, i) step := c.createProcess(name, container, "clone") + for k, v := range c.cloneEnv { + step.Environment[k] = v + } stage.Steps = append(stage.Steps, step) config.Stages = append(config.Stages, stage) From 3f8a8cc38e2e86102b2a959bb2127824f13e2214 Mon Sep 17 00:00:00 2001 From: Anton Bracke Date: Sat, 30 Oct 2021 16:01:10 +0200 Subject: [PATCH 5/6] change image for testing --- pipeline/frontend/yaml/compiler/compiler.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pipeline/frontend/yaml/compiler/compiler.go b/pipeline/frontend/yaml/compiler/compiler.go index eb79f35a3f..9ca3902a7b 100644 --- a/pipeline/frontend/yaml/compiler/compiler.go +++ b/pipeline/frontend/yaml/compiler/compiler.go @@ -110,18 +110,19 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { // add default clone step if !c.local && len(conf.Clone.Containers) == 0 && !conf.SkipClone { container := &yaml.Container{ - Name: "clone", - Image: "woodpeckerci/plugin-git:latest", + Name: "clone", + // Image: "woodpeckerci/plugin-git:latest", + Image: "woodpeckerci/plugin-git:next", Vargs: map[string]interface{}{"depth": "0"}, Environment: c.cloneEnv, } - // TODO: migrate to woodpeckerci/plugin-git:latest (multi arch) - switch c.metadata.Sys.Arch { - case "linux/arm": - container.Image = "plugins/git:linux-arm" - case "linux/arm64": - container.Image = "plugins/git:linux-arm64" - } + // // TODO: migrate to woodpeckerci/plugin-git:latest (multi arch) + // switch c.metadata.Sys.Arch { + // case "linux/arm": + // container.Image = "plugins/git:linux-arm" + // case "linux/arm64": + // container.Image = "plugins/git:linux-arm64" + // } name := fmt.Sprintf("%s_clone", c.prefix) step := c.createProcess(name, container, "clone") From ea21d873cbbd41b423ee459b86b25fa8062cbb2e Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 25 Nov 2021 21:01:31 +0100 Subject: [PATCH 6/6] rm & specify TODO --- pipeline/frontend/yaml/compiler/compiler.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pipeline/frontend/yaml/compiler/compiler.go b/pipeline/frontend/yaml/compiler/compiler.go index 9728d58099..cf6f8c096f 100644 --- a/pipeline/frontend/yaml/compiler/compiler.go +++ b/pipeline/frontend/yaml/compiler/compiler.go @@ -111,18 +111,12 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { if !c.local && len(conf.Clone.Containers) == 0 && !conf.SkipClone { container := &yaml.Container{ Name: "clone", - // Image: "woodpeckerci/plugin-git:latest", + // TODO: switch to `:latest` once v1.1.0 got released + // https://github.com/woodpecker-ci/plugin-git/issues/3 Image: "woodpeckerci/plugin-git:next", Vargs: map[string]interface{}{"depth": "0"}, Environment: c.cloneEnv, } - // // TODO: migrate to woodpeckerci/plugin-git:latest (multi arch) - // switch c.metadata.Sys.Arch { - // case "linux/arm": - // container.Image = "plugins/git:linux-arm" - // case "linux/arm64": - // container.Image = "plugins/git:linux-arm64" - // } name := fmt.Sprintf("%s_clone", c.prefix) step := c.createProcess(name, container, "clone")