From a552da6f91a33d0547bdb92c63ca38aba2b5dc10 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Sun, 11 Oct 2026 12:02:04 +0200 Subject: [PATCH] fix(oci): a Compose reservation is not the memory limit of the container What a Compose file reserves is the least the application is promised, not the most it may use. 81 recipes had taken it as the memory of the container, as low as 128 MB, and the kernel stopped applications such as Home Assistant Official and UniFi Network. Without a limit in the file the container gets the standard 1024 MB, or the reservation when it is larger. A limit the file sets is kept. --- oci/catalog/apps/2fauth.json | 2 +- oci/catalog/apps/actualbudget.json | 2 +- oci/catalog/apps/adguard-home.json | 2 +- oci/catalog/apps/adminer.json | 2 +- oci/catalog/apps/alist.json | 2 +- oci/catalog/apps/archivebox.json | 2 +- oci/catalog/apps/audiobookshelf.json | 2 +- oci/catalog/apps/bentopdf.json | 2 +- oci/catalog/apps/blinko.json | 2 +- oci/catalog/apps/chatgpt-next-web.json | 2 +- oci/catalog/apps/cloudbeaver.json | 2 +- oci/catalog/apps/convertx.json | 2 +- oci/catalog/apps/copyparty.json | 2 +- oci/catalog/apps/ddns-go.json | 2 +- oci/catalog/apps/deepseek-ocr-nvidia.json | 2 +- oci/catalog/apps/docmost.json | 2 +- oci/catalog/apps/embystat.json | 2 +- oci/catalog/apps/esphome.json | 2 +- oci/catalog/apps/etherpad.json | 2 +- oci/catalog/apps/excalidraw.json | 2 +- oci/catalog/apps/firefly.json | 2 +- oci/catalog/apps/flaresolverr.json | 2 +- oci/catalog/apps/flowise.json | 2 +- oci/catalog/apps/gateway-go.json | 2 +- oci/catalog/apps/gitea.json | 2 +- oci/catalog/apps/glances.json | 2 +- oci/catalog/apps/grafana.json | 2 +- oci/catalog/apps/homeassistant-official.json | 2 +- oci/catalog/apps/hugo.json | 2 +- oci/catalog/apps/karakeep.json | 2 +- oci/catalog/apps/kavita-jvmilazz0.json | 2 +- oci/catalog/apps/komga.json | 2 +- oci/catalog/apps/label-studio.json | 2 +- oci/catalog/apps/libredb-studio.json | 2 +- oci/catalog/apps/linkwarden.json | 2 +- oci/catalog/apps/logseq.json | 2 +- oci/catalog/apps/lucky.json | 2 +- oci/catalog/apps/lyrionmusicserver.json | 2 +- oci/catalog/apps/memos.json | 2 +- oci/catalog/apps/n8n.json | 2 +- oci/catalog/apps/netbird.json | 2 +- oci/catalog/apps/nextcloud-official.json | 2 +- oci/catalog/apps/nginxproxymanager.json | 2 +- oci/catalog/apps/node-red.json | 2 +- oci/catalog/apps/nzbfast.json | 2 +- oci/catalog/apps/open-webui-cuda.json | 2 +- oci/catalog/apps/open-webui-ollama.json | 2 +- oci/catalog/apps/open-webui.json | 2 +- oci/catalog/apps/openhab.json | 2 +- oci/catalog/apps/openlist.json | 2 +- oci/catalog/apps/openspeedtest.json | 2 +- oci/catalog/apps/opodsync.json | 2 +- oci/catalog/apps/pdfding.json | 2 +- oci/catalog/apps/peanut.json | 2 +- oci/catalog/apps/photoprism.json | 2 +- oci/catalog/apps/pihole.json | 2 +- oci/catalog/apps/pinchflat.json | 2 +- oci/catalog/apps/pingvin-share.json | 2 +- oci/catalog/apps/portainer.json | 2 +- oci/catalog/apps/psitransfer.json | 2 +- oci/catalog/apps/qbittorrent-hotio.json | 2 +- oci/catalog/apps/qui.json | 2 +- oci/catalog/apps/rdtclient.json | 2 +- oci/catalog/apps/readarr.json | 2 +- oci/catalog/apps/retroarch-inglebard.json | 2 +- oci/catalog/apps/romm.json | 2 +- oci/catalog/apps/siyuan-note.json | 2 +- .../apps/stable-diffusion-webui-nvidia.json | 2 +- oci/catalog/apps/tailscale.json | 2 +- oci/catalog/apps/teable.json | 2 +- oci/catalog/apps/trilium.json | 2 +- oci/catalog/apps/twingate-connector.json | 2 +- oci/catalog/apps/unifi-controller.json | 2 +- oci/catalog/apps/uptimekuma.json | 2 +- oci/catalog/apps/v2raya.json | 2 +- oci/catalog/apps/vaultwarden.json | 2 +- oci/catalog/apps/vocechat.json | 2 +- oci/catalog/apps/wallabag.json | 2 +- oci/catalog/apps/weknora.json | 2 +- oci/catalog/apps/ztnet.json | 2 +- oci/catalog/curated/open-webui-cuda.json | 2 +- oci/catalog/curated/open-webui-ollama.json | 2 +- oci/catalog/curated/open-webui.json | 2 +- oci/src/proxmenux_oci/casaos.py | 23 ++++++--- oci/tests/test_container_memory.py | 47 +++++++++++++++++++ 85 files changed, 147 insertions(+), 89 deletions(-) create mode 100644 oci/tests/test_container_memory.py diff --git a/oci/catalog/apps/2fauth.json b/oci/catalog/apps/2fauth.json index 32aec4b5..468010de 100644 --- a/oci/catalog/apps/2fauth.json +++ b/oci/catalog/apps/2fauth.json @@ -233,7 +233,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/actualbudget.json b/oci/catalog/apps/actualbudget.json index 3ac8a4a6..94d9a264 100644 --- a/oci/catalog/apps/actualbudget.json +++ b/oci/catalog/apps/actualbudget.json @@ -210,7 +210,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/adguard-home.json b/oci/catalog/apps/adguard-home.json index d811c81d..b3df1c3d 100644 --- a/oci/catalog/apps/adguard-home.json +++ b/oci/catalog/apps/adguard-home.json @@ -291,7 +291,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/adminer.json b/oci/catalog/apps/adminer.json index dbd75a29..a0e1e433 100644 --- a/oci/catalog/apps/adminer.json +++ b/oci/catalog/apps/adminer.json @@ -170,7 +170,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/alist.json b/oci/catalog/apps/alist.json index 11511147..4b6da070 100644 --- a/oci/catalog/apps/alist.json +++ b/oci/catalog/apps/alist.json @@ -211,7 +211,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/archivebox.json b/oci/catalog/apps/archivebox.json index f85fdb8a..b6e4d018 100644 --- a/oci/catalog/apps/archivebox.json +++ b/oci/catalog/apps/archivebox.json @@ -513,7 +513,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/audiobookshelf.json b/oci/catalog/apps/audiobookshelf.json index 54203ad0..f211b591 100644 --- a/oci/catalog/apps/audiobookshelf.json +++ b/oci/catalog/apps/audiobookshelf.json @@ -286,7 +286,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/bentopdf.json b/oci/catalog/apps/bentopdf.json index 41695b68..ce275314 100644 --- a/oci/catalog/apps/bentopdf.json +++ b/oci/catalog/apps/bentopdf.json @@ -214,7 +214,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/blinko.json b/oci/catalog/apps/blinko.json index 71bd6270..e5bb7665 100644 --- a/oci/catalog/apps/blinko.json +++ b/oci/catalog/apps/blinko.json @@ -364,7 +364,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/chatgpt-next-web.json b/oci/catalog/apps/chatgpt-next-web.json index 19c3f277..3b21e01f 100644 --- a/oci/catalog/apps/chatgpt-next-web.json +++ b/oci/catalog/apps/chatgpt-next-web.json @@ -226,7 +226,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/cloudbeaver.json b/oci/catalog/apps/cloudbeaver.json index 036e27a1..4d1758f1 100644 --- a/oci/catalog/apps/cloudbeaver.json +++ b/oci/catalog/apps/cloudbeaver.json @@ -213,7 +213,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/convertx.json b/oci/catalog/apps/convertx.json index ae1c7dc0..33e4cf79 100644 --- a/oci/catalog/apps/convertx.json +++ b/oci/catalog/apps/convertx.json @@ -237,7 +237,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 500, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/copyparty.json b/oci/catalog/apps/copyparty.json index 2345eeb3..1676786a 100644 --- a/oci/catalog/apps/copyparty.json +++ b/oci/catalog/apps/copyparty.json @@ -244,7 +244,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/ddns-go.json b/oci/catalog/apps/ddns-go.json index 7f431509..32595a79 100644 --- a/oci/catalog/apps/ddns-go.json +++ b/oci/catalog/apps/ddns-go.json @@ -211,7 +211,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/deepseek-ocr-nvidia.json b/oci/catalog/apps/deepseek-ocr-nvidia.json index b5d3e800..09db6503 100644 --- a/oci/catalog/apps/deepseek-ocr-nvidia.json +++ b/oci/catalog/apps/deepseek-ocr-nvidia.json @@ -261,7 +261,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/docmost.json b/oci/catalog/apps/docmost.json index 69b16273..a2395275 100644 --- a/oci/catalog/apps/docmost.json +++ b/oci/catalog/apps/docmost.json @@ -371,7 +371,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/embystat.json b/oci/catalog/apps/embystat.json index 30b1f655..4472fca6 100644 --- a/oci/catalog/apps/embystat.json +++ b/oci/catalog/apps/embystat.json @@ -238,7 +238,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/esphome.json b/oci/catalog/apps/esphome.json index f34a54f2..478002f6 100644 --- a/oci/catalog/apps/esphome.json +++ b/oci/catalog/apps/esphome.json @@ -231,7 +231,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/etherpad.json b/oci/catalog/apps/etherpad.json index e3040cab..7e8b5d27 100644 --- a/oci/catalog/apps/etherpad.json +++ b/oci/catalog/apps/etherpad.json @@ -318,7 +318,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/excalidraw.json b/oci/catalog/apps/excalidraw.json index ef6c1654..0df7f47c 100644 --- a/oci/catalog/apps/excalidraw.json +++ b/oci/catalog/apps/excalidraw.json @@ -173,7 +173,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/firefly.json b/oci/catalog/apps/firefly.json index 81db99f2..ba44cbd0 100644 --- a/oci/catalog/apps/firefly.json +++ b/oci/catalog/apps/firefly.json @@ -249,7 +249,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/flaresolverr.json b/oci/catalog/apps/flaresolverr.json index 07f69f0b..3c5e48c1 100644 --- a/oci/catalog/apps/flaresolverr.json +++ b/oci/catalog/apps/flaresolverr.json @@ -237,7 +237,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/flowise.json b/oci/catalog/apps/flowise.json index ec7a1cd3..b5bad139 100644 --- a/oci/catalog/apps/flowise.json +++ b/oci/catalog/apps/flowise.json @@ -300,7 +300,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/gateway-go.json b/oci/catalog/apps/gateway-go.json index fd4ccb11..09eec148 100644 --- a/oci/catalog/apps/gateway-go.json +++ b/oci/catalog/apps/gateway-go.json @@ -211,7 +211,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/gitea.json b/oci/catalog/apps/gitea.json index e8e3aa2e..5b02d08b 100644 --- a/oci/catalog/apps/gitea.json +++ b/oci/catalog/apps/gitea.json @@ -242,7 +242,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/glances.json b/oci/catalog/apps/glances.json index 02a6c1f3..c441cce7 100644 --- a/oci/catalog/apps/glances.json +++ b/oci/catalog/apps/glances.json @@ -243,7 +243,7 @@ "unprivileged": false, "ostype": "unmanaged", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/grafana.json b/oci/catalog/apps/grafana.json index 81d193df..472bd03b 100644 --- a/oci/catalog/apps/grafana.json +++ b/oci/catalog/apps/grafana.json @@ -211,7 +211,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/homeassistant-official.json b/oci/catalog/apps/homeassistant-official.json index af324258..1e263365 100644 --- a/oci/catalog/apps/homeassistant-official.json +++ b/oci/catalog/apps/homeassistant-official.json @@ -288,7 +288,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/hugo.json b/oci/catalog/apps/hugo.json index 6a285770..8e8de341 100644 --- a/oci/catalog/apps/hugo.json +++ b/oci/catalog/apps/hugo.json @@ -247,7 +247,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/karakeep.json b/oci/catalog/apps/karakeep.json index 76e7dc1d..d943f6a8 100644 --- a/oci/catalog/apps/karakeep.json +++ b/oci/catalog/apps/karakeep.json @@ -407,7 +407,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/kavita-jvmilazz0.json b/oci/catalog/apps/kavita-jvmilazz0.json index ba19aa34..6684e8d5 100644 --- a/oci/catalog/apps/kavita-jvmilazz0.json +++ b/oci/catalog/apps/kavita-jvmilazz0.json @@ -254,7 +254,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/komga.json b/oci/catalog/apps/komga.json index c258f5cb..4f656f34 100644 --- a/oci/catalog/apps/komga.json +++ b/oci/catalog/apps/komga.json @@ -294,7 +294,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/label-studio.json b/oci/catalog/apps/label-studio.json index 1b541fb8..7b8739ad 100644 --- a/oci/catalog/apps/label-studio.json +++ b/oci/catalog/apps/label-studio.json @@ -237,7 +237,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/libredb-studio.json b/oci/catalog/apps/libredb-studio.json index ec034ab1..14d4da2e 100644 --- a/oci/catalog/apps/libredb-studio.json +++ b/oci/catalog/apps/libredb-studio.json @@ -296,7 +296,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/linkwarden.json b/oci/catalog/apps/linkwarden.json index cb04c3b8..dffe71a0 100644 --- a/oci/catalog/apps/linkwarden.json +++ b/oci/catalog/apps/linkwarden.json @@ -467,7 +467,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/logseq.json b/oci/catalog/apps/logseq.json index 0f5d9872..92ee7cb6 100644 --- a/oci/catalog/apps/logseq.json +++ b/oci/catalog/apps/logseq.json @@ -275,7 +275,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/lucky.json b/oci/catalog/apps/lucky.json index 6878f2b3..f1433952 100644 --- a/oci/catalog/apps/lucky.json +++ b/oci/catalog/apps/lucky.json @@ -207,7 +207,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/lyrionmusicserver.json b/oci/catalog/apps/lyrionmusicserver.json index 8b08c640..5f73ff18 100644 --- a/oci/catalog/apps/lyrionmusicserver.json +++ b/oci/catalog/apps/lyrionmusicserver.json @@ -389,7 +389,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/memos.json b/oci/catalog/apps/memos.json index e40a9227..abf6170c 100644 --- a/oci/catalog/apps/memos.json +++ b/oci/catalog/apps/memos.json @@ -238,7 +238,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/n8n.json b/oci/catalog/apps/n8n.json index 5862f5e4..a161194a 100644 --- a/oci/catalog/apps/n8n.json +++ b/oci/catalog/apps/n8n.json @@ -230,7 +230,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 320, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/netbird.json b/oci/catalog/apps/netbird.json index 6ac9bdf0..76bffa84 100644 --- a/oci/catalog/apps/netbird.json +++ b/oci/catalog/apps/netbird.json @@ -247,7 +247,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/nextcloud-official.json b/oci/catalog/apps/nextcloud-official.json index ad64fdb8..27d0a3ab 100644 --- a/oci/catalog/apps/nextcloud-official.json +++ b/oci/catalog/apps/nextcloud-official.json @@ -223,7 +223,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/nginxproxymanager.json b/oci/catalog/apps/nginxproxymanager.json index 6c9dda62..be605e7f 100644 --- a/oci/catalog/apps/nginxproxymanager.json +++ b/oci/catalog/apps/nginxproxymanager.json @@ -267,7 +267,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/node-red.json b/oci/catalog/apps/node-red.json index 64c5aa78..066aa2fb 100644 --- a/oci/catalog/apps/node-red.json +++ b/oci/catalog/apps/node-red.json @@ -211,7 +211,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/nzbfast.json b/oci/catalog/apps/nzbfast.json index 5efed1c5..62ab3f81 100644 --- a/oci/catalog/apps/nzbfast.json +++ b/oci/catalog/apps/nzbfast.json @@ -321,7 +321,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/open-webui-cuda.json b/oci/catalog/apps/open-webui-cuda.json index 2c34636d..a62686e1 100644 --- a/oci/catalog/apps/open-webui-cuda.json +++ b/oci/catalog/apps/open-webui-cuda.json @@ -233,7 +233,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/open-webui-ollama.json b/oci/catalog/apps/open-webui-ollama.json index d057f636..6d0369cd 100644 --- a/oci/catalog/apps/open-webui-ollama.json +++ b/oci/catalog/apps/open-webui-ollama.json @@ -249,7 +249,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/open-webui.json b/oci/catalog/apps/open-webui.json index 79b77b3a..e051d915 100644 --- a/oci/catalog/apps/open-webui.json +++ b/oci/catalog/apps/open-webui.json @@ -233,7 +233,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/openhab.json b/oci/catalog/apps/openhab.json index 203dc82c..2af80a5a 100644 --- a/oci/catalog/apps/openhab.json +++ b/oci/catalog/apps/openhab.json @@ -353,7 +353,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/openlist.json b/oci/catalog/apps/openlist.json index cf7ddcd8..699a2db5 100644 --- a/oci/catalog/apps/openlist.json +++ b/oci/catalog/apps/openlist.json @@ -242,7 +242,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/openspeedtest.json b/oci/catalog/apps/openspeedtest.json index 53593358..a2e5912a 100644 --- a/oci/catalog/apps/openspeedtest.json +++ b/oci/catalog/apps/openspeedtest.json @@ -175,7 +175,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/opodsync.json b/oci/catalog/apps/opodsync.json index d2680e52..c99f50c6 100644 --- a/oci/catalog/apps/opodsync.json +++ b/oci/catalog/apps/opodsync.json @@ -209,7 +209,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/pdfding.json b/oci/catalog/apps/pdfding.json index 395d8d91..b935fd18 100644 --- a/oci/catalog/apps/pdfding.json +++ b/oci/catalog/apps/pdfding.json @@ -297,7 +297,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/peanut.json b/oci/catalog/apps/peanut.json index 51fa53f8..28e65b0a 100644 --- a/oci/catalog/apps/peanut.json +++ b/oci/catalog/apps/peanut.json @@ -221,7 +221,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/photoprism.json b/oci/catalog/apps/photoprism.json index e18061be..500fbcc8 100644 --- a/oci/catalog/apps/photoprism.json +++ b/oci/catalog/apps/photoprism.json @@ -281,7 +281,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/pihole.json b/oci/catalog/apps/pihole.json index 0cb42c98..57ed8c6d 100644 --- a/oci/catalog/apps/pihole.json +++ b/oci/catalog/apps/pihole.json @@ -288,7 +288,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/pinchflat.json b/oci/catalog/apps/pinchflat.json index 5a079d46..994f3350 100644 --- a/oci/catalog/apps/pinchflat.json +++ b/oci/catalog/apps/pinchflat.json @@ -269,7 +269,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/pingvin-share.json b/oci/catalog/apps/pingvin-share.json index 41eda8ca..dd299349 100644 --- a/oci/catalog/apps/pingvin-share.json +++ b/oci/catalog/apps/pingvin-share.json @@ -252,7 +252,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/portainer.json b/oci/catalog/apps/portainer.json index 7adf13e3..759063f5 100644 --- a/oci/catalog/apps/portainer.json +++ b/oci/catalog/apps/portainer.json @@ -267,7 +267,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/psitransfer.json b/oci/catalog/apps/psitransfer.json index 7384a0dd..b4689f00 100644 --- a/oci/catalog/apps/psitransfer.json +++ b/oci/catalog/apps/psitransfer.json @@ -232,7 +232,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/qbittorrent-hotio.json b/oci/catalog/apps/qbittorrent-hotio.json index ba4b2d8f..47763764 100644 --- a/oci/catalog/apps/qbittorrent-hotio.json +++ b/oci/catalog/apps/qbittorrent-hotio.json @@ -278,7 +278,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/qui.json b/oci/catalog/apps/qui.json index 19dcf5e2..2f07166a 100644 --- a/oci/catalog/apps/qui.json +++ b/oci/catalog/apps/qui.json @@ -307,7 +307,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/rdtclient.json b/oci/catalog/apps/rdtclient.json index 29447342..eefad3fb 100644 --- a/oci/catalog/apps/rdtclient.json +++ b/oci/catalog/apps/rdtclient.json @@ -281,7 +281,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/readarr.json b/oci/catalog/apps/readarr.json index a1d42968..c7e533ad 100644 --- a/oci/catalog/apps/readarr.json +++ b/oci/catalog/apps/readarr.json @@ -302,7 +302,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/retroarch-inglebard.json b/oci/catalog/apps/retroarch-inglebard.json index fb67744f..7b368c85 100644 --- a/oci/catalog/apps/retroarch-inglebard.json +++ b/oci/catalog/apps/retroarch-inglebard.json @@ -181,7 +181,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/romm.json b/oci/catalog/apps/romm.json index aebcbb3e..cd98a442 100644 --- a/oci/catalog/apps/romm.json +++ b/oci/catalog/apps/romm.json @@ -542,7 +542,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/siyuan-note.json b/oci/catalog/apps/siyuan-note.json index e2de9f5f..9da16c4f 100644 --- a/oci/catalog/apps/siyuan-note.json +++ b/oci/catalog/apps/siyuan-note.json @@ -231,7 +231,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/stable-diffusion-webui-nvidia.json b/oci/catalog/apps/stable-diffusion-webui-nvidia.json index b9f792f9..2da77dae 100644 --- a/oci/catalog/apps/stable-diffusion-webui-nvidia.json +++ b/oci/catalog/apps/stable-diffusion-webui-nvidia.json @@ -296,7 +296,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/tailscale.json b/oci/catalog/apps/tailscale.json index 774601a3..c763012f 100644 --- a/oci/catalog/apps/tailscale.json +++ b/oci/catalog/apps/tailscale.json @@ -244,7 +244,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/teable.json b/oci/catalog/apps/teable.json index 39b67beb..40910c31 100644 --- a/oci/catalog/apps/teable.json +++ b/oci/catalog/apps/teable.json @@ -425,7 +425,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/trilium.json b/oci/catalog/apps/trilium.json index 46879e05..7f4d89d2 100644 --- a/oci/catalog/apps/trilium.json +++ b/oci/catalog/apps/trilium.json @@ -213,7 +213,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/twingate-connector.json b/oci/catalog/apps/twingate-connector.json index c47c2abc..f37a70ec 100644 --- a/oci/catalog/apps/twingate-connector.json +++ b/oci/catalog/apps/twingate-connector.json @@ -216,7 +216,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 500, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/unifi-controller.json b/oci/catalog/apps/unifi-controller.json index 2411d60f..4a0bb12e 100644 --- a/oci/catalog/apps/unifi-controller.json +++ b/oci/catalog/apps/unifi-controller.json @@ -342,7 +342,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/uptimekuma.json b/oci/catalog/apps/uptimekuma.json index 0ab13ac1..fbe62a72 100644 --- a/oci/catalog/apps/uptimekuma.json +++ b/oci/catalog/apps/uptimekuma.json @@ -211,7 +211,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/v2raya.json b/oci/catalog/apps/v2raya.json index 43487c68..89511dd3 100644 --- a/oci/catalog/apps/v2raya.json +++ b/oci/catalog/apps/v2raya.json @@ -260,7 +260,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/vaultwarden.json b/oci/catalog/apps/vaultwarden.json index 2520d5cb..c2ca821b 100644 --- a/oci/catalog/apps/vaultwarden.json +++ b/oci/catalog/apps/vaultwarden.json @@ -231,7 +231,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/vocechat.json b/oci/catalog/apps/vocechat.json index 4d0d200e..795adfdc 100644 --- a/oci/catalog/apps/vocechat.json +++ b/oci/catalog/apps/vocechat.json @@ -221,7 +221,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/wallabag.json b/oci/catalog/apps/wallabag.json index 99fe72ef..d1ef18aa 100644 --- a/oci/catalog/apps/wallabag.json +++ b/oci/catalog/apps/wallabag.json @@ -242,7 +242,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/weknora.json b/oci/catalog/apps/weknora.json index 9c6abb16..5aca62ef 100644 --- a/oci/catalog/apps/weknora.json +++ b/oci/catalog/apps/weknora.json @@ -890,7 +890,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 128, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/apps/ztnet.json b/oci/catalog/apps/ztnet.json index ee269f9a..37930b62 100644 --- a/oci/catalog/apps/ztnet.json +++ b/oci/catalog/apps/ztnet.json @@ -382,7 +382,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 256, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/curated/open-webui-cuda.json b/oci/catalog/curated/open-webui-cuda.json index f2473ad9..2cf90c35 100644 --- a/oci/catalog/curated/open-webui-cuda.json +++ b/oci/catalog/curated/open-webui-cuda.json @@ -233,7 +233,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/curated/open-webui-ollama.json b/oci/catalog/curated/open-webui-ollama.json index 58365f36..be01b724 100644 --- a/oci/catalog/curated/open-webui-ollama.json +++ b/oci/catalog/curated/open-webui-ollama.json @@ -249,7 +249,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/catalog/curated/open-webui.json b/oci/catalog/curated/open-webui.json index 98ddbfb1..48b39434 100644 --- a/oci/catalog/curated/open-webui.json +++ b/oci/catalog/curated/open-webui.json @@ -233,7 +233,7 @@ "unprivileged": true, "ostype": "auto-from-image", "cores": 2, - "memory_mb": 512, + "memory_mb": 1024, "swap_mb": 512, "rootfs_size_gb": 8, "rootfs_storage": "local-lvm", diff --git a/oci/src/proxmenux_oci/casaos.py b/oci/src/proxmenux_oci/casaos.py index b70403ad..ada25152 100644 --- a/oci/src/proxmenux_oci/casaos.py +++ b/oci/src/proxmenux_oci/casaos.py @@ -702,15 +702,26 @@ def _compose_stack_contract( } -def _memory_mb(service: dict[str, Any]) -> int: - value = (((service.get("deploy") or {}).get("resources") or {}).get("reservations") or {}).get("memory") +def _megabytes(value: Any) -> int | None: match = re.fullmatch(r"\s*(\d+(?:\.\d+)?)\s*([KMG]?)B?\s*", str(value or ""), re.I) if not match: - return 1024 - number = float(match.group(1)) - unit = match.group(2).upper() + return None factors = {"": 1 / (1024 * 1024), "K": 1 / 1024, "M": 1, "G": 1024} - return max(128, int(number * factors[unit])) + return int(float(match.group(1)) * factors[match.group(2).upper()]) + + +def _memory_mb(service: dict[str, Any]) -> int: + """The memory the container is given. What a Compose file reserves is the + least the application is promised, not the most it may use: Docker lets it + grow past that, and a container limited to it is stopped by the kernel as + soon as it needs more. A reservation only raises the default; a limit the + file sets is the memory of the container.""" + resources = (service.get("deploy") or {}).get("resources") or {} + limit = _megabytes((resources.get("limits") or {}).get("memory")) + reservation = _megabytes((resources.get("reservations") or {}).get("memory")) or 0 + if limit: + return max(128, limit, reservation) + return max(1024, reservation) def _blockers( diff --git a/oci/tests/test_container_memory.py b/oci/tests/test_container_memory.py new file mode 100644 index 00000000..f4698fe1 --- /dev/null +++ b/oci/tests/test_container_memory.py @@ -0,0 +1,47 @@ +"""What a Compose file reserves for an application is the least it is promised, +not the most it may use. A container limited to that figure is stopped by the +kernel as soon as the application needs more.""" + +from pathlib import Path +import sys +import unittest + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "src")) + +from proxmenux_oci.casaos import _memory_mb +from proxmenux_oci.catalog import Catalog + + +def service(reservation=None, limit=None): + resources = {} + if reservation: + resources["reservations"] = {"memory": reservation} + if limit: + resources["limits"] = {"memory": limit} + return {"deploy": {"resources": resources}} if resources else {} + + +class ContainerMemoryTests(unittest.TestCase): + def test_a_reservation_is_not_the_memory_of_the_container(self): + self.assertEqual(_memory_mb(service(reservation="64M")), 1024) + self.assertEqual(_memory_mb(service(reservation="256M")), 1024) + + def test_a_larger_reservation_raises_it(self): + self.assertEqual(_memory_mb(service(reservation="2G")), 2048) + + def test_a_limit_the_file_sets_is_the_memory_of_the_container(self): + self.assertEqual(_memory_mb(service(limit="512M")), 512) + self.assertEqual(_memory_mb(service(reservation="128M", limit="128M")), 128) + + def test_nothing_stated_is_the_default(self): + self.assertEqual(_memory_mb({}), 1024) + + def test_the_recipes_that_only_reserve_memory_get_the_default(self): + catalog = Catalog(ROOT) + for app in ("homeassistant-official", "unifi-controller", "grafana", "gitea", "vaultwarden", "uptimekuma"): + self.assertGreaterEqual(catalog.compose(app)["proxmox"]["defaults"]["memory_mb"], 1024, app) + + +if __name__ == "__main__": + unittest.main()