diff --git a/README.md b/README.md index 27a5c2e..674d387 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,17 @@ Stop the local stack: ./scripts/dev-down ``` +Reset the local stack, including Docker volumes: + +```bash +./scripts/dev-down --volumes +``` + Once the stack is up: - Nextcloud: `http://localhost:8080` - aiNAS control plane: `http://localhost:3001` -The `dev-up` script waits for Nextcloud installation to finish and then enables the `ainascontrolplane` custom app inside the container. +The `dev-up` script waits for Nextcloud to report a healthy installed state, falls back to the documented `occ maintenance:install` flow if auto-install has not completed yet, and then enables the `ainascontrolplane` custom app inside the container. ## Architecture diff --git a/docker/compose.dev.yml b/docker/compose.dev.yml index 68783cc..fd21281 100644 --- a/docker/compose.dev.yml +++ b/docker/compose.dev.yml @@ -66,10 +66,10 @@ services: - "8080:80" volumes: - nextcloud-data:/var/www/html - - ../apps/ainas-controlplane:/var/www/html/custom_apps/ainascontrolplane + - nextcloud-custom-apps:/var/www/html/custom_apps volumes: nextcloud-data: + nextcloud-custom-apps: postgres-data: redis-data: - diff --git a/scripts/dev-down b/scripts/dev-down index 4a11e43..99f0a43 100755 --- a/scripts/dev-down +++ b/scripts/dev-down @@ -5,5 +5,10 @@ set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" compose_file="$repo_root/docker/compose.dev.yml" -docker compose -f "$compose_file" down --remove-orphans +args=(down --remove-orphans) +if [[ "${1:-}" == "--volumes" ]]; then + args+=(--volumes) +fi + +docker compose -f "$compose_file" "${args[@]}" diff --git a/scripts/dev-up b/scripts/dev-up index fb2f72f..cb2c714 100755 --- a/scripts/dev-up +++ b/scripts/dev-up @@ -4,13 +4,32 @@ set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" compose_file="$repo_root/docker/compose.dev.yml" +app_source_dir="$repo_root/apps/ainas-controlplane" + +nextcloud_occ() { + docker compose -f "$compose_file" exec -T --user www-data --workdir /var/www/html nextcloud php occ "$@" +} + +nextcloud_is_installed() { + nextcloud_occ status --output=json 2>/dev/null | grep -q '"installed":true' +} docker compose -f "$compose_file" up -d --build -echo "Waiting for Nextcloud to finish installing..." +docker compose -f "$compose_file" exec -T --user root nextcloud sh -lc ' + mkdir -p /var/www/html/custom_apps/ainascontrolplane + chown -R www-data:www-data /var/www/html/custom_apps +' + +docker compose -f "$compose_file" cp "$app_source_dir/." nextcloud:/var/www/html/custom_apps/ainascontrolplane +docker compose -f "$compose_file" exec -T --user root nextcloud sh -lc ' + chown -R www-data:www-data /var/www/html/custom_apps/ainascontrolplane +' + +echo "Waiting for Nextcloud command interface..." ready=0 for _ in {1..60}; do - if docker compose -f "$compose_file" exec -T --user www-data nextcloud php occ status >/dev/null 2>&1; then + if nextcloud_occ status --output=json >/dev/null 2>&1; then ready=1 break fi @@ -18,11 +37,30 @@ for _ in {1..60}; do done if [[ "$ready" -ne 1 ]]; then - echo "Nextcloud did not become ready in time." >&2 + echo "Nextcloud command interface did not become ready in time." >&2 exit 1 fi -docker compose -f "$compose_file" exec -T --user www-data nextcloud php occ app:enable --force ainascontrolplane >/dev/null +if ! nextcloud_is_installed; then + echo "Nextcloud is not installed yet. Running CLI install..." + + nextcloud_occ maintenance:install \ + --database pgsql \ + --database-name nextcloud \ + --database-host db \ + --database-user nextcloud \ + --database-pass nextcloud \ + --admin-user admin \ + --admin-pass admin \ + --data-dir /var/www/html/data + + if ! nextcloud_is_installed; then + echo "Nextcloud did not report an installed state after CLI install." >&2 + exit 1 + fi +fi + +nextcloud_occ app:enable --force ainascontrolplane >/dev/null echo "Nextcloud: http://localhost:8080" echo "aiNAS control plane: http://localhost:3001"