Skip to content
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

Injecting two params with ${env: xxx} breaks compose #144

Closed
3 tasks done
mdial89f opened this issue Jun 8, 2022 · 6 comments
Closed
3 tasks done

Injecting two params with ${env: xxx} breaks compose #144

mdial89f opened this issue Jun 8, 2022 · 6 comments

Comments

@mdial89f
Copy link

mdial89f commented Jun 8, 2022

Are you certain it's a bug?

  • Yes, it looks like a bug

Are you using the latest version?

  • Yes, I'm using the latest version

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Issue description

I have created a public repo to demonstrate the issue: https://github.com/mdial89f/env-issue

To summarize:
a compose file with the following contents will FAIL with "(node:69391) UnhandledPromiseRejectionWarning: ServerlessError: Unrecognized configuration variable sources: "env":

services:
  service-a:
    path: service-a
    params:
      one: ${env:USER}
      two: ${env:USER}

But if you comment out one of the params calling env, like the following contents, deployment succeeds:

services:
  service-a:
    path: service-a
    params:
      one: ${env:USER}
      # two: ${env:USER}

So, it seems you can only call env once in the compose file, for whatever reason.

To demonstrate the issue:

  • clone the repo git clone git@github.com:mdial89f/env-issue.git
  • have your aws creds exported or a profile active
  • npm run test This will fail, as the compose file in source has two parameters both defined with 'env:'
  • comment out serverless-compose.yml line 6, and run npm run test. This will succeed

Service configuration (serverless-compose.yml) content

services:
  service-a:
    path: service-a
    params:
      one: ${env:USER}
      two: ${env:USER}

See repo linked above for more info.



### Command name and used flags

sls deploy --stage test

### Command output

```shell
(node:69391) UnhandledPromiseRejectionWarning: ServerlessError: Unrecognized configuration variable sources: "env"
    at resolveConfigurationVariables (/Users/mike/Projects/github/acehole123/env-issue/node_modules/@serverless/compose/src/configuration/resolve-variables.js:79:11)
    at resolveConfigurationVariables (/Users/mike/Projects/github/acehole123/env-issue/node_modules/@serverless/compose/src/configuration/resolve-variables.js:51:12)
    at resolveConfigurationVariables (/Users/mike/Projects/github/acehole123/env-issue/node_modules/@serverless/compose/src/configuration/resolve-variables.js:51:12)
    at runComponents (/Users/mike/Projects/github/acehole123/env-issue/node_modules/@serverless/compose/src/index.js:109:9)```
See repo linked above for more info.
@pgrzesik
Copy link
Contributor

pgrzesik commented Jun 8, 2022

Hey @mdial89f - thanks a lot for reporting and sorry you've run into trouble. We've had a report of this issue already and it has been fixed today - I just published a new version that includes the fix - https://github.com/serverless/compose/releases/tag/v1.2.3

Let me know if that solves the problem for you.

@mdial89f
Copy link
Author

mdial89f commented Jun 8, 2022

Hey @mdial89f - thanks a lot for reporting and sorry you've run into trouble. We've had a report of this issue already and it has been fixed today - I just published a new version that includes the fix - https://github.com/serverless/compose/releases/tag/v1.2.3

Let me know if that solves the problem for you.

That fixed it!
Shame on me, it turns out I was NOT on the latest version. Closing. Thanks for all the work you put into this project.

@mdial89f mdial89f closed this as completed Jun 8, 2022
@pgrzesik
Copy link
Contributor

pgrzesik commented Jun 8, 2022

Ha, you actually were on the latest at the time, as I published the v1.2.3 release a few minutes after your ticket was created.

Thanks for the confirmation that everything now works as expected 🙇

@ada-cienciala
Copy link

@mdial89f @pgrzesik I'm tagging here because it seems envs worked for you.

I'm trying to use the env:XXX syntax. I know there's already an issue #185 asking about useDotenv support but here I see you did not use it (and compose will cry if you try to).

Did serverless compose stop supporting this syntax? The documentation says it still can use it but after creating .env file, it does not recognize defined values.

# .env 
AWS_REGION=us-west-2
# serverless-compose.yml
services:
  serviceA:
    path: ...
    region: ${env:AWS_REGION}

I'm only getting the The environment variable "AWS_REGION" is referenced but is not defined error. Can you share if you did anything else to get this working?

I'm on serverless 3.34.0 and serverless-compose 1.3.0

@mdial89f
Copy link
Author

mdial89f commented Dec 7, 2023

@ada-cienciala
What you have should work, provided that your .env file is being properly loaded. I'm not sure if serverless-compose has built in support for loading a .env file located in the current directory.
We use a tool called direnv to load our .env files.. can't recommend it enough! It hooks into your shell and keeps people correctly configured.

@ada-cienciala
Copy link

Oh, I assumed serverless loads the .env files because of the To automatically load environment variables from .env files (with the help of the dotenv package), set useDotenv: true in serverless.yml line in the documentation.

But it makes sense they would not load it if you cannot use the useDonenv in the compose file. So you just load it yourself. That's super useful info, I did not think of that, thank you so much! 🤍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants