laravel-aws-worker icon indicating copy to clipboard operation
laravel-aws-worker copied to clipboard

Removed use of env function to support cached environments

Open jlorente opened this issue 7 years ago • 9 comments

This Pull Request removes the use of the env() function to obtain the value of the "REGISTER_WORKER_ROUTES" environment variable.

Is related to the this issue.

This pull request breaks compatibility with previous versions. Users who want to install a new version with this code will have to publish the package in order to make it work as it has been working until now.

jlorente avatar Feb 27 '18 18:02 jlorente

Any chance of getting this merged in?

Laravel Docs:

If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.

Thanks

dclawson avatar May 29 '19 20:05 dclawson

Merge this please!

faculezcano avatar Mar 31 '20 21:03 faculezcano

@faculezcano could you please give a real-world example of when a config would be cached? I always assumed that you set the environment variable once and pretty much don't have to touch again

dusterio avatar Mar 31 '20 22:03 dusterio

Oh i missed the point that im using elastic beanstalk to deploy and the project folder is purged, you're right isnt really needed.

faculezcano avatar Mar 31 '20 23:03 faculezcano

@dusterio See the Laravel documentation about this. env() function should not be used outside the config files.

image

jlorente avatar Apr 01 '20 08:04 jlorente

@jlorente this is correct for basic installations (with .env files). in case of AWS - we are talking brand new containers every time and real environment variables only. Containers are immutable

dusterio avatar Apr 01 '20 08:04 dusterio

Maybe you don't want to use the environment variables coming from EB because there is a limit of the environment variables that you can define in EB. In my case, I deploy an .env file with the application because the total size of my variables exceeds the 4,096 bytes limit. In any case, this solution will work with cached and non cached environments.

image

jlorente avatar Apr 01 '20 09:04 jlorente

@jlorente if you are deploying unique files (stateful) in your containers, why not just include a config file with values then? for variables that are longer than 4096 characters.

if I understand correctly the purpose of .env file was local machine development - to simulate real environment variables quickly.

The reason I chose to use env() rather than config file is because I wanted to make this package as little (overhead) as possible. Since it's for stateless containers, it didn't make sense to use config.

But I see your point, I only had to include longer variables with AWS once and what I did is - I broke long strings into multiple, numbered variables, then concatenated them later in the code.

dusterio avatar Apr 01 '20 09:04 dusterio

Ok, I understand your point of making the package as little as possible. Mine is a concrete case and I am working with my fork of the project now, so I have no need of merging this pull request. But answering your last point, the problem is not the length of one variable, but the total sum of all the variables and values that must not exceed 4096 bytes, so breaking one variable value into multiple variables will end with the same problem.

image

jlorente avatar Apr 01 '20 09:04 jlorente

Appreciate the insight and effort here! We have this under advisement and will consider this further but for now I am, respectfully, going to close this PR out.

fylzero avatar Jul 09 '23 05:07 fylzero