From d846c65ae6929500a4b19563467c8487269d0006 Mon Sep 17 00:00:00 2001 From: Peter Pan Date: Mon, 18 May 2020 18:40:53 +0800 Subject: [PATCH] add build docker file (#635) * fix: high-dimensional page error when runs and tags mismatching * build: fix build error and add docker build * build: fix build error and add docker build * build: fix build error and add docker build --- .dockerignore | 144 ++++++++++++++++++ Dockerfile | 11 ++ .../packages/core/pages/high-dimensional.tsx | 2 +- frontend/scripts/build.sh | 3 +- frontend/scripts/install.sh | 6 +- scripts/build.sh | 4 +- visualdl/server/app.py | 31 ++-- 7 files changed, 181 insertions(+), 20 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..cb6c34a3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,144 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +*.dll + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +.DS_Store + +# PyCharm IDE +.idea/ + +/.vscode +.tool-versions + +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +node_modules +.pnp +.pnp.js + +# testing +coverage + +# next.js +.next + +# production +build +dist + +# misc +.DS_Store +.env* +.vscode + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# output +output + +# wasm target +frontend/packages/wasm/target diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..02edac56 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM nikolaik/python-nodejs:python3.8-nodejs14 + +WORKDIR /home/visualdl + +COPY . /home/visualdl + +RUN ["apt", "update"] +RUN ["apt", "-y", "install", "cmake"] +RUN ["pip", "install", "-r", "requirements.txt"] + +CMD ["python", "setup.py", "bdist_wheel"] diff --git a/frontend/packages/core/pages/high-dimensional.tsx b/frontend/packages/core/pages/high-dimensional.tsx index 2004554e..e0f73f0e 100644 --- a/frontend/packages/core/pages/high-dimensional.tsx +++ b/frontend/packages/core/pages/high-dimensional.tsx @@ -70,7 +70,7 @@ const HighDimensional: NextI18NextPage = () => { return []; } return runs.reduce( - (p, run) => [...p, ...(tags[run].map(tag => ({run, tag, label: `${run}/${tag}`})) ?? [])], + (p, run) => [...p, ...(tags[run]?.map(tag => ({run, tag, label: `${run}/${tag}`})) ?? [])], [] ); }, [runs, tags]); diff --git a/frontend/scripts/build.sh b/frontend/scripts/build.sh index 0e30cb54..d26a962f 100755 --- a/frontend/scripts/build.sh +++ b/frontend/scripts/build.sh @@ -11,8 +11,7 @@ OUTPUT="output" OUTPUT_PATH="$WORKING_PATH/$OUTPUT" # clean -rm -rf "$SERVER_DIR_PATH" -rm -rf "$SERVERLESS_DIR_PATH" +yarn clean # build if [ "$SCOPE" = "serverless" ]; then diff --git a/frontend/scripts/install.sh b/frontend/scripts/install.sh index 423527c0..572e55cd 100755 --- a/frontend/scripts/install.sh +++ b/frontend/scripts/install.sh @@ -6,7 +6,7 @@ set -e # https://rustup.rs/ if ! hash rustup 2>/dev/null; then curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path --default-toolchain nightly -y - source "$HOME/.cargo/env" + PATH="$HOME/.cargo/bin:$PATH" fi @@ -21,8 +21,10 @@ fi # yarn if ! hash yarn 2>/dev/null; then curl --compressed -o- -L https://yarnpkg.com/install.sh | bash - export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" + PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" fi +export PATH=$PATH + # yarn install yarn install --frozen-lockfile diff --git a/scripts/build.sh b/scripts/build.sh index 48fe7313..df40b2ac 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -15,8 +15,8 @@ build_frontend() { mkdir -p "$BUILD_DIR/package/dist" cd "$FRONTEND_DIR" - ./scripts/install.sh - SCOPE="serverless" PUBLIC_PATH="/{{PUBLIC_PATH}}" API_URL="/{{PUBLIC_PATH}}/api" ./scripts/build.sh + . ./scripts/install.sh + SCOPE="serverless" PUBLIC_PATH="/{{PUBLIC_PATH}}" API_URL="/{{PUBLIC_PATH}}/api" PATH="$PATH" ./scripts/build.sh # extract tar zxf "$FRONTEND_DIR/output/serverless.tar.gz" -C "$BUILD_DIR/package/dist" diff --git a/visualdl/server/app.py b/visualdl/server/app.py index 7c005d0c..3695fb6c 100644 --- a/visualdl/server/app.py +++ b/visualdl/server/app.py @@ -191,6 +191,7 @@ def create_app(args): @app.route(public_path + '/') def serve_static(filename): + print(static_file_path, filename) return send_from_directory( os.path.join(server_path, static_file_path), filename if re.search(r'\..+$', filename) else filename + '.html') @@ -333,6 +334,18 @@ def _open_browser(app, index_url): webbrowser.open(index_url) +def render_template(args): + template.render( + template_file_path, + static_file_path, + PUBLIC_PATH=args.public_path.strip('/')) + + +def clean_template(signalnum, frame): + template.clean(static_file_path) + sys.exit(0) + + def _run(logdir, host="127.0.0.1", port=8080, @@ -349,6 +362,10 @@ def _run(logdir, cache_timeout=cache_timeout, language=language, public_path=public_path) + args = parse_args() + render_template(args) + for sig in [signal.SIGINT, signal.SIGHUP, signal.SIGTERM]: + signal.signal(sig, clean_template) logger.info(" port=" + str(args.port)) app = create_app(args) index_url = "http://" + host + ":" + str(port) + args.public_path @@ -383,18 +400,6 @@ def run(logdir, return p.pid -def render_template(args): - template.render( - template_file_path, - static_file_path, - PUBLIC_PATH=args.public_path.strip('/')) - - -def clean_template(signalnum, frame): - template.clean(static_file_path) - sys.exit(0) - - def main(): args = parse_args() render_template(args) @@ -402,7 +407,7 @@ def main(): signal.signal(sig, clean_template) logger.info(" port=" + str(args.port)) app = create_app(args) - app.run(debug=False, host=args.host, port=args.port, threaded=False) + app.run(debug=False, host=args.host, port=args.port, threaded=True) if __name__ == "__main__": -- GitLab