fergusstrange / embedded-postgres

Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test
MIT License
817 stars 84 forks source link

Support running binaries on non-standard systems #109

Closed jordanisaacs closed 1 year ago

jordanisaacs commented 1 year ago

On some systems (eg NixOS), libraries and the interpreter path need to be patched. Thus, add two config options to support this.

  1. Config option for setting the binary interpreter using patchelf. Occurs on first download
  2. Config option for adding/overriding the binaries exec environment variables. Eg. for LD_LIBRARY_PATH. The initDatabase type now takes an extra parameter env.

These by default are unset and do not change existing behavior. The tests have been updated to take in POSTGRES_INTERPRETER for setting the interpreter.

I was able to successfully run the test suite on NixOS with these changes. To avoid changing the test suite further, I just used LD_LIBRARY_PATH as a global env variable. I am not sure the best way to test this otherwise as I cannot commit to keeping a Nix CI up to date.

fergusstrange commented 1 year ago

Hey @jordanisaacs. This is pretty neat and it's cool to see you've worked around the problem effectively.

As far as I'm aware there isn't huge demand from the community for this, so for now I'll close this unless a significant number of others ask for it. The amount of overhead this adds is fairly hefty, as shown from the significant coverage drop, which would likely impact our ability to effectively maintain updates and versions releases confidently.

Thanks for the contribution and I'll be sure to point anyone asking at your fork to drive interest.

lennyterra commented 1 year ago

Would love to see this implemented!

lennyterra commented 1 year ago

hey, @jordanisaacs how can I use this fork in the meantime? I tried cloning your branch and setting up replace github.com/fergusstrange/embedded-postgres => ../embedded-postgres

in my go.mod, but I'm getting the same errors as before:

Received unexpected error:
                            unable to init database using '/home/x/.embedded-postgres-go/extracted/bin/initdb -A password -U root -D /home/x/.embedded-postgres-go/extracted/data --pwfile=/home/x/.embedded-postgres-go/extracted/pwfile': fork/exec /home/x/.embedded-postgres-go/extracted/bin/initdb: no such file or directory