thatmattlove / hyperglass

hyperglass is the network looking glass that tries to make the internet better.
https://hyperglass.dev
BSD 3-Clause Clear License
594 stars 88 forks source link

Build UI Error #244

Closed KincaidYang closed 1 month ago

KincaidYang commented 2 months ago

Hi @thatmattlove , I encountered some issues. When running for the first time with docker compose up, everything was normal. However, when I stopped it and started again with systemctl start hyperglass, I ran into this problem. The output from systemctl status hyperglass showed that it was running normally, but in reality, it was unusable. Later, after stopping the service, I tried running it again with docker compose up and encountered the following error. I believe that when a file already exists, it should be overwritten or skipped instead of throwing an exception.

root@rttw /www/wwwroot/hyperglass # docker compose up
[+] Running 1/1
 ✔ Network hyperglass_default         Created                                                                                                                                     0.1s 
 ⠋ Container hyperglass-redis-1       Created                                                                                                                                     0.1s 
 ⠋ Container hyperglass-hyperglass-1  Created                                                                                                                                     0.1s 
Attaching to hyperglass-1, redis-1
redis-1       | 1:C 21 Apr 2024 00:55:28.963 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis-1       | 1:C 21 Apr 2024 00:55:28.963 * Redis version=7.2.4, bits=64, commit=00000000, modified=0, pid=1, just started
redis-1       | 1:C 21 Apr 2024 00:55:28.963 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis-1       | 1:M 21 Apr 2024 00:55:28.963 * monotonic clock: POSIX clock_gettime
redis-1       | 1:M 21 Apr 2024 00:55:28.964 * Running mode=standalone, port=6379.
redis-1       | 1:M 21 Apr 2024 00:55:28.964 * Server initialized
redis-1       | 1:M 21 Apr 2024 00:55:28.964 * Ready to accept connections tcp
hyperglass-1  | [INFO] 20240421 00:55:30 | Starting hyperglass {'version': '2.0.0-dev', 'listening': 'http://0.0.0.0:8001', 'workers': 16}
hyperglass-1  | [INFO] 20240421 00:55:31 | Starting UI build {}
hyperglass-1  | [CRITICAL] 20240421 00:56:26 | [Errno 17] File exists: '/etc/hyperglass/static/ui' {}
hyperglass-1  | ╭───────────────────── Traceback (most recent call last) ──────────────────────╮
hyperglass-1  | │ /opt/hyperglass/hyperglass/cli/main.py:61 in _start                          │
hyperglass-1  | │                                                                              │
hyperglass-1  | │    58 │   │   │   if build_complete:                                         │
hyperglass-1  | │    59 │   │   │   │   run(workers)                                           │
hyperglass-1  | │    60 │   │   else:                                                          │
hyperglass-1  | │ ❱  61 │   │   │   run(workers)                                               │
hyperglass-1  | │    62 │                                                                      │
hyperglass-1  | │    63 │   except (KeyboardInterrupt, SystemExit) as err:                     │
hyperglass-1  | │    64 │   │   error_message = str(err)                                       │
hyperglass-1  | │                                                                              │
hyperglass-1  | │ ╭───────────────────── locals ─────────────────────╮                         │
hyperglass-1  | │ │    build = False                                 │                         │
hyperglass-1  | │ │ build_ui = <function build_ui at 0x7f75196f9bc0> │                         │
hyperglass-1  | │ │   kwargs = {'workers': None}                     │                         │
hyperglass-1  | │ │      run = <function run at 0x7f75196f9b20>      │                         │
hyperglass-1  | │ │  workers = None                                  │                         │
hyperglass-1  | │ ╰──────────────────────────────────────────────────╯                         │
hyperglass-1  | │                                                                              │
hyperglass-1  | │ /opt/hyperglass/hyperglass/main.py:180 in run                                │
hyperglass-1  | │                                                                              │
................
╰──────────────────────────────────────────────────────────────────────────────╯
hyperglass-1  | FileExistsError: [Errno 17] File exists: '/etc/hyperglass/static/ui'
hyperglass-1 exited with code 1
maluueu commented 1 month ago

Can be fixed by deleting the build dir before copying to it. I will open a PR @thatmattlove

diff --git a/hyperglass/frontend/__init__.py b/hyperglass/frontend/__init__.py
index 2fe338e..cd0ce5b 100644
--- a/hyperglass/frontend/__init__.py
+++ b/hyperglass/frontend/__init__.py
@@ -131,6 +131,7 @@ async def build_ui(app_path: Path):
         log.error(err)
         raise RuntimeError(str(err)) from err

+    shutil.rmtree(build_dir)
     shutil.copytree(out_dir, build_dir)
     log.bind(src=out_dir, dst=build_dir).debug("Migrated Next.JS build output")
thatmattlove commented 1 month ago

Hey @maluueu - Apologies for not merging #246 directly; I was working on a number of other changes and forgot to merge your change beforehand. I did modify your change slightly by using the dirs_exist_ok=True argument to shutil.copytree, but the result is the same. This should be fixed now.

maluueu commented 1 month ago

Hey @maluueu - Apologies for not merging #246 directly; I was working on a number of other changes and forgot to merge your change beforehand. I did modify your change slightly by using the dirs_exist_ok=True argument to shutil.copytree, but the result is the same. This should be fixed now.

Hey @thatmattlove, no worries. Regarding the issue, are you sure that dirs_exist_ok=True fixes it completely? Consider the following scenario:

Wouldn't this cause File A to still exist in the output dir, rather than being removed fully?

thatmattlove commented 1 month ago

Ya know, you're right. If you don't mind, open another PR against the current commit and I'll merge it. Thank you!

maluueu commented 1 month ago

Ya know, you're right. If you don't mind, open another PR against the current commit and I'll merge it. Thank you!

sure, will do!

maluueu commented 1 month ago

@thatmattlove done (#247), also set exist_dir to False as that should never happen