fix(listmailuser): Don't query quota, if ENABLE_QUOTAS is not 1#2264
fix(listmailuser): Don't query quota, if ENABLE_QUOTAS is not 1#2264casperklein merged 19 commits intodocker-mailserver:masterfrom
Conversation
polarathene
left a comment
There was a problem hiding this comment.
Any logic that's trying to apply defaults that should have been applied already is a bit of a red flag, especially for maintenance.
For now, maintain this as a separate file (eg: /target/scripts/init-default-env.sh) and source that. helper-functions.sh is commonly sourced by utilities (and pretty much everything else), so is probably an appropriate place to import this workaround.
We should be able to avoid the issue entirely via an entrypoint script in future.
I think clearing the files is a good practice to avoid duplicate entrys, when the container is restarted. |
-ENTRYPOINT ["/usr/bin/dumb-init", "--"]
+ENTRYPOINT ["/usr/bin/dumb-init", "/entrypoint.sh"]
CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]Supposedly that would work fine, but allow conditional logic based on the CMD used?
I only bring it up because of I guess if I have had interest with adding an entrypoint script in the past, but I can definitely understand how always setting up ENV could be an issue (eg: the docker-mailserver/test/tests.bats Lines 478 to 482 in fb72f3a That's just running the container and echoing the ENV that was set on it. The
Likewise two tests that use Just a caveat to be aware of, doesn't seem like it would cause any problems for the project atm though 👍 |
polarathene
left a comment
There was a problem hiding this comment.
LGTM 👍
Just need to update the test to work with the new /etc/dms-settings approach 😀
| for VAR in "${!VARS[@]}" | ||
| do | ||
| echo "export ${VAR}='${VARS[${VAR}]}'" >>/root/.bashrc | ||
| echo "${VAR}='${VARS[${VAR}]}'" >>/etc/dms-settings |
There was a problem hiding this comment.
I didn't see in the discussion what the point of dropping the export prefix was? Couldn't you just dump these to /etc/dms-settings as before instead of /root/.bashrc? Then have /root/.bashrc source /etc/dms-settings?
Or was there some reason to want to temporarily set/override ENV without making it available to subprocesses?
I'm fine with whatever you go with, you have a better understanding of this stuff than me 😅 It seems better than maintaining a bunch of conditional default assignments like the previous approach 👍 (except for loss of compatibility with docker run or the docker exec ... sh -c ... overrride)
There was a problem hiding this comment.
The reason is pretty simple: The file should only contain the current container settings and not any further commands/logic. So if a script needs them (afaik this is the first time), the file can just be sourced. There is no need for "export". If a script needs our variables exported to a subprocess, it can do it on its own.
There was a problem hiding this comment.
Just seemed more consistent in behaviour/expectation if we kept the export as if .bashrc isn't loaded (eg: because of bash -c), then we're still able to make the expected environment available to our scripts. And I say that in the sense that sometimes calling a command may have the environment already made available to it, while the other context is sourcing it without the export.
I think we're more likely to run into troubleshooting issues from that inconsistency more than we would be from issues of having the env exported when it's one of the expected contexts and the whole point of this PR is a workaround for when that hasn't happened to ensure defaults are correctly fallen back to.
Not my forte here, so if your more confident in avoiding export as the better approach go for it 😎
There was a problem hiding this comment.
as if .bashrc isn't loaded
For clarification: the DMS variable stuff in .bashrc is not used in any way. It's just there (I think), to quickly check what ENVs the running container uses. So when you start a bash session, you can easily do something like echo $SOME_DMS_VAR.
That said, I don't think the exports in .bashrc aren't needed for anything DMS rely on.
Edit: The only exception is VIRUSMAILS_DELETE_DELAY.
The only script that need to access a DMS var (ENABLE_QUOTA) is listmailuser. I don't think introducing a entrypoint script is worth it. If there is more demand/scripts in the future, we can still implement it.
There was a problem hiding this comment.
The whole .bashrc thing started with this for the VIRUSMAILS_DELETE_DELAY.
Oups. You already figured that out above.
There was a problem hiding this comment.
start-mailserver.sh: default to 7 (makes the Dockerfile ENV a bit redundant? When the Dockerfile ENV was added in 2017 this var was removed, but then added back in 2018 to resolve an issue)
I think there is a room for improvements 😉 I am wondering, if any of the ENVs in Dockerfile nowadays are needed.
There was a problem hiding this comment.
Edit: The only exception is VIRUSMAILS_DELETE_DELAY.
Or maybe not 😆 You also wrote, that VIRUSMAILS_DELETE_DELAY is also in /etc/environment.
Correct. Haven't consider this till now. The script will throw an error "/usr/local/bin/listmailuser: line 5: /etc/dms-settings: No such file or directory" but then continues flawless, which I didn't understand at first. See below why. Some time back, you wanted us to use 1 #!/bin/bash
2
3 if [ "$SOME_UNSET_VARIABLE" -eq 0 ]; then
4 echo "foo"
5 fi
6
7 if [[ "$SOME_UNSET_VARIABLE" -eq 0 ]]; then
8 echo "bar"
9 fiI stumpled upon this, because I wondered, why listmailuser didn't fail, when $ENABLE_QUOTA was unset (called via setup.sh and no container running). |
That works how I'd expect tbh. The value is unset/null/false, so I expect the it to evaluate to equivalent of 0 (falsey). Some programming languages at least behave that way. Although |
|
I guess this is some kind of Bashism, but it also kind of makes sense to me. What you brought up a If this was a programming language like C or Rust or something else with a strict typing discipline, I'd consider this a drawback too, but with Bash, I've learned to just accept it :D |
Description
Fixes #2263 (comment) and introduces a new file
/etc/dms-settings, which contains all DMS specific settings.Type of change
Checklist:
docs/)