Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running alembic via the container image is problematic #72

Open
spantaleev opened this issue Jul 30, 2021 · 2 comments
Open

Running alembic via the container image is problematic #72

spantaleev opened this issue Jul 30, 2021 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@spantaleev
Copy link

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

@spantaleev spantaleev added the bug Something isn't working label Jul 30, 2021
@zeratax
Copy link
Owner

zeratax commented Jul 30, 2021

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?

@spantaleev
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants