fzngagan
(Faizaan Gagan)
September 2, 2020, 12:20pm
1
Some client libraries like GitHub - googleapis/google-auth-library-ruby: Google Auth Library for Ruby require the authentication credentials to be set as environment variables
. Is it possible to pass them via the yml
file.
I tried
Adding export VAR=VALUE
to the custom commands section of the yml file.
Adding VARIABLE: VALUE
to the env
section of the yml.
fzngagan
(Faizaan Gagan)
September 2, 2020, 1:32pm
2
@merefield pointed out to me that its indeed possible.
in the custom commands section do
# adds the variable to .bashrc file
exec: echo 'export VAR=value' >> ~/.bashrc
...
# reloads the file
exec: source ~/.bashrc
I can confirm that this approach indeed works.
p.s.
Somehow the source ~/.bashrc
doesn’t update the environment. Maybe its being called too early.
Also tried,
- exec: /bin/bash -c "source ~/.bashrc"
6 Likes
justin
(Justin DiRose)
September 2, 2020, 4:28pm
3
Can’t you use the env:
section of the container definition for this? That should create an environment variable the Rails app can access.
So like
env:
CUSTOM_ENV: "value"
Otherwise it looks like pups already pipes in env variables on the host , too.
5 Likes
fzngagan
(Faizaan Gagan)
September 2, 2020, 4:41pm
4
That gives me an error related to docker. That would be very intuitive if it worked like that. Or I’m crazy. I think there’s a rule to accept custom vars starting with DISCOURSE_
.
2 Likes
fzngagan
(Faizaan Gagan)
September 2, 2020, 5:00pm
5
I’ll try the env thing once again when I get at my desk tomorrow.
3 Likes
fzngagan
(Faizaan Gagan)
September 2, 2020, 6:02pm
6
So, I was crazy. This works fine. The issue was due to a multiline value. I removed it and the build suceeded. But the question is, how to use multiline values?
3 Likes
fzngagan
(Faizaan Gagan)
September 3, 2020, 9:24pm
7
Yuhoo, I was able to make it work. The issue was that I was using a RSA Private key as an environment variable. This is what needs to be done to make that work.
wrap your key in single quotes ''
and add an extra \
with all the \n
appearing in the key. i.e. \n
would be come \\n
.
1 Like
just FYI, there are easier ways of doing that then updating all of the \n directly.
Something like this:
key: |
---BEGIN SECRET KEY---
SHH do not read this is secret
---END SECRET KEY---
2 Likes
fzngagan
(Faizaan Gagan)
September 3, 2020, 10:49pm
9
featheredtoast:
Something like this:
Do you mean pasting the middle part of the key as it is? That would be somewhat more cleaner.
I mean that yml has multiline support starting with the |
character (and optional variations)
You can then paste the key as-is with no edits (aside from prefixed spaces).
1 Like
fzngagan
(Faizaan Gagan)
September 3, 2020, 10:53pm
11
I tried a silly thing I added |
and an actual new line instead of each \n
which didn’t work.