From 8fa2a231297f1b7fac19546e6ec486a0f604f731 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 20 Nov 2019 10:01:42 -0800 Subject: [PATCH] support for new env plugin --- command/compile.go | 3 ++- command/daemon/config.go | 6 ++++++ command/daemon/daemon.go | 10 +++++++++- command/exec.go | 3 ++- engine/compiler/clone_test.go | 3 +++ engine/compiler/compiler.go | 17 +++++++++++++---- engine/compiler/compiler_test.go | 3 +++ engine/engine_impl.go | 2 +- go.mod | 4 ++-- go.sum | 6 ++++++ 10 files changed, 47 insertions(+), 10 deletions(-) diff --git a/command/compile.go b/command/compile.go index 2065d18..ecd4782 100644 --- a/command/compile.go +++ b/command/compile.go @@ -17,6 +17,7 @@ import ( "github.com/drone-runners/drone-runner-docker/engine/resource" "github.com/drone/envsubst" "github.com/drone/runner-go/environ" + "github.com/drone/runner-go/environ/provider" "github.com/drone/runner-go/manifest" "github.com/drone/runner-go/registry" "github.com/drone/runner-go/secret" @@ -97,7 +98,7 @@ func (c *compileCommand) run(*kingpin.ParseContext) error { // compile the pipeline to an intermediate representation. comp := &compiler.Compiler{ - Environ: c.Environ, + Environ: provider.Static(c.Environ), Labels: c.Labels, Resources: c.Resources, Privileged: append(c.Privileged, compiler.Privileged...), diff --git a/command/daemon/config.go b/command/daemon/config.go index 2d34df5..c2309d0 100644 --- a/command/daemon/config.go +++ b/command/daemon/config.go @@ -78,6 +78,12 @@ type Config struct { CPUSet []string `envconfig:"DRONE_CPU_SET"` } + Environ struct { + Endpoint string `envconfig:"DRONE_ENV_PLUGIN_ENDPOINT"` + Token string `envconfig:"DRONE_ENV_PLUGIN_TOKEN"` + SkipVerify bool `envconfig:"DRONE_ENV_PLUGIN_SKIP_VERIFY"` + } + Secret struct { Endpoint string `envconfig:"DRONE_SECRET_PLUGIN_ENDPOINT"` Token string `envconfig:"DRONE_SECRET_PLUGIN_TOKEN"` diff --git a/command/daemon/daemon.go b/command/daemon/daemon.go index 7f9b281..a4a6475 100644 --- a/command/daemon/daemon.go +++ b/command/daemon/daemon.go @@ -16,6 +16,7 @@ import ( "github.com/drone-runners/drone-runner-docker/runtime" "github.com/drone/runner-go/client" + "github.com/drone/runner-go/environ/provider" "github.com/drone/runner-go/handler/router" "github.com/drone/runner-go/logger" loghistory "github.com/drone/runner-go/logger/history" @@ -120,7 +121,6 @@ func (c *daemonCommand) run(*kingpin.ParseContext) error { ), Compiler: &compiler.Compiler{ Clone: config.Runner.Clone, - Environ: config.Runner.Environ, Privileged: append(config.Runner.Privileged, compiler.Privileged...), Networks: config.Runner.Networks, Volumes: config.Runner.Volumes, @@ -132,6 +132,14 @@ func (c *daemonCommand) run(*kingpin.ParseContext) error { CPUShares: config.Resources.CPUShares, CPUSet: config.Resources.CPUSet, }, + Environ: provider.Combine( + provider.Static(config.Runner.Environ), + provider.External( + config.Environ.Endpoint, + config.Environ.Token, + config.Environ.SkipVerify, + ), + ), Registry: registry.Combine( registry.File( config.Docker.Config, diff --git a/command/exec.go b/command/exec.go index b9842e6..6447807 100644 --- a/command/exec.go +++ b/command/exec.go @@ -22,6 +22,7 @@ import ( "github.com/drone/drone-go/drone" "github.com/drone/envsubst" "github.com/drone/runner-go/environ" + "github.com/drone/runner-go/environ/provider" "github.com/drone/runner-go/logger" "github.com/drone/runner-go/manifest" "github.com/drone/runner-go/pipeline" @@ -117,7 +118,7 @@ func (c *execCommand) run(*kingpin.ParseContext) error { // compile the pipeline to an intermediate representation. comp := &compiler.Compiler{ - Environ: c.Environ, + Environ: provider.Static(c.Environ), Labels: c.Labels, Resources: c.Resources, Privileged: append(c.Privileged, compiler.Privileged...), diff --git a/engine/compiler/clone_test.go b/engine/compiler/clone_test.go index 92ae4b1..eb0832d 100644 --- a/engine/compiler/clone_test.go +++ b/engine/compiler/clone_test.go @@ -11,6 +11,7 @@ import ( "github.com/drone-runners/drone-runner-docker/engine" "github.com/drone-runners/drone-runner-docker/engine/resource" "github.com/drone/drone-go/drone" + "github.com/drone/runner-go/environ/provider" "github.com/drone/runner-go/manifest" "github.com/drone/runner-go/registry" "github.com/drone/runner-go/secret" @@ -28,6 +29,7 @@ func TestClone(t *testing.T) { c := &Compiler{ Registry: registry.Static(nil), Secret: secret.Static(nil), + Environ: provider.Static(nil), } args := Args{ Repo: &drone.Repo{}, @@ -63,6 +65,7 @@ func TestClone(t *testing.T) { func TestCloneDisable(t *testing.T) { c := &Compiler{ + Environ: provider.Static(nil), Registry: registry.Static(nil), Secret: secret.Static(nil), } diff --git a/engine/compiler/compiler.go b/engine/compiler/compiler.go index bc189ba..b21f2c3 100644 --- a/engine/compiler/compiler.go +++ b/engine/compiler/compiler.go @@ -15,6 +15,7 @@ import ( "github.com/drone/drone-go/drone" "github.com/drone/runner-go/clone" "github.com/drone/runner-go/environ" + "github.com/drone/runner-go/environ/provider" "github.com/drone/runner-go/labels" "github.com/drone/runner-go/manifest" "github.com/drone/runner-go/registry" @@ -25,7 +26,9 @@ import ( ) // random generator function -var random = uniuri.New +var random = func() string { + return "drone-" + uniuri.NewLen(20) +} // Privileged provides a list of plugins that execute // with privileged capabilities in order to run Docker @@ -96,7 +99,7 @@ type Compiler struct { // Environ provides a set of environment variables that // should be added to each pipeline step by default. - Environ map[string]string + Environ provider.Provider // Labels provides a set of labels that should be added // to each container by default. @@ -202,9 +205,15 @@ func (c *Compiler) Compile(ctx context.Context, args Args) *engine.Spec { Volumes: []*engine.Volume{volume}, } + // list the global environment variables + envs, _ := c.Environ.List(ctx, &provider.Request{ + Build: args.Build, + Repo: args.Repo, + }) + // create the default environment variables. - envs := environ.Combine( - c.Environ, + envs = environ.Combine( + envs, args.Build.Params, args.Pipeline.Environment, environ.Proxy(), diff --git a/engine/compiler/compiler_test.go b/engine/compiler/compiler_test.go index 2519f35..621f40e 100644 --- a/engine/compiler/compiler_test.go +++ b/engine/compiler/compiler_test.go @@ -17,6 +17,7 @@ import ( "github.com/drone-runners/drone-runner-docker/engine" "github.com/drone-runners/drone-runner-docker/engine/resource" "github.com/drone/drone-go/drone" + "github.com/drone/runner-go/environ/provider" "github.com/drone/runner-go/manifest" "github.com/drone/runner-go/registry" "github.com/drone/runner-go/secret" @@ -97,6 +98,7 @@ func TestCompile_Secrets(t *testing.T) { manifest, _ := manifest.ParseFile("testdata/secret.yml") compiler := &Compiler{ + Environ: provider.Static(nil), Registry: registry.Static(nil), Secret: secret.StaticVars(map[string]string{ "token": "3DA541559918A808C2402BBA5012F6C60B27661C", @@ -158,6 +160,7 @@ func testCompile(t *testing.T, source, golden string) *engine.Spec { } compiler := &Compiler{ + Environ: provider.Static(nil), Registry: registry.Static(nil), Secret: secret.StaticVars(map[string]string{ "token": "3DA541559918A808C2402BBA5012F6C60B27661C", diff --git a/engine/engine_impl.go b/engine/engine_impl.go index e97a27a..1617a44 100644 --- a/engine/engine_impl.go +++ b/engine/engine_impl.go @@ -157,7 +157,7 @@ func (e *Docker) create(ctx context.Context, spec *Spec, step *Step, output io.W // create pull options with encoded authorization credentials. pullopts := types.ImagePullOptions{} if step.Auth != nil { - pullopts.RegistryAuth = auths.Encode( + pullopts.RegistryAuth = auths.Header( step.Auth.Username, step.Auth.Password, ) diff --git a/go.mod b/go.mod index 182af7a..3d38db0 100644 --- a/go.mod +++ b/go.mod @@ -11,9 +11,9 @@ require ( github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9 github.com/docker/distribution v2.7.1+incompatible github.com/docker/go-connections v0.3.0 // indirect - github.com/drone/drone-go v1.0.5-0.20190504210458-4d6116b897ba + github.com/drone/drone-go v1.1.1-0.20191119212130-1d2e07e87e79 github.com/drone/envsubst v1.0.2 - github.com/drone/runner-go v1.3.0 + github.com/drone/runner-go v1.4.1-0.20191119212738-c0d9268011a7 github.com/drone/signal v1.0.0 github.com/ghodss/yaml v1.0.0 github.com/gogo/protobuf v0.0.0-20170307180453-100ba4e88506 // indirect diff --git a/go.sum b/go.sum index 89cafe5..6dc5a84 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,9 @@ github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/drone/drone-go v1.0.5-0.20190504210458-4d6116b897ba h1:GKiT4UPBligLXJAP1zRllHvTUygAAlgS3t9LM9aasp0= github.com/drone/drone-go v1.0.5-0.20190504210458-4d6116b897ba/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4= +github.com/drone/drone-go v1.1.0 h1:2mritc5b7PhQWvILNyzaImZMRWVbMmmZ5Q0UDwwO7SI= +github.com/drone/drone-go v1.1.1-0.20191119212130-1d2e07e87e79 h1:jW+dJ8HrZ1CbazlsYoriOOCQnVJ2NkfNczLHs6UMU6I= +github.com/drone/drone-go v1.1.1-0.20191119212130-1d2e07e87e79/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4= github.com/drone/envsubst v1.0.2 h1:dpYLMAspQHW0a8dZpLRKe9jCNvIGZPhCPrycZzIHdqo= github.com/drone/envsubst v1.0.2/go.mod h1:bkZbnc/2vh1M12Ecn7EYScpI4YGYU0etwLJICOWi8Z0= github.com/drone/runner-go v1.2.2 h1:fwYgjyJl6KdjQGEUFof9+HLtNpK3iHq7UuR+/aYNyDk= @@ -40,6 +43,9 @@ github.com/drone/runner-go v1.2.3-0.20191031202840-a11193321443 h1:uu8lbyWKBx0Y1 github.com/drone/runner-go v1.2.3-0.20191031202840-a11193321443/go.mod h1:61VgQWhZbNPXp01lBuR7PAztTMySGLnMzK/4oYE3D9Y= github.com/drone/runner-go v1.3.0 h1:RGJIk7vbvxdfd3wFyiP4XkLO+b5esCLg1aFUCIHISeE= github.com/drone/runner-go v1.3.0/go.mod h1:61VgQWhZbNPXp01lBuR7PAztTMySGLnMzK/4oYE3D9Y= +github.com/drone/runner-go v1.4.0 h1:zAeYtlKQGvJr2ehfLzQWblzWzvfdkNaapbr6x536fLA= +github.com/drone/runner-go v1.4.1-0.20191119212738-c0d9268011a7 h1:iNLp8xT0rMcV/tT2J3fCuEbWLqoP7CiL3WR8W3i3HpQ= +github.com/drone/runner-go v1.4.1-0.20191119212738-c0d9268011a7/go.mod h1:IqwuMbIoeH45k4NemcNPwymm+l386EeyBC166UElURw= github.com/drone/signal v1.0.0 h1:NrnM2M/4yAuU/tXs6RP1a1ZfxnaHwYkd0kJurA1p6uI= github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=