Skip to content

Commit dc0a594

Browse files
committed
updated Dockerfile and ExApp's main.py to set those env variables
Signed-off-by: bigcat88 <[email protected]>
1 parent f6e4308 commit dc0a594

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@ RUN --mount=type=cache,target=/root/.cache/pip \
6262
venv/bin/python -m pip install torch==2.7.0 torchvision torchaudio; \
6363
fi
6464

65+
COPY ex_app/lib/exclude_nodes.py ex_app/lib/exclude_flows.py /ex_app/lib/
66+
COPY scripts/ci/get_excludes.py /get_excludes.py
6567
RUN --mount=type=cache,target=/root/.cache/pip \
6668
cd /Visionatrix && \
6769
venv/bin/python -m pip install "psycopg[binary]" greenlet && \
6870
venv/bin/python -m pip install . && \
69-
venv/bin/python -m visionatrix install && \
70-
rm visionatrix.db
71+
VISIONATRIX_INSTALL_EXCLUDE_NODES="$(python /get_excludes.py nodes)" \
72+
venv/bin/python -m visionatrix install && \
73+
rm visionatrix.db && \
74+
rm /get_excludes.py && \
75+
rm -rf /ex_app
7176

7277
# Setup nodejs and npm for building the front-end client
7378
RUN apt-get update && \

ex_app/lib/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from time import sleep
1818

1919
import httpx
20+
from exclude_flows import EXCLUDE_FLOWS_IDS
21+
from exclude_nodes import EXCLUDE_NODES_IDS
2022
from fastapi import BackgroundTasks, Body, Depends, FastAPI, Request, responses
2123
from nc_py_api import NextcloudApp
2224
from nc_py_api.ex_app import (
@@ -74,6 +76,9 @@
7476
print("[DEBUG]: PROJECT_ROOT_FOLDER=", PROJECT_ROOT_FOLDER, flush=True)
7577
print("[DEBUG]: STATIC_FRONTEND_PRESENT=", STATIC_FRONTEND_PRESENT, flush=True)
7678

79+
os.environ["VISIONATRIX_INSTALL_EXCLUDE_NODES"] = EXCLUDE_NODES_IDS
80+
os.environ["VISIONATRIX_EXCLUDE_FLOWS"] = EXCLUDE_FLOWS_IDS
81+
7782

7883
def _(text):
7984
return current_translator.get().gettext(text)

scripts/ci/get_excludes.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env python3
22
"""
3-
Tiny helper for GitHub Actions.
3+
Tiny helper for GitHub Actions *and* Docker builds.
44
55
Usage:
6-
python3 scripts/ci/get_excludes.py flows # → prints "id1;id2;…"
7-
python3 scripts/ci/get_excludes.py nodes # → prints "url1;url2;…"
6+
python3 get_excludes.py flows # → prints "id1;id2;…"
7+
python3 get_excludes.py nodes # → prints "url1;url2;…"
88
9-
It simply echoes the semicolon-joined list so the caller can redirect it
10-
into the desired environment variable.
9+
It echoes a semicolon-joined list so callers can assign it to an environment variable, e.g.:
10+
11+
VISIONATRIX_INSTALL_EXCLUDE_NODES="$(python /get_excludes.py nodes)"
1112
"""
1213

1314
from __future__ import annotations
@@ -28,21 +29,43 @@ def _import_list(file: Path, var: str) -> Sequence[str]:
2829
return value
2930

3031

32+
def find_repo_root() -> Path:
33+
"""
34+
Locate directory that contains ex_app/lib/ .
35+
Strategy (first match wins):
36+
1. Walk up from this script's directory.
37+
2. Walk up from CWD (useful if script is executed via absolute path).
38+
3. Fallback to filesystem root (where Dockerfile copies it as /ex_app/lib).
39+
"""
40+
def search_up(start: Path) -> Path | None:
41+
for p in [start, *list(start.parents)]:
42+
if (p / "ex_app" / "lib").is_dir():
43+
return p
44+
return None
45+
46+
here = Path(__file__).resolve().parent
47+
return search_up(here) or search_up(Path.cwd()) or Path("/")
48+
49+
3150
def main() -> None:
3251
if len(sys.argv) != 2 or sys.argv[1] not in {"flows", "nodes"}:
3352
print("Usage: get_excludes.py [flows|nodes]", file=sys.stderr)
3453
sys.exit(1)
3554

3655
mode = sys.argv[1]
37-
repo_root = Path(__file__).resolve().parents[2] # <repo>/scripts/ci/…
56+
repo_root = find_repo_root() # <repo root> or "/" inside container
3857

3958
if mode == "flows":
4059
py_file = repo_root / "ex_app" / "lib" / "exclude_flows.py"
4160
var_name = "EXCLUDE_FLOWS_IDS"
42-
else: # nodes
61+
else:
4362
py_file = repo_root / "ex_app" / "lib" / "exclude_nodes.py"
4463
var_name = "EXCLUDE_NODES_IDS"
4564

65+
if not py_file.is_file():
66+
print(f"Error: cannot locate {py_file}", file=sys.stderr)
67+
sys.exit(2)
68+
4669
items = _import_list(py_file, var_name)
4770
print(";".join(items))
4871

0 commit comments

Comments
 (0)