MDeLuise / plant-it

🪴 Self-hosted, open source gardening companion app
https://plant-it.org
GNU General Public License v3.0
545 stars 19 forks source link

Can't use Local environment #58

Closed cesarblancg closed 8 months ago

cesarblancg commented 10 months ago

Question

Hi! I attempted to run it in my local environment to experiment with new features, but I’m unable to set the API key.

Steps:

Clone the repository. Set the Trefle API key in the .env file. Launch it with “./mvnw spring-boot:run -Dspring-boot.run.profiles=dev -DcopyFiles”. Log in with user/user credentials. How can I set the API key? It’s showing an error.

MDeLuise commented 10 months ago

Hi! Thanks for the feedback, I'm happy to hear that you want to try the app in a "developer mode". You're right, I tried to run locally the backend as specified in the readme and it's not possible to change the default variable values using the .env file. I didn't notice this before since I use IntelliJ to run the backend and I put the TREFLE_KEY as environment variable inside the profile I use for the app from the IDE.

Problem

The problem is the following: the backend (spring) uses the provided application[-profile].properties files in order to read the variables. In those files there are the specified default values and global variable names to override these default values.

On the docker deployment, the .env file is passed as global variables so this works as expected.

Temporary solution

As for now, you can:

Long term solution

I have to understand how to make possible for spring to load external environment files. From a first research it seems that spring does not support external env file natively but there are some plugins in order to achieve this.

MDeLuise commented 8 months ago

Hi @cesarblancg I updated the documentation about the local environment.

I still have to check how to pass an environment file with all the properties in a local deployment (like it's done in docker deployment), but for now for the backend service it's possibile to pass the property values from the CLI running

./mvnw spring-boot:run -Dspring-boot.run.profiles=dev -DcopyFiles -Dspring-boot.run.arguments="--<param_name_1>=<param_value_1> --<param_name_2>=<param_value_2>"

For example, if you want to use TREFLE_KEY in a local deployment you can run the following command

./mvnw spring-boot:run -Dspring-boot.run.profiles=dev -DcopyFiles -Dspring-boot.run.arguments="--TREFLE_KEY=xxx"

Reopen the issue without any problem if something does not work as expected.