Commit be17a931 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

[Lorenz] Create script to deploy dependency graph viewer to Firebase

Heavily based on tools/binary_size/libsupersize/upload_html_viewer.py.

Bug: 1111056
Change-Id: I71dfe9850e60a0f194ffe42896e79335f273c6d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333453
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794681}
parent 1bc87ec0
...@@ -67,6 +67,15 @@ npm run build && npm run serve-dist ...@@ -67,6 +67,15 @@ npm run build && npm run serve-dist
**To view the visualization, open `localhost:8888/package_view.html`.** **To view the visualization, open `localhost:8888/package_view.html`.**
### Deploy
The Chromium Dependency Graph Visualizer is hosted at
https://chromium-dependency-graph.firebaseapp.com.
If you are a Googler, you can see this [doc][deploy doc] for how to deploy a new
version of the viewer.
[deploy doc]: https://docs.google.com/document/d/1u4wlB2EAWNx8zkQr60CQbxDD_Ji_mgSGjhBvX6K8IdM/edit?usp=sharing
### Miscellaneous ### Miscellaneous
To run [ESLint](https://eslint.org/) on the JS and Vue files: To run [ESLint](https://eslint.org/) on the JS and Vue files:
``` ```
......
#!/usr/bin/env python3
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Deploy the Dependency Graph Viewer to Firebase hosting."""
import shutil
import subprocess
import tempfile
from pathlib import Path
FIREBASE_PROJECT = 'chromium-dependency-graph'
JS_DIR = Path(__file__).parent / 'js'
def _Prompt(message):
"""Prompt the user with a message and request affirmative outcome."""
choice = input(message + ' [y/N] ').lower()
return choice and choice[0] == 'y'
def _FirebaseLogin():
"""Login into the Firebase CLI"""
subprocess.check_call(['firebase', 'login'])
def _CheckFirebaseCLI():
"""Fail with a proper error message, if Firebase CLI is not installed."""
if subprocess.call(['firebase', '--version'],
stdout=subprocess.DEVNULL) != 0:
link = 'https://firebase.google.com/docs/cli#install_the_firebase_cli'
raise Exception(
'Firebase CLI not installed or not on your PATH. Follow '
'the instructions at ' + link + ' to install')
def _CheckNPM():
"""Fail with a proper error message, if npm is not installed."""
if subprocess.call(['npm', '--version'], stdout=subprocess.DEVNULL) != 0:
link = 'https://nodejs.org'
raise Exception(
'npm not installed or not on your PATH. Either install Node.js '
'through your package manager or download it from ' + link + '.')
def _BuildDist():
"""Build distribution files."""
subprocess.check_call(['npm', 'run', '--prefix', JS_DIR, 'build'])
return JS_DIR / 'dist'
def _FirebaseInitProjectDir(project_dir):
"""Create a firebase.json file that is needed for deployment."""
project_static_dir = project_dir / 'public'
with open(project_dir / 'firebase.json', 'w') as f:
f.write("""
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/README*",
"**/.*"
]
}
}
""")
return project_static_dir
def _FirebaseDeploy(project_dir):
"""Deploy the project to firebase hosting."""
subprocess.check_call(['firebase', 'deploy', '-P', FIREBASE_PROJECT],
cwd=project_dir)
def _CopyDistFiles(dist_dir, project_static_dir):
"""Copy over static files from the dist directory."""
shutil.copytree(dist_dir, project_static_dir)
def main():
message = (
f"""This script builds the Clank Dependency Graph Visualizer and \
deploys it to Firebase hosting at {FIREBASE_PROJECT}.firebaseapp.com.
Please ensure you have read the instructions at //{JS_DIR}/README.md first \
before running this.
Are you sure you want to continue?""")
if not _Prompt(message):
print('Nothing was deployed.')
return
_CheckFirebaseCLI()
_CheckNPM()
_FirebaseLogin()
dist_dir = _BuildDist()
with tempfile.TemporaryDirectory(prefix='firebase-') as project_dir_str:
project_dir = Path(project_dir_str)
project_static_dir = _FirebaseInitProjectDir(project_dir)
shutil.copytree(dist_dir, project_static_dir)
_FirebaseDeploy(project_dir)
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment