1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

add asset migration to setup process

This commit is contained in:
checktheroads
2020-02-15 20:02:47 -07:00
parent f45b149832
commit 354f789403
4 changed files with 71 additions and 34 deletions

View File

@@ -1,25 +1,28 @@
FROM ubuntu:bionic as base
# ENV LC_ALL=C.UTF-8
# ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
WORKDIR /tmp
RUN curl -sL https://deb.nodesource.com/setup_13.x | bash - \
RUN apt-get update \
&& apt-get install -y git curl net-tools \
&& curl -sL https://deb.nodesource.com/setup_13.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y git curl net-tools python3 python3-pip python3-venv redis-server nodejs yarn \
&& apt-get install -y python3 python3-pip python3-venv redis-server nodejs yarn \
&& curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 \
&& git clone --single-branch --branch v1.0.0 --depth 1 https://github.com/checktheroads/hyperglass \
&& ln -s $(which python3) /usr/bin/python \
&& echo "Python Version: $(python --version)" \
&& echo "NodeJS Version: $(node --version)" \
&& echo "Yarn Version: $(yarn --version)"
ENV PATH=$PATH:$HOME/.poetry/bin
&& python3 --version \
&& echo "NodeJS $(node --version)" \
&& echo "Yarn $(yarn --version)" \
&& git clone --single-branch --branch v1.0.0 --depth 1 https://github.com/checktheroads/hyperglass
ENV PATH=$PATH:/root/.poetry/bin
# ENV BASH_ENV=/etc/profile exec bash
FROM base
WORKDIR $HOME
RUN bash -c 'BASH_ENV=/etc/profile exec bash' \
&& $HOME/.poetry/bin/poetry install --no-ansi \
&& $HOME/.poetry/bin/poetry run hyperglass setup -d
&& $HOME/.poetry/bin/poetry run hyperglass build-ui
FROM base as install
WORKDIR ./hyperglass
RUN poetry install --no-ansi
FROM install as setup
WORKDIR ./hyperglass
RUN poetry run hyperglass setup -d
EXPOSE 8001
CMD poetry run hyperglass start

View File

@@ -106,7 +106,13 @@ def generate_secret(length):
)
def setup(unattended):
"""Define application directory, move example files, generate systemd service."""
from hyperglass.cli.util import create_dir, move_files, make_systemd, write_to_file
from hyperglass.cli.util import (
create_dir,
move_files,
make_systemd,
write_to_file,
migrate_static_assets,
)
user_path = Path.home() / "hyperglass"
root_path = Path("/etc/hyperglass/")
@@ -158,3 +164,5 @@ def setup(unattended):
systemd_file = install_path / "hyperglass.service"
systemd = make_systemd(user)
write_to_file(systemd_file, systemd)
migrate_static_assets(install_path)

View File

@@ -358,3 +358,20 @@ def write_to_file(file, data):
elif file.exists():
success("Wrote systemd file {f}", f=file)
return True
def migrate_static_assets(app_path):
"""Migrate app's static assets to app_path.
Arguments:
app_path {Path} -- hyperglass runtime path
"""
from hyperglass.util import migrate_static_assets as _migrate
migrated, msg, a, b = _migrate(app_path)
if not migrated:
callback = error
elif migrated:
callback = success
callback(msg, a=a, b=b)

View File

@@ -255,6 +255,31 @@ async def move_files(src, dst, files): # noqa: C901
return migrated
def migrate_static_assets(app_path):
"""Compare repository's static assets with build directory's assets.
If the contents don't match, re-copy the files.
"""
import shutil
from pathlib import Path
from filecmp import dircmp
asset_dir = Path(__file__).parent.parent / "images"
target_dir = app_path / "static" / "images"
comparison = dircmp(asset_dir, target_dir, ignore=[".DS_Store"])
if not comparison.left_list == comparison.right_list:
shutil.copytree(asset_dir, target_dir)
if not comparison.left_list == comparison.right_list:
return (
False,
"Files in {a} do not match files in {b}",
str(asset_dir),
str(target_dir),
)
return (True, "Migrated assets from {a} to {b}", str(asset_dir), str(target_dir))
async def check_node_modules():
"""Check if node_modules exists and has contents.
@@ -346,8 +371,6 @@ async def build_frontend( # noqa: C901
"""
import hashlib
import tempfile
import shutil
from filecmp import dircmp
from pathlib import Path
from aiofile import AIOFile
import ujson as json
@@ -434,22 +457,8 @@ async def build_frontend( # noqa: C901
elif dev_mode and not force:
log.debug("Running in developer mode, did not build new UI files")
"""
Compare repository's static assets with build directory's
assets. If the contents don't match, re-copy the files.
"""
asset_dir = Path(__file__).parent.parent / "images"
target_dir = app_path / "static" / "images"
comparison = dircmp(asset_dir, target_dir, ignore=[".DS_Store"])
migrate_static_assets()
if not comparison.left_list == comparison.right_list:
shutil.copytree(asset_dir, target_dir)
if not comparison.left_list == comparison.right_list:
raise Exception(
"Files in '{a}' do not match files in '{b}'".format(
a=str(asset_dir), b=str(target_dir)
)
)
except Exception as e:
raise RuntimeError(str(e))