Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workaround to support yaml anchors #103

Closed
wants to merge 1 commit into from

Conversation

jmccann
Copy link
Contributor

@jmccann jmccann commented Oct 11, 2018

Adding a workaround to allow yaml anchors to work with drone-cli. They have been working fine with Drone 0.8.6 server/agents.

This works by unmarshalling from []byte yaml to a map[string]interface{} and then back to a []byte yaml. During this process the anchors are "compiled". So

some-anchor: &some-anchor
  image: alpine:3.7
  commands:
    - echo "hello world"

pipeline:
  foo:
    <<: *some-anchor

Then becomes:

pipeline:
  foo:
    commands:
    - echo "hello world"
    image: alpine:3.7

some-anchor:
  commands:
  - echo "hello world"
  image: alpine:3.7

@bradrydzewski
Copy link
Contributor

I wonder if we apply this patch to go-yaml if it will work?

[[constraint]]
  branch = "fix-for-issue-91"
  name = "gopkg.in/yaml.v2"
  source = "https://github.com/vinzenz/yaml.git"

@bradrydzewski
Copy link
Contributor

also just a heads up that the CLI in master changed to support 0.9 (some deprecated API calls were removed, some structures changed). So we probably need to branch 0.8.6 and update.

@jmccann
Copy link
Contributor Author

jmccann commented Oct 11, 2018

You think the issue is with that package? I'm not sure since I'm using that package to "fix" this.

And yes, would love to be able to fix in 0.8.6 also. The "patch" I PM'd you earlier was against the 0.8.6 code.

@bradrydzewski
Copy link
Contributor

I think it could be at the package level. This is the particular issue that seems similar to what you are describing: go-yaml/yaml#91

@jmccann
Copy link
Contributor Author

jmccann commented Oct 11, 2018

So I added the following to Gopkg.toml:

+[[override]]
+  branch = "fix-for-issue-91"
+  name = "gopkg.in/yaml.v2"
+  source = "https://github.com/vinzenz/yaml.git"

And did a dep ensure to update local vendor.

I then ran and got:

» go build -o drone.bin github.com/drone/drone-cli/drone && ./drone.bin exec           
panic: reflect.Value.Addr of unaddressable value [recovered]
	panic: reflect.Value.Addr of unaddressable value [recovered]
	panic: reflect.Value.Addr of unaddressable value

goroutine 1 [running]:
github.com/drone/drone-cli/vendor/gopkg.in/yaml%2ev2.handleErr(0xc42022f420)
	/Users/z087177/go/src/github.com/drone/drone-cli/vendor/gopkg.in/yaml.v2/yaml.go:164 +0x99
panic(0x14a9ca0, 0x15f3580)
	/usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:502 +0x229
github.com/drone/drone-cli/vendor/gopkg.in/yaml%2ev2.handleErr(0xc42022ec98)
	/Users/z087177/go/src/github.com/drone/drone-cli/vendor/gopkg.in/yaml.v2/yaml.go:164 +0x99
panic(0x14a9ca0, 0x15f3580)
	/usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:502 +0x229
reflect.Value.Addr(0x14d45a0, 0xc42035e7e0, 0x15, 0xb, 0xc42039e268, 0x1)
	/usr/local/Cellar/go/1.10.3/libexec/src/reflect/value.go:245 +0x94
github.com/drone/drone-cli/vendor/gopkg.in/yaml%2ev2.(*decoder).alias(0xc420360cc0, 0xc420396700, 0x14d45a0, 0xc42035e7e0, 0x15, 0x1012089)
	/Users/z087177/go/src/github.com/drone/drone-cli/vendor/gopkg.in/yaml.v2/decode.go:400 +0x47c
...

So it didn't seem happy ...

data, err = yamlv2.Marshal(anyJSON)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.9 supports multi-document yaml files which would be problematic here. But we can definitely backport this to 0.8. I will create an 0.8 branch tomorrow morning that we can use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there documentation around that so I can try to understand the issue. Looking at the cli source it seems it looks for a single file, defaulting to .drone.yml, and reads the file and starts using it.

Thanks for the help on this!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the yaml.Unmarshal will not work with a multi-document yaml like this https://github.com/drone/drone-git/blob/master/.drone.yml :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants