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

Can't pass source variables to the exec arguments list #158

Closed
carolynvs opened this issue Feb 12, 2019 · 4 comments
Closed

Can't pass source variables to the exec arguments list #158

carolynvs opened this issue Feb 12, 2019 · 4 comments
Assignees

Comments

@carolynvs
Copy link
Member

This was first implemented in #31 but doesn't seem to work anymore.

When you run this, replace TODO with your username.

mixins:
  - exec

name: HELLO
version: 0.1.0
description: "An example Porter configuration"
invocationImage: TODO/porter-hello:latest

parameters:
  - name: cmd
    type: string
    default: "echo hello world"

install:
  - description: "Install Hello World"
    exec:
      command: bash
      arguments:
        - -c
        - source: bundle.parameters.cmd

uninstall:
  - description: "Uninstall Hello World"
    exec:
      command: bash
      arguments:
        - -c
        - echo Goodbye World
$ porter build && duffle install FOO -f bundle.json --insecure
Executing install action...
executing porter install configuration from /cnab/app/porter.yaml
Install Hello World
Error: yaml: unmarshal errors:
  line 6: cannot unmarshal !!map into string
err: yaml: unmarshal errors:
  line 6: cannot unmarshal !!map into string
@nunix
Copy link

nunix commented Feb 12, 2019

just for information, I got the exact same issue by running with porter only:

porter run --action install --file ./porter.yaml --debug

really looking forward to this fix :)

@jeremyrickard
Copy link
Contributor

jeremyrickard commented Feb 12, 2019

This turns out not to be a problem with the way the parameter sourcing is working exactly..., it's a "how go is parsing YAML and reflection" problem. You can pass the params, with slightly different YAML right now.

The yaml above fails (here it is again):

install:
  - description: "Install Hello World"
    exec:
      command: bash
      arguments:
        - -c
        - source: bundle.parameters.cmd

However.....this does work

install:
  - description: "Install Hello World"
    exec:
      command: bash
      arguments:
        - -c
        - "source: bundle.parameters.cmd"

When the YAML blob gets loaded to process, it's failing to handle that correctly. Working on a fix now.

@nunix
Copy link

nunix commented Feb 13, 2019

I tried the workaround and the values are empty (still based on my yaml file). Which I think it's because I do directly the command porter run --action install --file ./porter.yaml --debug instead of piping it like Carolyn did in her example.

My porter version is:
image

@carolynvs
Copy link
Member Author

carolynvs commented Feb 13, 2019

I think I know what you are running into!

Short answer:

Set an environment variable named after the parameter that you are trying to access (or matching the destination env var used) before running porter run. So to match my porter.yaml above, I would set $env:CMD = "echo hello world".

Long answer:

porter is intended to execute inside of a CNAB environment. From the spec, parameters are either exported as environment variables in the environment or as files (depending on how they are defined in the bundle). Porter reads parameters and credentials not from the porter.yaml but from the CNAB environment. That's why you saw in my examples that I was running a duffle install. If you do a porter run directly, you'll need to provide those environment variables or files yourself.

jeremyrickard added a commit to jeremyrickard/porter that referenced this issue Feb 13, 2019
…put sourcing

This PR updates how we handle slice elements for doing parameter/credential/ouput sourcing.
We probably should think about revisitng the entire process for this in the future.

In summary, we are using reflectwalk to handle walking the manifest. This involves handling a couple
call backs, notably "SliceElement" and "MapElement". The Slice Element assumed that it would see something
of the form source: <x.y.z> as a string. In reality, if that's not wrapped in quote, Go and YAML see that
as a Map, but the map callback doesn't get called to handle that. This was resulting in the block not getting
rewritten and the exec mixin was exploding (probably any would have). This PR updates the logic of the slice elem
processing to check and see if it's a map and handle it in a similar manner to a top level map entry in the yaml.

Closes: getporter#158
jeremyrickard added a commit to jeremyrickard/porter that referenced this issue Feb 13, 2019
…put sourcing

This PR updates how we handle slice elements for doing parameter/credential/ouput sourcing.
We probably should think about revisitng the entire process for this in the future.

In summary, we are using reflectwalk to handle walking the manifest. This involves handling a couple
call backs, notably "SliceElement" and "MapElement". The Slice Element assumed that it would see something
of the form source: <x.y.z> as a string. In reality, if that's not wrapped in quote, Go and YAML see that
as a Map, but the map callback doesn't get called to handle that. This was resulting in the block not getting
rewritten and the exec mixin was exploding (probably any would have). This PR updates the logic of the slice elem
processing to check and see if it's a map and handle it in a similar manner to a top level map entry in the yaml.

Closes: getporter#158
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

No branches or pull requests

3 participants