-
Notifications
You must be signed in to change notification settings - Fork 729
ui: add gae internal server code #5339
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # This file specifies files that are *not* uploaded to Google Cloud | ||
| # using gcloud. It follows the same syntax as .gitignore, with the addition of | ||
| # "#!include" directives (which insert the entries of the given .gitignore-style | ||
| # file at that point). | ||
| # | ||
| # For more information, run: | ||
| # $ gcloud topic gcloudignore | ||
| # | ||
| .gcloudignore | ||
| # If you would like to upload your .git directory, .gitignore file or files | ||
| # from your .gitignore file, remove the corresponding line | ||
| # below: | ||
| .git | ||
| .gitignore | ||
|
|
||
| # Python pycache: | ||
| __pycache__/ | ||
| # Ignored by the build system | ||
| /setup.cfg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| runtime: python312 | ||
|
|
||
| entrypoint: gunicorn -b :$PORT main:app | ||
|
|
||
| instance_class: F1 | ||
|
|
||
| automatic_scaling: | ||
| max_instances: 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/bash | ||
| gcloud app deploy app.yaml --project google.com:perfetto-gae-internal | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import posixpath | ||
|
|
||
| from flask import Flask, Response, abort | ||
| from flask_cors import CORS | ||
| from google.cloud import storage | ||
|
|
||
| app = Flask(__name__) | ||
| CORS(app, origins=["https://ui.perfetto.dev", "http://localhost:10000"], supports_credentials=True) | ||
|
|
||
| BUCKET_NAME = "perfetto-ui-internal" | ||
| BASE_PREFIX = "extension-server-v1" | ||
|
|
||
| gcs_client = storage.Client() | ||
| bucket = gcs_client.bucket(BUCKET_NAME) | ||
|
|
||
|
|
||
| @app.route("/", defaults={"path": ""}) | ||
| @app.route("/<path:path>") | ||
| def serve(path): | ||
| # Normalize and reject any path traversal attempts. | ||
| normalized = posixpath.normpath(path) if path else "" | ||
| if normalized.startswith("..") or "/../" in normalized or normalized.startswith("/"): | ||
| abort(403) | ||
|
|
||
| blob_path = f"{BASE_PREFIX}/{normalized}" if normalized else BASE_PREFIX + "/" | ||
|
|
||
| blob = bucket.blob(blob_path) | ||
| if not blob.exists(): | ||
| abort(404) | ||
|
|
||
| data = blob.download_as_bytes() | ||
| content_type = blob.content_type or "application/octet-stream" | ||
| return Response(data, content_type=content_type) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app.run(host="127.0.0.1", port=8080, debug=True) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Flask==3.0.0 | ||
| Flask-Cors==4.0.0 | ||
| google-cloud-storage==2.14.0 | ||
| gunicorn==21.2.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.