-
Notifications
You must be signed in to change notification settings - Fork 27
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
Enrivonment variable to force the configuration file. #61
Enrivonment variable to force the configuration file. #61
Conversation
The command now will honor the environment variable `PGENV_CONFIGURATION_FILE` so that, if set, will determine the path to the configuration file to be used during all the operations. This allows to decied which configuration file to use before the `pgenv` starts working, so for example: % export PGENV_CONFIGURATION_FILE=~/git/pgenv/config/default.conf % pgenv build 16beta2 will use the default configuration file instead of a version specific one. Added also a `pgenv config use <version>` command that prints the environment variable to export or set in the shell session (but does not set itself), so that it is possible to do % export $( pgenv config use default ) to obtain the environment changed, and hence ease the "computation" of which file name to use for a specific version. Close theory#60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works once, but then it overwrites the file, which isn't great. If the user specifies a file to use with PGENV_CONFIGURATION_FILE
, pgenv should not overwrite it.
The subcommand `config path` prints out the configuration file path for the specified version, or the default one if no version is specified. In this way, it is possible to export the environment variable like in the following: $ export PGENV_CONFIGURATION_FILE=$( pgenv config path default ) See theory#61
If the user has defined the PGENV_CONFIGURATION_FILE variable he probably does not want to overwrite a per-PostgreSQL specific configuration file. See <theory#61 (review)>
I've modified the code:
I'm not sure if not overwriting the configuration file is the right behavior, and I suspect it can confuse the users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few suggested tweaks and a question, and can confirm that it no longer deletes the file. Yay!
@@ -635,6 +635,8 @@ The `config` command accepts the following subcommands: | |||
(Using `$EDITOR`, e.g: `export EDITOR=/usr/bin/emacs`) | |||
- `delete` removes the specified configuration | |||
- `migrate` is a command used to change the configuration format between versions of `pgenv` | |||
- `path` accepts a version number and prints on standard output the path to such version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `path` accepts a version number and prints on standard output the path to such version | |
- `path` accepts a version number (or "default") and prints on standard output the path to such version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, every config
command accepts default
, I think it is already clear, but I added as you suggest.
# if the user has defined an environment variable PGENV_CONFIGURATION_FILE | ||
# I need to use that instead of trying to understand which file to use | ||
if [ ! -z "$PGENV_CONFIGURATION_FILE" -a -z "$skip_env" ]; then | ||
pgenv_debug "Configuration file overwritten by environment variable PGENV_CONFIGURATION_FILE = $PGENV_CONFIGURATION_FILE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually overwrite the file, or do you mean to say here that the setting of PGENV_CONFIGURATION_FILE
overrides the calculated configuration file?
# This can be useful to exdport the environment variable | ||
# to point to a custom path, like this: | ||
# | ||
# % export PGENV_CONFIGURATION_FILE=$( pgenv config path 16neta2 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# % export PGENV_CONFIGURATION_FILE=$( pgenv config path 16neta2 ) | |
# % export PGENV_CONFIGURATION_FILE="$( pgenv config path 16neta2 )" |
The one thing I'm wondering if there is some way to set a variable that means "don't write out a new file". It's implied by setting What do you think, @fluca1978? |
Actually I kinda thing it ought not to write a new file by default, but it's probably too late to reverse that pattern now. |
See <theory#61>
Well, implementing this is quite easy, but I ask myself if we need another environment variable. |
The reason I suggest this is that for those of us who don't want to create a file every time, there is no way to prevent it without always setting an environment variable — because if you put it in the config file, it's too late. Am I right? I'm fine to look at doing it in a separate PR, totally, and agree about not changing the default now. |
Sorry, it is not clear to me how to proceed. The other thing you are asking for is a way to avoid creation of a configuration file at build/rebuild time. |
I think so, yes.
Yes, I think this is worth discussing in a new issue/PR. |
Exploit getopt(1) to get command line options availability. The idea is to do a first parse at the very beginning of the script, so that options can be detected and internal and environmental variables can be set accordingly. Then the command line parsing continues as before. Added a new section to the documentation about variables and command line flags to illustrate how both can be combined and used. Close theory#61
pgenv_debug "Cannot write configuration file while PGENV-CONFIGURATION_FILE set!" | ||
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addition is causing the build script to error, signalling a failed build, when building by a default.conf
present in the default config
directory.
Debug output (removed the build output, but build succeeded)
citus@6c4d7721b906:~$ echo $PGENV_CONFIGURATION_FILE
citus@6c4d7721b906:~$ PGENV_DEBUG=1 pgenv build 14.9
[DEBUG] Looking for configuration in /home/citus/.pgenv/config/14.9.conf
[DEBUG] Looking for configuration in /home/citus/.pgenv/config/default.conf
[DEBUG] Load configuration from [/home/citus/.pgenv/config/default.conf]
[DEBUG] Downloading tarball
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 21.1M 100 21.1M 0 0 3751k 0 0:00:05 0:00:05 --:--:-- 3803k
[DEBUG] Patching version 14.9
[DEBUG] Patch index file []
[DEBUG] Skipping patch: no index file found!
[DEBUG] configure command line [--prefix=/home/citus/.pgenv/pgsql-14.9] + [--enable-debug --enable-depend --enable-cassert --enable-tap-tests CFLAGS=-ggdb -Og -g3 -fno-omit-frame-pointer -DUSE_VALGRIND --with-openssl --with-libxml --with-libxslt --with-uuid=e2fs --with-icu --with-lz4]
...
[DEBUG] Configuration file overwritten by environment variable PGENV_CONFIGURATION_FILE = /home/citus/.pgenv/config/default.conf
[DEBUG] Cannot write configuration file while PGENV-CONFIGURATION_FILE set!
citus@6c4d7721b906:~$ echo $?
1
citus@6c4d7721b906:~$ echo $PGENV_CONFIGURATION_FILE
citus@6c4d7721b906:~$
exit with a non-zero exit here is probably not desirable.
Example how this breaks automated workflows: https://github.com/citusdata/citus/actions/runs/6082295223/job/16499766357
It took me a while to understand this was caused by a change in pgenv instead of actual build failures, but running the steps of the build manually pointed me to this change.
Any idea how this should be solved? As you can see from the debug output pgenv
assumes the PGENV_CONFIGURATION_FILE
is set, although it is not, probably due to the config being resolved.
I believe the previous behaviour was to write the applied config of the build to a version specific file when seeded from a default config file. This is sane, as it makes rebuilds more deterministic.
minor nit; the log line has a small typo in there
pgenv_debug "Cannot write configuration file while PGENV-CONFIGURATION_FILE set!" | |
exit 1 | |
pgenv_debug "Cannot write configuration file while PGENV_CONFIGURATION_FILE set!" | |
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the github actions link in an incognito window seems to indicate that non-contributors can't see the output of the Build and push
step, but it fails on exit 1
on pgenv build <version>
.
The output pasted above is easier to digest as it has the big wall of text removed and actually contains the debug lines, cause is the same.
There are different problems here:
@thanodnl could you please test the new version and report in a separate issue any thing that I could have missed? |
@fluca1978 Thanks for the quick turnaround (!), the new commit on the mainline works again for automation use-cases. Nevertheless, I have pinned the version to the latest working tag in our environment to prevent future changes to break our workflow :D. Once a new tag is stamped I will update there, but this makes our dev environment builds more consistent. With regards to the other points
I think if it fails to write a file due to an error it would be acceptable to exit with an error code, however, if it doesn't write a file due to a logical decision I think it would be undesirable to
I take no stance on this. I was under the impression that it deliberately created an extra artefact, next to the postgres build, to capture the exact conditions it was built with. If the new desired behaviour is to not do so that is fine with me. It was mostly an observation that a PR that seemingly only added an environment variable to pass in a config file, had the side effect of not writing the version specific file if it was deduced from I haven't tested other scenario's as we (my team and me) have a shared |
The change did not gain a release (tag) because there is also #60 under discussion and development, and to some extent these changes are related.
There is room for improvement here for sure! |
7214768 seems like the right change to me. |
The command now will honor the environment variable
PGENV_CONFIGURATION_FILE
so that, if set, will determine the path to the configuration file to be used during all the operations. This allows to decied which configuration file to use before thepgenv
starts working, so for example:will use the default configuration file instead of a version specific one.
Added also a
pgenv config use <version>
command that prints the environment variable to export or set in the shell session (but does not set itself), so that it is possible to do% export $( pgenv config use default )
to obtain the environment changed, and hence ease the "computation" of which file name to use for a specific version.
Close #60