1
0
Fork 0
mirror of https://github.com/drone/drone-cli.git synced 2024-06-02 12:16:01 +02:00

downgrade yaml package pending runtime fixes

This commit is contained in:
Brad Rydzewski 2018-11-15 14:03:59 -08:00
parent 72ee0689fd
commit bd829e84ca
18 changed files with 54 additions and 107 deletions

6
Gopkg.lock generated
View File

@ -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

View File

@ -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"

View File

@ -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)

View File

@ -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,
})
}

View File

@ -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()
}

View File

@ -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)
}
}
}
}

View File

@ -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

View File

@ -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{

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -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{},
},

View File

@ -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
}

View File

@ -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)

View File

@ -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
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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 {