-
Notifications
You must be signed in to change notification settings - Fork 224
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
Using multi line environment variable in stack.yml results in an error #857
Comments
It looks like you may benefit from using a pipe here with Have you tried a simple multi-line variable without the interpolation? For example, how we do it here? https://github.com/openfaas/templates/blob/master/template/go/template.yml#L19 |
@alexellis Hey, thanks for the tip. I remember trying that, just tried that now. it still gives me the error # stack.yml
version: 1.0
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
myfn:
lang: dockerfile
handler: .
image: localhost:5000/myfn:latest
build_args:
RSA: |
${RSA} My guess would be that only the first line of the multiline env var is being indented, but the other lines wont. I tried also using but still got the same error |
I don't think you are quoting the string correctly. Try adding the literal value and tabbing correctly, then see if it works as expected. |
OK, it works when I put the literal value and tabbing correctly, how can i make it work as an environment variable? tried: build_args:
RSA: |
"
-----BEGIN RSA PRIVATE KEY-----
rsa_key
-----END RSA PRIVATE KEY-----
" it doesn't work if I have the quotes in the same line of ---BEGIN and ---END, but thats another error relating to ssh value. build_args:
RSA: |
"
${RSA}
" but got the original error again |
Perhaps you can save your file with the indentation in place?
|
I don't get the YAML parsing error, but when building the container, ssh connections fail since the RSA value is now indented and has quotes. root@1a2a03d37fef:/# cat ~/.ssh/id_rsa
"
-----BEGIN RSA PRIVATE KEY-----
rsa_key is not indented here
-----END RSA PRIVATE KEY-----
" It only indents the first line, and keeps the quotes. gives back the YAML parsing error if I removed the quotes from Thanks for your fast responses, really appreciate the help |
My suggestion would be for you to base64 encode the string, and then run base64 --decode within the container. A base64 string can be represented on a single line preserving any whitespace and newlines required. In stack.yml:
At build time:
Within your Dockerfile:
I'm going to close out the issue now as we've given a working solution. If you have issues with getting the solution to work, create a quick repo with everything and I'll give it a shot myself. |
/msg: enduser |
Thank you for your interest in OpenFaaS. This project is maintained and made available for hobbyists and commercial users alike, so we need to balance our time across everyone's needs. Whilst we are excited in your interest in using OpenFaaS, we would also ask you to take a look at our contribution guide on Setting expectations, support and SLAs. Commercial users can purchase support in order to get dedicated help from OpenFaaS Ltd, or they can book ad-hoc consulting hours to get an engineer to dedicate time to helping them. If that is not a good fit for you at this time, please check out the OpenFaaS GitHub Sponsors options which are priced for practitioners like yourself. Organisations can also sponsor through their GitHub billing relationship. When you become a sponsor as an indvidual, it will show this on your issues and PRs, so that the community can see that you are supporting our work, and can prioritise your needs. If you are receiving this message after having received hands-on support from the OpenFaaS community, please join GitHub Sponsors to say thank you for our time. Thank you for supporting OpenFaaS. |
Encoding in base64 solves my issue, thanks! |
You're welcome. Please consider the message Derek sent over. |
My actions before raising this issue
I want to stress out that I cannot use k8s secrets as this is a build argument required for the container build.
I have a multi line environment variable
$RSA
containing RSA key that I need to pass as a build argument to Docker.The command
faas-cli build / up --build-arg RSA=${RSA}
works. However if I tried to the following it doesn't:Expected Behaviour
RSA
build argument should contain the environment variable value from my shell.Current Behaviour
The following error occurs:
❯ faas-cli up Error with YAML file Yaml: line 15: could not find expected ':'
Possible Solution
I can use the same environment variable without issues in
docker-compose.yml
:Steps to Reproduce (for bugs)
faas-cli new --lang python3 myfn
myfn.yml
tostack.yml
stack.yml
and replace with the given configuration above.export RSA=$(cat $HOME/.ssh/my_rsa)
faas-cli up
Context
Your Environment
faas-cli version
):docker version
(e.g. Docker 17.0.05 ):Are you using Kubernetes or faasd? K8s
Operating System and version (e.g. Linux, Windows, MacOS): Linux (Fedora 32)
Code example or link to GitHub repo or gist to reproduce problem: Everything provide in the issue
Other diagnostic information / logs from troubleshooting guide: The logs are from the cli so not providing for now unless request.
The text was updated successfully, but these errors were encountered: