boustrophedon / pgtemp

Rust library and daemon for easily starting postgres databases per-test without Docker
MIT License
219 stars 5 forks source link

Can't run in Github Actions due to `sudo` use #8

Open nihohit opened 2 months ago

nihohit commented 2 months ago

When I try to use this in Github Actions I get these errors:

initdb failed! stdout: 

stderr: sudo: initdb: command not found
), location: Location { file: "/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgtemp-0.3.0/src/run_db.rs", line: 72, col: 9 }

from what I see, this happens because sudo can't find initdb in its secure path - adding the path to postgres to $PATH doesn't solve the issue. I mitigated the issue by copying the whole postgresql bin &lib folders into /usr/bin & /usr/lib respectively, but it would be nice if the library could handle this.

boustrophedon commented 1 month ago

If you have the $GITHUB_PATH step in your github action, you probably need to do something like sudo -E so that the updated $PATH environment variable is carried over.

However, postgres itself refuses to run as root so I'm not sure what you're doing will work at all.

nihohit commented 1 month ago

However, postgres itself refuses to run as root so I'm not sure what you're doing will work at all.

It works, I assume thanks to the sudo call in pgtemp.

As for using sudo -E - it seems like it isn't supported by the sudo in the runner:

Run sudo -E
usage: sudo -h | -K | -k | -V
usage: sudo -v [-ABkNnS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-ABkNnS] [-g group] [-h host] [-p prompt] [-U user]
            [-u user] [command [arg ...]]
usage: sudo [-ABbEHkNnPS] [-r role] [-t type] [-C num] [-D directory]
            [-g group] [-h host] [-p prompt] [-R directory] [-T timeout]
            [-u user] [VAR=value] [-i | -s] [command [arg ...]]
usage: sudo -e [-ABkNnS] [-r role] [-t type] [-C num] [-D directory]
            [-g group] [-h host] [-p prompt] [-R directory] [-T timeout]
            [-u user] file ...

I'm not sure that there is a solution to this issue 🤷

boustrophedon commented 1 month ago

It works, I assume thanks to the sudo call in pgtemp.

Ah, I had gone back and forth on whether to include that feature and forgot that I actually ended up keeping it.

I'm not sure why it isn't working for you in github actions then. You definitely have the $GITHUB_PATH step included in your action prior to starting pgtemp?

nihohit commented 1 month ago

Yup, github path is set in an earlier step and PATH is echoed in the test step to verify that it includes the postgresql dir, but 'sudo' doesn't use the updated path.

On Tue, 9 Jul 2024, 23:36 Harry Stern, @.***> wrote:

It works, I assume thanks to the sudo call in pgtemp.

Ah, I had gone back and forth on whether to include that feature and forgot that I actually ended up keeping it.

I'm not sure why it isn't working for you in github actions then. You definitely have the $GITHUB_PATH step included in your action prior to starting pgtemp?

— Reply to this email directly, view it on GitHub https://github.com/boustrophedon/pgtemp/issues/8#issuecomment-2218686203, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDEBBULSFO7BX4TD7BH7H3ZLRCWXAVCNFSM6AAAAABKSP4IOKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJYGY4DMMRQGM . You are receiving this because you authored the thread.Message ID: @.***>