moodlehq / moodle-docker

A docker environment for moodle developers
GNU General Public License v3.0
406 stars 252 forks source link

Use .env file for directory/db #130

Closed iwasherefirst2 closed 1 year ago

iwasherefirst2 commented 4 years ago

Using an environment file for directory/db has the advantage that the user does not need to specify the variables after each reboot.

Added .env to gitignore list, to avoid that environment variables end up in repository.

Created moodle-start for convenience.

Updated readme.

Closes #80 Closes #81

danpoltawski commented 4 years ago

I realise I just posted two negative comments - I think the rest of the .env support is a great idea - thank you for contributing it. :-) :+1: - just wanted to make my thinking clear, @moodlehq now maintain this project.

iwasherefirst2 commented 4 years ago

I realise I just posted two negative comments - I think the rest of the .env support is a great idea - thank you for contributing it. :-) +1 - just wanted to make my thinking clear, @moodlehq now maintain this project.

Thank you. I also think using an .env is very convenient. Writing the path to your Moodle in the terminal every time after I boot my computer was time-consuming (long path) and error prone (typo). Also when I read the readme for the first time, I was very confused about the Quick start section. I was sure that this was a script that I have to adjust, so I went to all files in the folder. I was surprised when I found out that I actually have to type all this in the terminal. That is why I tried to be more explicit in the new readme.

stronk7 commented 3 years ago

Hi @iwasherefirst2,

nice improvement!

Would you mind, please, rebasing your commits on top of current master (I think you will face some minor conflicts to solve with that). And then proceed to squash current 6 commits, so everything can get the final review and, hopefully, land all-together?

Ciao :-)

stronk7 commented 3 years ago

Side comment about this patch, because for example it will affect some of my usual flows with moodle-docker.

Maybe the .env file should be setting the env variables only if they aren't defined ? I mean, basically act as "defaults" more that "environment" and only apply for them if undefined.

Real example: I've here some wrappers over moodle-docker that are basically a couple of nested loops changing the PHP versions (MOODLE_DOCKER_PHP_VERSION) and the databases (MOODLE_DOCKER_DB). I know that I can continue using it as is, as far as I don't create the .env file... everything will continue working the same.

But, if I normally want to work with postgres (for example) and I'm interested into the new file... then the wrapper above will stop working, because the variables in that file will, always, get precedence over the already specified ones.

So, just guessing if we should consider "renaming" all this from "env" to "defaults" and provide that slightly different behavior. For people not switching often it will behave 100% the same. But for crazy-switchers will make life easier.

Thoughts?

BTW, another little idea, is that maybe the .env.example template, better if it's not invisible and, also, maybe better if it has some comment about the possibility of setting up any other env variable there to make it explicitly clear.

Up to you, only a couple of details that came to my brain when reviewing current proposed patch.

Thanks for your contribution, much appreciated!

Ciao :-)

skodak commented 1 year ago

I have used a bit different approach in https://github.com/moodlehq/moodle-docker/pull/232