zeratax / matrix-registration

a token based matrix registration api

Home Page:https://zeratax.github.io/matrix-registration/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running alembic via the container image is problematic

spantaleev opened this issue · comments

Because nix is used to build the container image, it's not easy to run alembic.

For 0.9.1, the alembic binary happens to be at /nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/bin/alembic. Seems like we need to set this as an --entrypoint to invoke it.

It appears that we also need to pass a config to it, which happens to live at /nix/store/5q2rmk3i4cvjzb5x6s19s5gmv34gjpf6-python3.8-matrix-registration/alembic.ini.

Looks like we also need to run the alembic command with a working directory like /nix/store/5q2rmk3i4cvjzb5x6s19s5gmv34gjpf6-python3.8-matrix-registration (passed to docker run via -w).


In the end, I've gotten to a command like this:

docker run \
-it \
--rm \
--name matrix-registration-db \
--log-driver=none \
--user=991:991 \
--cap-drop=ALL \
--network=matrix \
--mount type=bind,src=/matrix/matrix-registration/config,dst=/config,ro \
--mount type=bind,src=/matrix/matrix-registration/data,dst=/data \
-w /nix/store/5q2rmk3i4cvjzb5x6s19s5gmv34gjpf6-python3.8-matrix-registration \
--entrypoint=/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/bin/alembic \
docker.io/zeratax/matrix-registration:v0.9.1 \
-c /nix/store/5q2rmk3i4cvjzb5x6s19s5gmv34gjpf6-python3.8-matrix-registration/alembic.ini upgrade head

Yet I still get some error like this:

Traceback (most recent call last):
  File "/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/bin/.alembic-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/lib/python3.8/site-packages/alembic/config.py", line 577, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/lib/python3.8/site-packages/alembic/config.py", line 571, in main
    self.run_cmd(cfg, options)
  File "/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/lib/python3.8/site-packages/alembic/config.py", line 548, in run_cmd
    fn(
  File "/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/lib/python3.8/site-packages/alembic/command.py", line 298, in upgrade
    script.run_env()
  File "/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/lib/python3.8/site-packages/alembic/script/base.py", line 489, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
    module = load_module_py(module_id, path)
  File "/nix/store/lcbqvdllxb7lnrk85zq4pdl63yxdbb4z-python3.8-alembic-1.4.2/lib/python3.8/site-packages/alembic/util/compat.py", line 184, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "alembic/env.py", line 14, in <module>
    from matrix_registration import config as mr_config
ModuleNotFoundError: No module named 'matrix_registration

So I'm guessing the command above needs even more work.


Is it possible to adjust the container-building script, so that it puts binaries (or symlinks to them) at a predictable path?

What would be the proper way to invoke alembic from a container image?


Related to spantaleev/matrix-docker-ansible-deploy#1208

https://github.com/ZerataX/matrix-registration/blob/2a36ebb4fa660bbd75600946b592119c497f1fba/docker.nix#L13-L26

I could easily add something to this like

Env = [ "PATH=${pkgs.matrix-registration.alembic}/bin/" ];

and maybe also add a symlink for the ini to /data?
kinda wish i could just set two entrypoints for both alembic and mreg.

Hmm the other nix approach might be to make a wrapper, e.g. I use this:

{
matrix-registration-cli-wrapper = pkgs.stdenv.mkDerivation {
    name = "matrix-registration-cli-wrapper";
    buildInputs = [ pkgs.makeWrapper ];
    buildCommand = ''
      mkdir -p $out/bin
      makeWrapper ${pkgs.matrix-registration}/bin/matrix-registration "$out/bin/matrix-registration" \
        --add-flags "--config-path='${matrix-registration-config}'"
    '';
  };
}

if I put both configured like that on the PATH I could just use a default entrypoint.

then I guess you would have to write out the entire command. as in matrix-registration serve or alembic upgrade head instead of just serve, but overwriting the entrypoint for alembic seems kinda bad?

I'm not sure I understand what the above nix configuration does, but anyway.. writing out the entire command sounds (matrix-registration serve, instead of just serve) sounds good.