Allocate docker limits based on server size.
This assumes 1-builder per server.
It is still able to be overwritten by settings,
so to have this take effect we need to set:
```
DOCKER_LIMITS = None
```
import logging
import re
+import subprocess
from django.conf import settings
@@ -25,9 +26,37 @@ if old_config:
)
DOCKER_IMAGE_SETTINGS.update(old_config)
-DOCKER_LIMITS = {'memory': '200m', 'time': 600}
+DOCKER_LIMITS = {
+ 'memory': '200m',
+ 'time': 600,
+}
+
+# Set docker limits dynamically based on system memory
+free_memory = int(subprocess.check_output("free -m | awk '/^Mem:/{print $2}'", shell=True))
+if free_memory > 14000:
+ DOCKER_LIMITS.update({
+ 'memory': '13g',
+ 'time': 2400,
+ })
+elif free_memory > 8000:
+ DOCKER_LIMITS.update({
+ 'memory': '7g',
+ 'time': 1800,
+ })
+elif free_memory > 4000:
+ DOCKER_LIMITS.update({
+ 'memory': '3g',
+ 'time': 900,
+ })
+elif free_memory > 2000:
+ DOCKER_LIMITS.update({
+ 'memory': '1g',
+ 'time': 600,
+ })
+
DOCKER_LIMITS.update(settings.DOCKER_LIMITS)
+
DOCKER_TIMEOUT_EXIT_CODE = 42
DOCKER_OOM_EXIT_CODE = 137
