-
Notifications
You must be signed in to change notification settings - Fork 621
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
feat: add ability to load env vars via profile #207
Conversation
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.
LGTM. I've verified that the variables are available both in the boot scripts and in user sessions.
I wish lima.env
and lima.profile
had newlines at the end, but that is maybe just personal preference. Same way I would have called the lima.profile
file lima.sh
, just to match the name it gets under /etc/profile.d
.
But I'm fine with merging as-is once it passes CI.
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.
I have to revoke my approval; the missing newline on lima.env
is causing a failure:
/mnt/lima-cidata/boot/03-etc-hosts.sh: line 5: LIMA_CIDATA_SLIRP_GATEWAY: unbound variable
Please add a trailing newline to lima.profile
as well!
@AkihiroSuda What is the reason lima.env
does not include the export
keyword, so it could be sourced directly from the shell instead of being read like this:
while read -r line; do export "$line"; done <"${LIMA_CIDATA_MNT}"/lima.env
The problem is Adding the newline back is the quick fix to make it work again. Changing the format of |
Just because other env files such as /etc/environment and .env file (of docker compose) do not include |
BTW, I noticed that Tempted to say we switch to |
While testing this with the I now wonder if we should install the variables twice, under Please tell me I'm confused, and that there is a simple solution to this! |
This seems to be due to session persistence. When I run So right now I feel that using just Sorry for all the flip-flopping! @AkihiroSuda could you chime in with your opinion? |
Yes, /etc/environment SGTM. |
We would write it in Since |
Please also rebase your PR on the latest master to resolve a problem with Github Actions and our test workflow! |
aebe6ca
to
19addae
Compare
@loganprice Thanks for rebasing the branch; it is now passing all CI tests. I'm going to wait until you rewrite the implementation to generate Let me know if you need any further clarification; I know I have confused everyone (including myself) by going back and forth between the different options. |
|
I'll have a look; I already have some other feedback... |
I think this is an argument in favour of creating a
We can then update
The first line removes an existing block of our variables during a reboot and the second one appends it again. This way we maintain any other changes the user might have made to the file (as long as they don't insert them between our marker lines). I would prefer to remove the
I know it will be functionally identical, but having the same variables/values defined in multiple places always makes me nervous. Use a single source of truth. 😄 Keeping the values in a data file also solves the shellcheck issue. @AkihiroSuda I just learned that it is impossible to define an environment variable whose value includes the |
SGTM |
f561e99
to
abcbc41
Compare
pkg/cidata/cidata.TEMPLATE.d/boot.sh
Outdated
|
||
# shellcheck disable=SC2163 | ||
while read -r line; do | ||
[ "$(expr "$line" : '^#.*')" -eq 0 ] && export "$line" |
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.
The ^
at the beginning of the regular expression is implied:
$ expr " #FOO" : "#"
0
$ expr "#FOO" : "#"
1
On some expr
versions (e.g. busybox
as used by Alpine) it generates some noise on stderr:
$ expr "#FOO" : "^#"
expr: warning: '^#': using '^' as the first character
of a basic regular expression is not portable; it is ignored
1
So the current version works, but I would prefer to avoid the warning and simplify as:
[ "$(expr "$line" : '^#.*')" -eq 0 ] && export "$line" | |
[ "$(expr "$line" : '#')" -eq 0 ] && export "$line" |
Otherwise, it works exactly as I would have hoped, and I would have approved, except for this little nit.
Thank you for staying with my changing opinions on how this should be implemented!
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.
Oh, almost forgot: could you please squash the previous commits that have effectively been reverted? And also clean up the resulting commit message. Thank you!
Signed-off-by: loganprice <Logan.B.Price@gmail.com>
6b4098a
to
81d4831
Compare
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.
Thank you very much; it is all good now.
Curiously, when I test again now with Alpine, the /etc/environment
changes are not visible in the user environment (but are visible after sudo sh
). I thought they were visible in the user environment when I tested the previous version. Anyways, I don't see how this can be related to the latest change, so I think this will have to be addressed in the Alpine configuration.
Late to the party, but lima.env vs lima.environment is really confusing 😓 |
Sorry, that was my fault. Please suggest better names, and we can rename (in addition to documentation). |
I’d just name it “etc_environment” |
No description provided.