moodle-docker icon indicating copy to clipboard operation
moodle-docker copied to clipboard

Use .env file for directory/db

Open iwasherefirst2 opened this issue 4 years ago • 5 comments

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

iwasherefirst2 avatar Jun 23 '20 22:06 iwasherefirst2

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.

danpoltawski avatar Jun 24 '20 00:06 danpoltawski

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.

iwasherefirst2 avatar Jun 24 '20 05:06 iwasherefirst2

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 avatar May 30 '21 22:05 stronk7

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 :-)

stronk7 avatar May 30 '21 22:05 stronk7

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

skodak avatar Oct 07 '22 10:10 skodak