Thanks to visit codestin.com
Credit goes to github.com

Skip to content

create pattern construct for a webapp extension #10701

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

Merged
merged 3 commits into from
Apr 24, 2024
Merged

Conversation

thrau
Copy link
Member

@thrau thrau commented Apr 21, 2024

Motivation

Webapp extensions such as:

Follow a common pattern. They

  • expose routes through subdomains and submounts (http://my-extension.localhost.localstack.cloud:4566, and http://localhost.localstack.cloud:4566/_extension/my-extension)
  • Enable logging for their root module my_extension
  • Serve jinja2 templates
  • Serve static files

Their file layout will typically look like this:

my_extension
├── extension.py
├── __init__.py
├── static              <-- make sure static resources get packaged!
│   ├── __init__.py
│   ├── favicon.ico
│   └── style.css
└── templates            <-- jinja2 templates
   └── index.html

This PR introduces this pattern as a class that can be extended to quickly develop extensions like this.

Examples of how existing extensions have been simplified can be found in:

Requires Rolo v0.5.0

Changes

  • Introduce localstack.extension.patterns
  • Add a high-level pattern WebAppExtension

Testing

If you want to test this you can:

TODO

What's left to do:

  • Wait for rolo dependency to be updated v0.5.0

@thrau thrau added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Apr 21, 2024
@thrau thrau requested a review from joe4dev April 21, 2024 14:42
Copy link

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 31m 41s ⏱️ + 1m 33s
2 890 tests ±0  2 606 ✅ ±0  284 💤 ±0  0 ❌ ±0 
2 892 runs  ±0  2 606 ✅ ±0  286 💤 ±0  0 ❌ ±0 

Results for commit eff4d80. ± Comparison against base commit 51b397f.

@thrau thrau added this to the 3.4 milestone Apr 21, 2024
@thrau thrau marked this pull request as ready for review April 22, 2024 19:45
Copy link
Member

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

Looking at the extension examples, it makes the API so much easier to use. Auto-CORS config is a nice extra as well. 🙌

I tested these changes with the https://github.com/localstack/localstack-extension-event-studio and it works like a charm. 👍

I'm not so familiar with our routing internals and would suggest someone else signing it off, for example @alexrashed or @dfangl.

@joe4dev joe4dev requested review from alexrashed and dfangl April 23, 2024 16:57
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

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

Really nice abstraction, which saves a lot of repetitive code among the different extension implementations, but also helps tackling edge cases in a generic way (f.e. the 301 redirect for relative imports)! 🚀
I think this can be merged as is (after removing the container.py). 🥳

@thrau thrau force-pushed the extension-patterns branch from eff4d80 to 7e1cf6d Compare April 24, 2024 16:17
@thrau thrau added semver: patch Non-breaking changes which can be included in patch releases and removed semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases labels Apr 24, 2024
@thrau
Copy link
Member Author

thrau commented Apr 24, 2024

marking this as patch since it is purely additive and affects no existing localstack control paths

@thrau thrau merged commit e8c8629 into master Apr 24, 2024
@thrau thrau deleted the extension-patterns branch April 24, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants