Skip to content

examples: add an example of importing local lua code#7629

Merged
mattklein123 merged 8 commits intoenvoyproxy:masterfrom
cetanu:patch-1
Jul 29, 2019
Merged

examples: add an example of importing local lua code#7629
mattklein123 merged 8 commits intoenvoyproxy:masterfrom
cetanu:patch-1

Conversation

@cetanu
Copy link
Copy Markdown
Contributor

@cetanu cetanu commented Jul 18, 2019

This extends the existing example of using the Lua HTTP Filter in Envoy, so that there is a basic example of adding a lua file on the disk of the proxy, to be imported via a require statement in the inline code.

@cetanu cetanu changed the title Add an example of importing local on-disk lua code to the examples directory Add an example of importing local lua code to the examples directory Jul 18, 2019
@cetanu cetanu changed the title Add an example of importing local lua code to the examples directory Add an example of importing local lua code Jul 18, 2019
cetanu added 4 commits July 18, 2019 17:03
Signed-off-by: Vasili Syrakis <vsyrakis@atlassian.com>
Signed-off-by: Vasili Syrakis <vsyrakis@atlassian.com>
Signed-off-by: Vasili Syrakis <vsyrakis@atlassian.com>
Signed-off-by: Vasili Syrakis <vsyrakis@atlassian.com>
@zuercher
Copy link
Copy Markdown
Member

Note this fails CI because //test/config_test:example_configs_test loads all the examples (to make certain they stay up-to-date) and can't find your module. I think you need to arrange for the module file to get added to the tar file in test/configs/configgen.sh.

@zuercher zuercher self-assigned this Jul 18, 2019
@cetanu
Copy link
Copy Markdown
Contributor Author

cetanu commented Jul 23, 2019

I've looked through these and don't see any obvious way to get this file added... Any hints?

@zuercher
Copy link
Copy Markdown
Member

zuercher commented Jul 23, 2019

I haven't tried this, but I think the following changes are sufficient:

  1. mylibrary.lua needs to go into a subdirectory under envoy/lua (and update examples/lua/envoy.yaml to match). Let's say that the library is now examples/lua/lib/mylibrary.lua. It doesn't matter much what the subdirectory's name is, but it will need to match what's done in step 3.
  2. In examples/BUILD, add lua/lib/mylibrary.lua to the configs filegroup.
  3. In configs/configgen.sh, we need to handle *.lua files the same way as *.pem files, so make "$OUT_DIR/lib" and add a *.lua entry to copy the files there. Again, the subdirectory needs to match step 1.

The tarball created by configgen.sh (normally found in bazel-bin/configs/example_configs.tar; you can run bazel build //configs:example_configs to generate it) should then contain your config file as lua_envoy.yaml and the library as lib/mylibrary.lua.

Hopefully that all makes sense. The subdirectory in step 1 is necessary because the example config test will try to load every file in the root directory of the tarball as an envoy config (regardless of file extension). Having the subdirectory names in steps 1 & 3 match makes it so the config can be run directly from the examples directory or from the test without modification.

cetanu added 2 commits July 25, 2019 14:33
Signed-off-by: Vasili Syrakis <vsyrakis@atlassian.com>
Signed-off-by: Vasili Syrakis <vsyrakis@atlassian.com>
Signed-off-by: Vasili Syrakis <vsyrakis@atlassian.com>
@cetanu
Copy link
Copy Markdown
Contributor Author

cetanu commented Jul 26, 2019

Sorry about that, I wasn't entirely sure how lua handles imports to nested paths... looks like the last commit may be okay. I hope.

@zuercher
Copy link
Copy Markdown
Member

/retest

@repokitteh-read-only
Copy link
Copy Markdown

🤷‍♀️ nothing to rebuild.

🐱

Caused by: a #7629 (comment) was created by @zuercher.

see: more, trace.

@zuercher
Copy link
Copy Markdown
Member

I think you’ll need to merge master or push an empty commit (`git commit --allow-empty’) to get the missing CI job to run again.

Signed-off-by: Vasili Syrakis <vsyrakis@atlassian.com>
Copy link
Copy Markdown
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Thanks!

@zuercher zuercher changed the title Add an example of importing local lua code examples: add an example of importing local lua code Jul 29, 2019
Copy link
Copy Markdown
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Awesome. Thank you!

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Awesome!

@mattklein123 mattklein123 merged commit ab7ab69 into envoyproxy:master Jul 29, 2019
@cetanu cetanu deleted the patch-1 branch July 31, 2019 00:51
@cetanu
Copy link
Copy Markdown
Contributor Author

cetanu commented Jul 31, 2019

🎉 thanks for helping to get the tests passing, hope this is useful for folks out there

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.

4 participants