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

1.2.0 breaks serverless interpolation #19

Closed
otbe opened this issue Aug 7, 2018 · 8 comments
Closed

1.2.0 breaks serverless interpolation #19

otbe opened this issue Aug 7, 2018 · 8 comments

Comments

@otbe
Copy link

otbe commented Aug 7, 2018

Hi there,

I love your plugin and I use it for my current pet project. I guess something has broken in the last version. This works in 1.1.5

custom:
  dotenv:
    path: .${self:provider.stage}.env

It will load stage specific files like .dev.env.
In 1.2.0 it can't find the file anymore. envPath is just .${self:provider.stage}.env. I think this related to change when the plugin loads the env file.

Thanks!

@colynb
Copy link
Collaborator

colynb commented Aug 7, 2018 via email

@slavaguzenko-vicinity
Copy link

@colynb I think restoring hooks in the constructor should fix the problem:

// this.loadEnv()
this.hooks = {
  "before:offline:start:init": this.loadEnv.bind(this),
  "before:offline:start": this.loadEnv.bind(this),
  "before:invoke:local:invoke": this.loadEnv.bind(this),
  "before:deploy:resources": this.loadEnv.bind(this),
  "before:deploy:functions": this.loadEnv.bind(this),
  "before:package:initialize": this.loadEnv.bind(this),
}

@colynb
Copy link
Collaborator

colynb commented Sep 24, 2018

Hi @otbe - I've included an update to master branch with a new feature that I think resolves this issue. I have not published it to npm yet so if you wanted to try it out, just clone the repo. In a nutshell, you can control which env file is loaded based on what the environment is set to. You can set environment one of two ways: by setting NODE_ENV or passing in the --env option in the sls command. I've updated the README with more detailed instructions: https://github.com/infrontlabs/serverless-dotenv-plugin#automatic-env-file-name-resolution

@otbe
Copy link
Author

otbe commented Sep 25, 2018

Hi @colynb

thanks for the update. 👍
Im not quite sure if this is a way I would like to go. We use many "stages" that are all build with NODE_ENV=production (configured by webpacks mode). So all artifacts are build in "production" mode and deployed with slightly different .env files for each stage. I dont know if there are any sideffects by setting NODE_ENV to something like "stage1" even if its set to "production" by webpack internally. 🤔

Any thoughts?

@colynb
Copy link
Collaborator

colynb commented Sep 25, 2018 via email

@otbe
Copy link
Author

otbe commented Sep 25, 2018

Oh 😱
Sorry I totally misinterpreted that part. Yes I think this should be fine for us :)

@colynb
Copy link
Collaborator

colynb commented Sep 25, 2018 via email

@otbe
Copy link
Author

otbe commented Sep 25, 2018

Dont know :/
At a first glance I thought --env is an alias to set NODE_ENV and I skipped the rest of the docs. But its mentioned quite well that --env should be used if you cant set NODE_ENV. So this should be fine 🤔

@colynb colynb closed this as completed May 7, 2019
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