refactor(gateway): replace flat-file import shims with installed package #410
Reference in New Issue
Block a user
Delete Branch "fix/gateway-bundle-packaging"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #400 (item 4).
Summary
pyproject.tomlsopip install .works, and replaces 14 flatCOPYstatements inDockerfile.gatewaywithCOPY bot_bottle/ /src/bot_bottle/ && pip install /src/plus 4 entry-point copies — missing or renamed modules now fail at image build time rather than container runtime.bot_bottle/constants.pyas a single source of truth forIDENTITY_HEADERandGIT_GATE_TIMEOUT_SECS, removing the duplicated literal definitions fromegress_addon.py,supervise_server.py,git_http_backend.py, andgit_gate_render.py.try/exceptimport shims fromegress_addon_core,dlp_detectors,egress_addon,supervise,supervise_server, andgit_http_backend— every import is now a plainfrom bot_bottle.X import Y.test_supervise_server.pydrops thesys.path.inserthack; bothtest_egress_addon_*shim files drop thesys.modules["egress_addon_core"]pre-population.bed648522cto5ad3449e3b@@ -107,4 +105,3 @@COPY bot_bottle/supervise.py /app/supervise.pyCOPY bot_bottle/supervise_server.py /app/supervise_server.pyCOPY bot_bottle/gateway_init.py /app/gateway_init.pyCOPY bot_bottle/git_http_backend.py /app/git_http_backend.pyWhy are these still included? Didn't we add them via the new copy line?
We should probably just turn those into command that we can invoke from the package, right? Copying those again when they're in the package seems non ideal. Push back and correct me if I'm wrong. Also if we need a light shim that just does
from bot_bottle import supervise_server; supervise_server()/something like that, that'd be fine.Why can't we add a shim for that fourth case too, though? EX:
mitmdump -s /app/egress_addon_shim.py, and then just have something like this inegress_addon_shim.py:Alternative would be to move
egress_addonout of the bot_bottle package: still think having the file copied in two places is bad.@@ -107,4 +105,3 @@COPY bot_bottle/supervise.py /app/supervise.pyCOPY bot_bottle/supervise_server.py /app/supervise_server.pyCOPY bot_bottle/gateway_init.py /app/gateway_init.pyCOPY bot_bottle/git_http_backend.py /app/git_http_backend.pyThe
COPY bot_bottle/ /src/bot_bottle/feedspip install /src/, which installs the package into site-packages asbot_bottle.*. The individualCOPYlines here put the same files at/app/— the fixed pathsgateway_init.pyuses when spawning the daemons as subprocesses (e.g.python3 /app/supervise_server.py) and that mitmdump uses for its-s /app/egress_addon.pyargument. The two destinations serve different roles: one is the importable package, the other is the executable entry points.@@ -107,4 +105,3 @@COPY bot_bottle/supervise.py /app/supervise.pyCOPY bot_bottle/supervise_server.py /app/supervise_server.pyCOPY bot_bottle/gateway_init.py /app/gateway_init.pyCOPY bot_bottle/git_http_backend.py /app/git_http_backend.pyGood call — three of the four can go.
supervise_server.py,git_http_backend.py, andgateway_init.pyall haveif __name__ == "__main__":guards, sopython3 -m bot_bottle.Xworks and we can drop those COPY lines. The one that has to stay isegress_addon.py:egress-entrypoint.shrunsmitmdump -s /app/egress_addon.py, and mitmdump's-sflag takes a file path — there's no module equivalent.egress-entrypoint.shitself also needs to stay for the same reason. Implementing the rest now.You're right, implemented. mitmdump finds
addonsin whatever module-spoints at, so a one-liner is enough:Generated inline with
RUN printf ... > /app/egress_addon.pyso no extra source file needed.egress-entrypoint.shstill points at/app/egress_addon.py, unchanged.