pgtemp icon indicating copy to clipboard operation
pgtemp copied to clipboard

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

Open nihohit opened this issue 1 year ago • 4 comments

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.

nihohit avatar Jul 09 '24 09:07 nihohit

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.

boustrophedon avatar Jul 09 '24 18:07 boustrophedon

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 🤷

nihohit avatar Jul 09 '24 19:07 nihohit

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?

boustrophedon avatar Jul 09 '24 20:07 boustrophedon

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: @.***>

nihohit avatar Jul 09 '24 20:07 nihohit

0.6.0 is out with bin_path https://docs.rs/pgtemp/0.6.0/pgtemp/struct.PgTempDBBuilder.html#method.with_bin_path

boustrophedon avatar Feb 27 '25 00:02 boustrophedon