From bd829e84ca2f91f712ea331166d4b4eca3799550 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 15 Nov 2018 14:03:59 -0800 Subject: [PATCH] downgrade yaml package pending runtime fixes --- Gopkg.lock | 6 ++-- Gopkg.toml | 2 +- .../github.com/drone/drone-yaml/yaml/build.go | 2 +- .../drone/drone-yaml/yaml/compiler/clone.go | 7 +--- .../drone-yaml/yaml/compiler/compiler.go | 29 ++++++++++++--- .../yaml/compiler/internal/rand/rand.go | 36 ------------------- .../drone-yaml/yaml/compiler/script_posix.go | 12 ++----- .../drone/drone-yaml/yaml/compiler/step.go | 5 ++- .../yaml/compiler/transform/netrc.go | 7 +--- .../yaml/compiler/transform/secret.go | 13 ++----- .../yaml/compiler/transform/volume.go | 6 ++-- .../github.com/drone/drone-yaml/yaml/cond.go | 22 ++++-------- .../github.com/drone/drone-yaml/yaml/env.go | 2 +- .../drone/drone-yaml/yaml/linter/linter.go | 4 +-- .../github.com/drone/drone-yaml/yaml/param.go | 2 +- .../github.com/drone/drone-yaml/yaml/port.go | 2 +- .../github.com/drone/drone-yaml/yaml/push.go | 2 +- .../github.com/drone/drone-yaml/yaml/unit.go | 2 +- 18 files changed, 54 insertions(+), 107 deletions(-) delete mode 100644 vendor/github.com/drone/drone-yaml/yaml/compiler/internal/rand/rand.go diff --git a/Gopkg.lock b/Gopkg.lock index 4f675869..7d8674a7 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -100,13 +100,11 @@ revision = "18ed46cdaba01970970290a83715c871fb169db4" [[projects]] - branch = "master" name = "github.com/drone/drone-yaml" packages = [ "yaml", "yaml/compiler", "yaml/compiler/image", - "yaml/compiler/internal/rand", "yaml/compiler/transform", "yaml/converter", "yaml/converter/internal", @@ -114,7 +112,7 @@ "yaml/pretty", "yaml/signer" ] - revision = "00544d2965ea883dffaf6aa9e56c0130941483f6" + revision = "3bda9f5012c9aee2237b6a8a2625da7ea126dcc6" [[projects]] name = "github.com/drone/envsubst" @@ -284,6 +282,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "e876cc62fe39d562e521936b5afc6c520c0a1b826a44c17ecda377b10880c332" + inputs-digest = "0f9dac53920f6d551d503a8f6d7c17958bce16772977fe6d523d995c5b599fa2" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 450979a7..55dd760a 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -38,8 +38,8 @@ name = "github.com/drone/drone-runtime" [[constraint]] - branch = "master" name = "github.com/drone/drone-yaml" + revision = "3bda9f5012c9aee2237b6a8a2625da7ea126dcc6" [[constraint]] name = "github.com/drone/signal" diff --git a/vendor/github.com/drone/drone-yaml/yaml/build.go b/vendor/github.com/drone/drone-yaml/yaml/build.go index 73ab569d..5a9a4c46 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/build.go +++ b/vendor/github.com/drone/drone-yaml/yaml/build.go @@ -23,7 +23,7 @@ type ( } ) -// UnmarshalYAML implements yaml unmarshalling. +// UnmarshalYAML implements yaml unmarhsaling. func (b *Build) UnmarshalYAML(unmarshal func(interface{}) error) error { d := new(build) err := unmarshal(&d.Image) diff --git a/vendor/github.com/drone/drone-yaml/yaml/compiler/clone.go b/vendor/github.com/drone/drone-yaml/yaml/compiler/clone.go index 62f556d2..82afa0bf 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/compiler/clone.go +++ b/vendor/github.com/drone/drone-yaml/yaml/compiler/clone.go @@ -5,7 +5,6 @@ import ( "github.com/drone/drone-runtime/engine" "github.com/drone/drone-yaml/yaml" - "github.com/drone/drone-yaml/yaml/compiler/internal/rand" ) // default name of the clone step. @@ -49,11 +48,7 @@ func setupCloneCredentials(spec *engine.Spec, dst *engine.Step, data []byte) { Path: "/root/.git-credentials", }) spec.Files = append(spec.Files, &engine.File{ - Metadata: engine.Metadata{ - UID: rand.String(), - Namespace: spec.Metadata.Namespace, - Name: ".git-credentials", - }, + Name: ".git-credentials", Data: data, }) } diff --git a/vendor/github.com/drone/drone-yaml/yaml/compiler/compiler.go b/vendor/github.com/drone/drone-yaml/yaml/compiler/compiler.go index cc85b9bf..281b30c8 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/compiler/compiler.go +++ b/vendor/github.com/drone/drone-yaml/yaml/compiler/compiler.go @@ -4,11 +4,16 @@ import ( "github.com/drone/drone-runtime/engine" "github.com/drone/drone-yaml/yaml" "github.com/drone/drone-yaml/yaml/compiler/image" - "github.com/drone/drone-yaml/yaml/compiler/internal/rand" + + "github.com/dchest/uniuri" ) // TODO(bradrydzewski) handle depends_on (clone, services, etc) +// random provides the default function used to +// generate a random string. +var random = uniuri.New + // A Compiler compiles the pipeline configuration to an // intermediate representation that can be executed by // the Drone runtime engine. @@ -29,6 +34,11 @@ type Compiler struct { // deprecated in a future release. PrivilegedFunc func(*yaml.Container) bool + // RandFunc returns a random string. The random + // function is used to create unique identifiers for + // the namespace, container, and volume resources. + RandFunc func() string + // SkipFunc returns true if the step should be skipped. // The skip function can be used to evaluate the when // clause of each step, and return true if it should @@ -46,7 +56,7 @@ type Compiler struct { // pipeline configuration that can be executed by the // Drone runtime engine. func (c *Compiler) Compile(from *yaml.Pipeline) *engine.Spec { - namespace := rand.String() + namespace := c.random() spec := &engine.Spec{ Metadata: engine.Metadata{ @@ -81,7 +91,7 @@ func (c *Compiler) Compile(from *yaml.Pipeline) *engine.Spec { spec.Docker.Volumes = append(spec.Docker.Volumes, &engine.Volume{ Metadata: engine.Metadata{ - UID: rand.String(), + UID: c.random(), Name: workspaceName, Namespace: namespace, Labels: map[string]string{}, @@ -96,7 +106,7 @@ func (c *Compiler) Compile(from *yaml.Pipeline) *engine.Spec { for _, from := range from.Volumes { to := &engine.Volume{ Metadata: engine.Metadata{ - UID: rand.String(), + UID: c.random(), Name: from.Name, Namespace: namespace, Labels: map[string]string{}, @@ -194,7 +204,7 @@ func (c *Compiler) Compile(from *yaml.Pipeline) *engine.Spec { if spec.Docker != nil && len(rename) > 0 { v := &engine.Volume{ Metadata: engine.Metadata{ - UID: rand.String(), + UID: c.random(), Name: "_docker_socket", Namespace: namespace, Labels: map[string]string{}, @@ -264,3 +274,12 @@ func (c *Compiler) skip(container *yaml.Container) bool { } return false } + +// return a random string. If the user-defined random +// function is nil, a defalt random function is returned. +func (c *Compiler) random() string { + if c.RandFunc != nil { + return c.RandFunc() + } + return uniuri.New() +} diff --git a/vendor/github.com/drone/drone-yaml/yaml/compiler/internal/rand/rand.go b/vendor/github.com/drone/drone-yaml/yaml/compiler/internal/rand/rand.go deleted file mode 100644 index 935d68ae..00000000 --- a/vendor/github.com/drone/drone-yaml/yaml/compiler/internal/rand/rand.go +++ /dev/null @@ -1,36 +0,0 @@ -package rand - -import ( - "crypto/rand" -) - -var chars = []byte("abcdefghijklmnopqrstuvwxyz0123456789") - -// random string length -const length = 32 - -// String returns a string value. -func String() string { - clen := len(chars) - maxrb := 255 - (256 % clen) - b := make([]byte, length) - r := make([]byte, length+(length/4)) // storage for random bytes. - i := 0 - for { - if _, err := rand.Read(r); err != nil { - panic("rand: error reading random bytes") - } - for _, rb := range r { - c := int(rb) - if c > maxrb { - // Skip this number to avoid modulo bias. - continue - } - b[i] = chars[c%clen] - i++ - if i == length { - return string(b) - } - } - } -} diff --git a/vendor/github.com/drone/drone-yaml/yaml/compiler/script_posix.go b/vendor/github.com/drone/drone-yaml/yaml/compiler/script_posix.go index 66baedef..73462639 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/compiler/script_posix.go +++ b/vendor/github.com/drone/drone-yaml/yaml/compiler/script_posix.go @@ -7,7 +7,6 @@ import ( "github.com/drone/drone-runtime/engine" "github.com/drone/drone-yaml/yaml" - "github.com/drone/drone-yaml/yaml/compiler/internal/rand" ) func setupScript(spec *engine.Spec, dst *engine.Step, src *yaml.Container) { @@ -26,21 +25,16 @@ func setupScript(spec *engine.Spec, dst *engine.Step, src *yaml.Container) { buf.String(), ) spec.Files = append(spec.Files, &engine.File{ - Metadata: engine.Metadata{ - UID: rand.String(), - Namespace: spec.Metadata.Namespace, - Name: src.Name, - }, + Name: src.Name, Data: []byte(script), }) dst.Files = append(dst.Files, &engine.FileMount{ Name: src.Name, - Path: "/usr/drone/bin/init", + Path: "/bin/droneinit", Mode: 0777, }) - dst.Docker.Command = []string{"/bin/sh"} - dst.Docker.Args = []string{"/usr/drone/bin/init"} + dst.Docker.Args = []string{"/bin/droneinit"} } // buildScript is a helper script this is added to the build diff --git a/vendor/github.com/drone/drone-yaml/yaml/compiler/step.go b/vendor/github.com/drone/drone-yaml/yaml/compiler/step.go index 2516e7ab..eaef704e 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/compiler/step.go +++ b/vendor/github.com/drone/drone-yaml/yaml/compiler/step.go @@ -6,13 +6,12 @@ import ( "github.com/drone/drone-runtime/engine" "github.com/drone/drone-yaml/yaml" "github.com/drone/drone-yaml/yaml/compiler/image" - "github.com/drone/drone-yaml/yaml/compiler/internal/rand" ) func createStep(spec *engine.Spec, src *yaml.Container) *engine.Step { dst := &engine.Step{ Metadata: engine.Metadata{ - UID: rand.String(), + UID: random(), Name: src.Name, Namespace: spec.Metadata.Namespace, Labels: map[string]string{ @@ -125,7 +124,7 @@ func createStep(spec *engine.Spec, src *yaml.Container) *engine.Step { func createBuildStep(spec *engine.Spec, src *yaml.Container) *engine.Step { dst := &engine.Step{ Metadata: engine.Metadata{ - UID: rand.String(), + UID: random(), Name: src.Name, Namespace: spec.Metadata.Namespace, Labels: map[string]string{ diff --git a/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/netrc.go b/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/netrc.go index 8e2e9dbe..fa9441db 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/netrc.go +++ b/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/netrc.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/drone/drone-runtime/engine" - "github.com/drone/drone-yaml/yaml/compiler/internal/rand" ) const ( @@ -22,11 +21,7 @@ func WithNetrc(machine, username, password string) func(*engine.Spec) { } netrc := generateNetrc(machine, username, password) spec.Files = append(spec.Files, &engine.File{ - Metadata: engine.Metadata{ - UID: rand.String(), - Name: netrcName, - Namespace: spec.Metadata.Namespace, - }, + Name: netrcName, Data: []byte(netrc), }) for _, step := range spec.Steps { diff --git a/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/secret.go b/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/secret.go index 9e21606f..232d8c45 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/secret.go +++ b/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/secret.go @@ -1,9 +1,6 @@ package transform -import ( - "github.com/drone/drone-runtime/engine" - "github.com/drone/drone-yaml/yaml/compiler/internal/rand" -) +import "github.com/drone/drone-runtime/engine" // WithSecrets is a transform function that adds a set // of global secrets to the container. @@ -12,11 +9,7 @@ func WithSecrets(secrets map[string]string) func(*engine.Spec) { for key, value := range secrets { spec.Secrets = append(spec.Secrets, &engine.Secret{ - Metadata: engine.Metadata{ - UID: rand.String(), - Name: key, - Namespace: spec.Metadata.Namespace, - }, + Name: key, Data: value, }, ) @@ -53,8 +46,6 @@ func WithSecretFunc(f SecretFunc) func(*engine.Spec) { for name := range set { secret := f(name) if secret != nil { - secret.Metadata.UID = rand.String() - secret.Metadata.Namespace = spec.Metadata.Namespace spec.Secrets = append(spec.Secrets, secret) } } diff --git a/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/volume.go b/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/volume.go index 6a1e9965..d3550caa 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/volume.go +++ b/vendor/github.com/drone/drone-yaml/yaml/compiler/transform/volume.go @@ -1,8 +1,8 @@ package transform import ( + "github.com/dchest/uniuri" "github.com/drone/drone-runtime/engine" - "github.com/drone/drone-yaml/yaml/compiler/internal/rand" ) // WithVolumes is a transform function that adds a set @@ -12,8 +12,8 @@ func WithVolumes(volumes map[string]string) func(*engine.Spec) { for key, value := range volumes { volume := &engine.Volume{ Metadata: engine.Metadata{ - UID: rand.String(), - Name: rand.String(), + UID: uniuri.New(), + Name: uniuri.New(), Namespace: spec.Metadata.Namespace, Labels: map[string]string{}, }, diff --git a/vendor/github.com/drone/drone-yaml/yaml/cond.go b/vendor/github.com/drone/drone-yaml/yaml/cond.go index 4aefd17f..8e565dc9 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/cond.go +++ b/vendor/github.com/drone/drone-yaml/yaml/cond.go @@ -57,29 +57,21 @@ func (c *Condition) Excludes(v string) bool { return false } -// UnmarshalYAML implements yml unmarshalling. +// UnmarshalYAML implements yml unmarhsaling. func (c *Condition) UnmarshalYAML(unmarshal func(interface{}) error) error { - var out1 string - var out2 []string - var out3 = struct { + var out1 []string + var out2 = struct { Include []string Exclude []string }{} - err := unmarshal(&out1) - if err == nil { - c.Include = []string{out1} - return nil - } - + unmarshal(&out1) unmarshal(&out2) - unmarshal(&out3) - c.Exclude = out3.Exclude + c.Exclude = out2.Exclude c.Include = append( - out3.Include, - out2..., + out2.Include, + out1..., ) - return nil } diff --git a/vendor/github.com/drone/drone-yaml/yaml/env.go b/vendor/github.com/drone/drone-yaml/yaml/env.go index 653306f6..b6e959f1 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/env.go +++ b/vendor/github.com/drone/drone-yaml/yaml/env.go @@ -17,7 +17,7 @@ type ( } ) -// UnmarshalYAML implements yaml unmarshalling. +// UnmarshalYAML implements yaml unmarhsaling. func (v *Variable) UnmarshalYAML(unmarshal func(interface{}) error) error { d := new(variable) err := unmarshal(&d.Value) diff --git a/vendor/github.com/drone/drone-yaml/yaml/linter/linter.go b/vendor/github.com/drone/drone-yaml/yaml/linter/linter.go index 494cc7c8..dbeb5c9a 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/linter/linter.go +++ b/vendor/github.com/drone/drone-yaml/yaml/linter/linter.go @@ -124,14 +124,14 @@ func checkVolumes(pipeline *yaml.Pipeline, trusted bool) error { func checkHostPathVolume(volume *yaml.VolumeHostPath, trusted bool) error { if trusted == false { - return errors.New("linter: untrusted repositories cannot mount host volumes") + return errors.New("linter: untrusted repsitories cannot mount host volumes") } return nil } func checkEmptyDirVolume(volume *yaml.VolumeEmptyDir, trusted bool) error { if trusted == false && volume.Medium == "memory" { - return errors.New("linter: untrusted repositories cannot mount in-memory volumes") + return errors.New("linter: untrusted repsitories cannot mount in-memory volumes") } return nil } diff --git a/vendor/github.com/drone/drone-yaml/yaml/param.go b/vendor/github.com/drone/drone-yaml/yaml/param.go index b66579ef..9f94bffe 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/param.go +++ b/vendor/github.com/drone/drone-yaml/yaml/param.go @@ -16,7 +16,7 @@ type ( } ) -// UnmarshalYAML implements yaml unmarshalling. +// UnmarshalYAML implements yaml unmarhsaling. func (p *Parameter) UnmarshalYAML(unmarshal func(interface{}) error) error { d := new(parameter) err := unmarshal(d) diff --git a/vendor/github.com/drone/drone-yaml/yaml/port.go b/vendor/github.com/drone/drone-yaml/yaml/port.go index 79d90855..983e412f 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/port.go +++ b/vendor/github.com/drone/drone-yaml/yaml/port.go @@ -16,7 +16,7 @@ type ( } ) -// UnmarshalYAML implements yaml unmarshalling. +// UnmarshalYAML implements yaml unmarhsaling. func (p *Port) UnmarshalYAML(unmarshal func(interface{}) error) error { out := new(port) err := unmarshal(&out.Port) diff --git a/vendor/github.com/drone/drone-yaml/yaml/push.go b/vendor/github.com/drone/drone-yaml/yaml/push.go index d65b2b20..bb3a6d1e 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/push.go +++ b/vendor/github.com/drone/drone-yaml/yaml/push.go @@ -13,7 +13,7 @@ type ( } ) -// UnmarshalYAML implements yaml unmarshalling. +// UnmarshalYAML implements yaml unmarhsaling. func (p *Push) UnmarshalYAML(unmarshal func(interface{}) error) error { d := new(push) err := unmarshal(&d.Image) diff --git a/vendor/github.com/drone/drone-yaml/yaml/unit.go b/vendor/github.com/drone/drone-yaml/yaml/unit.go index 7c947ac1..e9e759e3 100644 --- a/vendor/github.com/drone/drone-yaml/yaml/unit.go +++ b/vendor/github.com/drone/drone-yaml/yaml/unit.go @@ -7,7 +7,7 @@ import "github.com/docker/go-units" // (eg. "44kiB", "17MiB"). type BytesSize int64 -// UnmarshalYAML implements yaml unmarshalling. +// UnmarshalYAML implements yaml unmarhsaling. func (b *BytesSize) UnmarshalYAML(unmarshal func(interface{}) error) error { var intType int64 if err := unmarshal(&intType); err == nil {