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

opa build -t wasm doesn't generate bundle.tar.gz #3270

Closed
onelittlenightmusic opened this issue Mar 15, 2021 · 7 comments · Fixed by #3276
Closed

opa build -t wasm doesn't generate bundle.tar.gz #3270

onelittlenightmusic opened this issue Mar 15, 2021 · 7 comments · Fixed by #3276
Labels

Comments

@onelittlenightmusic
Copy link
Contributor

onelittlenightmusic commented Mar 15, 2021

opa build doesn't seem to be able to generate bundle.tar.gz after 0.27.0. Before 0.26.0, it works well.

Expected Behavior

opa build -t wasm -e hello/hello hello.rego
(no error and generated bundle.tar.gz)

Actual Behavior

Using v0.27.0 or later

bin/opa0.27.0 build -t wasm -e hello/hello hello.rego
error: compiler ABI version not in capabilities (have [], want {1 1})

Using v0.26.0, this command works.

bin/opa0.26.0 build -t wasm -e hello/hello hello.rego
(no error)

Steps to Reproduce the Problem

  • Create a file hello.rego
package hello

default hello = ""

hello = rtn {
    m := input.message
    rtn := concat("", ["hello, ", m])
}
opa  build -t wasm -e hello/hello hello.rego

Environment

  • MacOS 11.2.3 (big sur)
  • Each version of binaries were separately downloaded from release page.
    Thank you, all the community!!

Additional Info

I am not sure if this is related to #3264 or not..

@srenatus
Copy link
Contributor

You'll have to provide a capabilities json of the target version. Your cli executable doesn't have wasm enabled so it won't build what it cannot run.

@onelittlenightmusic
Copy link
Contributor Author

@srenatus Thank you so much for your advice! You saved my day. I downloaded the following file to the same directory.
https://github.com/open-policy-agent/opa/blob/master/capabilities/v0.27.1.json
And I ran this command.

opa build -t wasm -e hello/hello hello.rego --capabilities v0.27.1.json

Finally, I got bundle.tar.gz correctly. I appreciate that.

I guess a description about necessity of capacilities json can be added in the following document. What do you think about it?
https://www.openpolicyagent.org/docs/latest/wasm/#compiling-policies

# download
curl -L -o  v0.27.1.json https://raw.githubusercontent.com/open-policy-agent/opa/master/capabilities/v0.27.1.json
opa build -t wasm -e example/allow example.rego --capabilities v<version>.json

@srenatus
Copy link
Contributor

Yup there's definitely a documentation need here. Would you want to contribute a note there or would you prefer if I did that? 😃

@srenatus srenatus added docs bug and removed docs labels Mar 15, 2021
@srenatus
Copy link
Contributor

Nevermind the docs, we'll fix this in code 😅

@onelittlenightmusic
Copy link
Contributor Author

onelittlenightmusic commented Mar 15, 2021

@srenatus Thank you for your comment! I am sorry for late response. If I have a chance, I would like to contribute. I am not familiar with document structure, but I found a likely document in the following document. Is this correct? If so, I will try PR in a few days.
https://github.com/open-policy-agent/opa/blob/master/docs/content/wasm.md
I feel like that the concept of capabilities is vaster than wasm itself. I guess in the future, there might be a documentation need of vast concept of capabilities (is there already such a document?). Anyway, I think at least the description in wasm is needed, so I will make PR.

@srenatus
Copy link
Contributor

Anyway, I think at least the description in wasm is needed, so I will make PR.

Thank you! As hinted on above, I'll put a PR out for changing the default behaviour here. (Next thing, tomorrow at the latest.)

@onelittlenightmusic
Copy link
Contributor Author

Oh, I see. Great! Default behavior change is much better. There will be no need to amend document. No need to hurry. Thank you for all!

srenatus added a commit to srenatus/opa that referenced this issue Mar 15, 2021
We now discern:

1. If there's no Wasm ABI version array at all in the capabilities of
   the `opa` binary used to build a Wasm bundle.
2. If the provided capabilities.json contains EMPTY Wasm ABI versions
   array.

(1.) would happen if the binary itself has no support for running the
Wasm module, i.e. it was built without the `opa_wasm` go tag. Anyways,
such a binary is perfactly capable of emitting wasm code, so that's
what we'll allow it to do (with this change).

(2.) still gives you the option to disable building wasm bundles via
capabilities.json, but it's an edge case: usually, you'd use it to
control the ABI versions you're building for. If you want, however,
you can still say "none" by providing an empty array.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
srenatus added a commit that referenced this issue Mar 16, 2021
We now discern:

1. If there's no Wasm ABI version array at all in the capabilities of
   the `opa` binary used to build a Wasm bundle.
2. If the provided capabilities.json contains EMPTY Wasm ABI versions
   array.

(1.) would happen if the binary itself has no support for running the
Wasm module, i.e. it was built without the `opa_wasm` go tag. Anyways,
such a binary is perfactly capable of emitting wasm code, so that's
what we'll allow it to do (with this change).

(2.) still gives you the option to disable building wasm bundles via
capabilities.json, but it's an edge case: usually, you'd use it to
control the ABI versions you're building for. If you want, however,
you can still say "none" by providing an empty array.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants