Implement env plugin. #39

Merged
merged 1 commit into from Mar 9, 2016

Projects

None yet

3 participants

@walac
Contributor
walac commented Mar 8, 2016

env plugin is responsible to process the section "env" from the task
payload. It setups environment variables inside the sandbox.

@petemoore petemoore was assigned by walac Mar 8, 2016
@jonasfj jonasfj and 1 other commented on an outdated diff Mar 8, 2016
plugins/env/payload-schema.yml
@@ -0,0 +1,6 @@
+$schema: http://json-schema.org/draft-04/schema#
+title: "EnvPayload"
+type: "object"
+patternProperties:
+ .+:
+ type: string
@jonasfj
jonasfj Mar 8, 2016 Member

Don't use pattern properties...
Just use additionalProperties: {type: string}

Also add some "description" properties, ideally with a description that can serve as documentation... It doesn't have to be long, but a line, two or 5 would be good. Usually using markdown in description properties is fine, we do it everywhere...

@walac
walac Mar 8, 2016 Contributor

Fixed.

@walac
Contributor
walac commented Mar 8, 2016

Why must generated_*.go files be checked in?

@jonasfj
Member
jonasfj commented Mar 8, 2016

Why must generated_*.go files be checked in?

Because they are hard to generate... there are pros/cons... but they aren't generated by go build so it's nice to do... especially because it prevents anyone from using it as a library..

@walac
Contributor
walac commented Mar 8, 2016

Implementation changed based on what @petemoore, @jonasfj and I discussed.

@jonasfj jonasfj commented on an outdated diff Mar 8, 2016
plugins/env/env.go
+ return taskPlugin{
+ TaskPluginBase: plugins.TaskPluginBase{},
+ payload: options.Payload.(envPayload),
+ }, nil
+}
+
+type taskPlugin struct {
+ plugins.TaskPluginBase
+ payload envPayload
+}
+
+func (self taskPlugin) BuildSandbox(sandboxBuilder engines.SandboxBuilder) error {
+ for k, v := range self.payload {
+ err := sandboxBuilder.SetEnvironmentVariable(k, v)
+ if err != nil {
+ return err
@jonasfj
jonasfj Mar 8, 2016 Member

Most errors here should be transformed to MalformedPayloadError see: https://github.com/taskcluster/taskcluster-worker/blob/2130156c8e55bdc710af9a7c16e5877844ef7f17/engines/sandboxbuilder.go#L64-L73

Basically, ErrNamingConflict is a problem that can be solved by changing the task payload. The same is the case for ErrFeatureNotSupported, if env vars aren't support... user just shouldn't specify any...

@jonasfj
jonasfj Mar 8, 2016 Member

Errors other than the ones specified as "Non-fatal errors" in https://github.com/taskcluster/taskcluster-worker/blob/2130156c8e55bdc710af9a7c16e5877844ef7f17/engines/sandboxbuilder.go#L64-L73

Can be passed through as you have no possible way to handle those gracefully. Thus they must be fatal.

@walac walac Implement env plugin.
env plugin is responsible to process the "env" section from the task
payload. It setups environment variables inside the sandbox.
e16de29
@jonasfj
Member
jonasfj commented Mar 9, 2016

r+

@petemoore
Member

This looks awesome! Tests too! ++

@walac walac merged commit 1587a61 into taskcluster:master Mar 9, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment