From d386c8e9c0dfab867a35308950b3aa7c43ddeed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Fri, 5 Sep 2025 12:32:48 -0400 Subject: [PATCH] wip --- bootc/base/env.sh | 1 - bootc/scenario1/Containerfile | 4 +- bootc/scenario1/env.sh | 1 - .../systemd/configs/nextcloud-app.env | 20 +++ .../systemd/configs/nextcloud-config.env.tmpl | 26 +++ .../systemd/configs/nextcloud-db.env | 5 + .../systemd/configs/nextcloud-redis.env | 1 + .../etc/containers/systemd/configs/nginx.conf | 163 ++++++++++++++++++ .../systemd/configs/redis-session.ini | 0 .../etc/containers/systemd/configs/redis.conf | 3 + .../etc/containers/systemd/configs/www.conf | 9 + .../containers/systemd/nextcloud-db.container | 39 +++++ .../systemd/nextcloud-fpm.container | 55 ++++++ .../systemd/nextcloud-nginx.container | 38 ++++ .../systemd/nextcloud-redis.container | 43 +++++ .../check/required.d/30_nextcloud_check.sh | 28 +++ .../root/etc/systemd/system/nextcloud.target | 10 ++ bootc/scenario4/Containerfile | 8 + .../systemd/configs/odoo-config.env.tmpl} | 0 .../containers/systemd/configs/odoo-db.env | 0 .../etc/containers/systemd/odoo-app.container | 3 + .../etc/containers/systemd/odoo-db.container | 7 +- .../containers/systemd/odoo-init.container | 3 + .../check/required.d/30_odoo_check.sh | 0 .../root/etc/odoo/init.sh | 0 .../root/etc/odoo/odoo.conf | 0 .../root/etc/systemd/system/odoo.target | 2 - 27 files changed, 459 insertions(+), 10 deletions(-) delete mode 100644 bootc/base/env.sh delete mode 100644 bootc/scenario1/env.sh create mode 100644 bootc/scenario1/root/etc/containers/systemd/configs/nextcloud-app.env create mode 100644 bootc/scenario1/root/etc/containers/systemd/configs/nextcloud-config.env.tmpl create mode 100644 bootc/scenario1/root/etc/containers/systemd/configs/nextcloud-db.env create mode 100644 bootc/scenario1/root/etc/containers/systemd/configs/nextcloud-redis.env create mode 100644 bootc/scenario1/root/etc/containers/systemd/configs/nginx.conf create mode 100644 bootc/scenario1/root/etc/containers/systemd/configs/redis-session.ini create mode 100644 bootc/scenario1/root/etc/containers/systemd/configs/redis.conf create mode 100644 bootc/scenario1/root/etc/containers/systemd/configs/www.conf create mode 100644 bootc/scenario1/root/etc/containers/systemd/nextcloud-db.container create mode 100644 bootc/scenario1/root/etc/containers/systemd/nextcloud-fpm.container create mode 100644 bootc/scenario1/root/etc/containers/systemd/nextcloud-nginx.container create mode 100644 bootc/scenario1/root/etc/containers/systemd/nextcloud-redis.container create mode 100755 bootc/scenario1/root/etc/greenboot/check/required.d/30_nextcloud_check.sh create mode 100644 bootc/scenario1/root/etc/systemd/system/nextcloud.target create mode 100644 bootc/scenario4/Containerfile rename bootc/{scenario1/root/etc/containers/systemd/configs/odoo-config.env => scenario4/root/etc/containers/systemd/configs/odoo-config.env.tmpl} (100%) rename bootc/{scenario1 => scenario4}/root/etc/containers/systemd/configs/odoo-db.env (100%) rename bootc/{scenario1 => scenario4}/root/etc/containers/systemd/odoo-app.container (91%) rename bootc/{scenario1 => scenario4}/root/etc/containers/systemd/odoo-db.container (87%) rename bootc/{scenario1 => scenario4}/root/etc/containers/systemd/odoo-init.container (92%) rename bootc/{scenario1 => scenario4}/root/etc/greenboot/check/required.d/30_odoo_check.sh (100%) rename bootc/{scenario1 => scenario4}/root/etc/odoo/init.sh (100%) rename bootc/{scenario1 => scenario4}/root/etc/odoo/odoo.conf (100%) rename bootc/{scenario1 => scenario4}/root/etc/systemd/system/odoo.target (73%) diff --git a/bootc/base/env.sh b/bootc/base/env.sh deleted file mode 100644 index f6bcac6..0000000 --- a/bootc/base/env.sh +++ /dev/null @@ -1 +0,0 @@ -TARGET_IMAGE="edge-registry.itix.fr/demo-edge-retail/generic:latest" diff --git a/bootc/scenario1/Containerfile b/bootc/scenario1/Containerfile index b136cbe..15b6195 100644 --- a/bootc/scenario1/Containerfile +++ b/bootc/scenario1/Containerfile @@ -1,8 +1,8 @@ -FROM edge-registry.itix.fr/demo-edge-retail/generic:latest +FROM edge-registry.itix.fr/demo-edge-retail/base:latest ADD --chown=root:root root / RUN </dev/null; for try in $(seq 0 12); do if ! /bin/true 5<> /dev/tcp/127.0.0.1/5432; then echo "Waiting for PostgreSQL to be available..."; sleep 5; else exit 0; fi; done; exit 1' + +# Wait for Redis to be ready +ExecStartPre=/bin/sh -c 'exec 2>/dev/null; for try in $(seq 0 12); do if ! /bin/true 5<> /dev/tcp/127.0.0.1/6379; then echo "Waiting for Redis to be available..."; sleep 5; else exit 0; fi; done; exit 1' + +[Install] +WantedBy=nextcloud.target diff --git a/bootc/scenario1/root/etc/containers/systemd/nextcloud-nginx.container b/bootc/scenario1/root/etc/containers/systemd/nextcloud-nginx.container new file mode 100644 index 0000000..92e506e --- /dev/null +++ b/bootc/scenario1/root/etc/containers/systemd/nextcloud-nginx.container @@ -0,0 +1,38 @@ +[Unit] +Description=Nextcloud Nginx Reverse Proxy +Documentation=https://nextcloud.com/ +After=network.target + +# Only start if Nextcloud has been configured +ConditionPathExists=/etc/containers/systemd/configs/nextcloud-config.env + +[Container] +ContainerName=nextcloud-nginx +Image=docker.io/nginxinc/nginx-unprivileged:1.20-alpine + +# Network configuration +Network=host +AddCapability=CAP_NET_BIND_SERVICE + +# Run with the same UID/GID as PHP-FPM +User=82:82 + +# Volume mounts +Volume=/var/lib/nextcloud/data:/var/www/html:z +Volume=/etc/containers/systemd/configs/nginx.conf:/etc/nginx/nginx.conf:ro + +# Health check (equivalent to readiness probe) +HealthCmd=curl -f http://localhost:80/status.php +HealthInterval=30s +HealthTimeout=10s +HealthStartPeriod=30s +HealthRetries=3 + +[Service] +Restart=always +RestartSec=5 +TimeoutStartSec=300 +TimeoutStopSec=30 + +[Install] +WantedBy=nextcloud.target diff --git a/bootc/scenario1/root/etc/containers/systemd/nextcloud-redis.container b/bootc/scenario1/root/etc/containers/systemd/nextcloud-redis.container new file mode 100644 index 0000000..651366d --- /dev/null +++ b/bootc/scenario1/root/etc/containers/systemd/nextcloud-redis.container @@ -0,0 +1,43 @@ +[Unit] +Description=Redis Cache for Nextcloud +Documentation=https://redis.io/ +After=network.target + +# Only start if Nextcloud has been configured +ConditionPathExists=/etc/containers/systemd/configs/nextcloud-config.env + +[Container] +ContainerName=nextcloud-redis +Image=docker.io/library/redis:8-alpine + +# Network configuration +Network=host + +# Redis configuration with authentication +Exec=redis-server /usr/local/etc/redis/redis.conf + +# Environment variables +EnvironmentFile=/etc/containers/systemd/configs/nextcloud-redis.env + +# Volume mounts for data persistence +Volume=/var/lib/redis:/data:Z +Volume=/etc/containers/systemd/configs/redis.conf:/usr/local/etc/redis/redis.conf:ro + +# Health check +HealthCmd=redis-cli ping | grep -q PONG +HealthInterval=30s +HealthTimeout=5s +HealthStartPeriod=10s +HealthRetries=3 + +[Service] +Restart=always +RestartSec=5 +TimeoutStartSec=300 +TimeoutStopSec=30 + +# Skaffold filesystem + fix permissions +ExecStartPre=install -m 0700 -o 0 -g 0 -d /var/lib/redis + +[Install] +WantedBy=nextcloud.target diff --git a/bootc/scenario1/root/etc/greenboot/check/required.d/30_nextcloud_check.sh b/bootc/scenario1/root/etc/greenboot/check/required.d/30_nextcloud_check.sh new file mode 100755 index 0000000..4e1978b --- /dev/null +++ b/bootc/scenario1/root/etc/greenboot/check/required.d/30_nextcloud_check.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -Eeuo pipefail +declare -a container_state=() +MAX_ATTEMPTS=60 + +for attempt in (( i=1; i<=MAX_ATTEMPTS; i++ )); do + echo "Checking Nextcloud deployment ($attempt/$MAX_ATTEMPTS)..." + + state=1 + for container in nextcloud-db nextcloud-redis nextcloud-fpm nextcloud-nginx; do + container_state=( $( ( podman inspect "$container" || true ) | jq -r '.[0].State.Status // "unknown", .[0].State.Health.Status // "unknown"') ) + echo "Container $container has state ${container_state[0]} and its health is ${container_state[1]}!" + if [[ "${container_state[0]}-${container_state[1]}" != "running-healthy" ]]; then + state=0 + fi + done + + if [[ $state -eq 1 ]]; then + echo "Nextcloud deployment is up and running!" + exit 0 + fi + + sleep 5 +done + +echo "Nextcloud deployment is not running correctly after $MAX_ATTEMPTS attempts!" +exit 1 diff --git a/bootc/scenario1/root/etc/systemd/system/nextcloud.target b/bootc/scenario1/root/etc/systemd/system/nextcloud.target new file mode 100644 index 0000000..3a2ba68 --- /dev/null +++ b/bootc/scenario1/root/etc/systemd/system/nextcloud.target @@ -0,0 +1,10 @@ +[Unit] +Description=Nextcloud Service Target +Documentation=man:systemd.target(5) +Wants=nextcloud-db.service nextcloud-redis.service nextcloud-fpm.service nextcloud-nginx.service +After=nextcloud-db.service nextcloud-redis.service nextcloud-fpm.service nextcloud-nginx.service +# Allow isolation - can stop/start this target independently +AllowIsolate=yes + +[Install] +WantedBy=multi-user.target diff --git a/bootc/scenario4/Containerfile b/bootc/scenario4/Containerfile new file mode 100644 index 0000000..18e4c0b --- /dev/null +++ b/bootc/scenario4/Containerfile @@ -0,0 +1,8 @@ +FROM edge-registry.itix.fr/demo-edge-retail/base:latest + +ADD --chown=root:root root / + +RUN <