Add initial configuration files and scripts for NextCloud setup

This commit is contained in:
2026-02-25 00:48:52 +03:30
parent 1fc3f4bcf1
commit a85136ba06
7 changed files with 244 additions and 0 deletions

29
.env.example Normal file
View File

@@ -0,0 +1,29 @@
# ===== Core image =====
AIO_IMAGE=nextcloud/all-in-one:latest
# ===== Nextcloud AIO =====
# Public HTTPS endpoint for Nextcloud served by AIO's Apache
AIO_APACHE_PORT=8443
# Bind 8080 only to loopback so the AIO management API is not exposed publicly
AIO_INTERFACE_BIND=127.0.0.1
AIO_DOCKER_API_PROXY_PORT=8080
AIO_NC_APACHE_PORT=11000
AIO_NC_APACHE_BINDING=127.0.0.1
AIO_NETWORK_NAME=nextcloud-aio
AIO_MASTERCONFIG_VOLUME=nextcloud_aio_mastercontainer
# Data paths (must exist on host)
NEXTCLOUD_DATADIR=/srv/nextcloud/data
NEXTCLOUD_MOUNT=/srv/nextcloud
# Runtime limits
NEXTCLOUD_MEMORY_LIMIT=1024M
NEXTCLOUD_UPLOAD_LIMIT=10G
# Set to true only for local/lab setups where public domain checks are not possible.
SKIP_DOMAIN_VALIDATION=true
TALK_PORT=3478
# ===== Local reverse proxy (Caddy) =====
NEXTCLOUD_DOMAIN=nextcloud.test
CADDY_TLS=internal

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
.env
.logs/com.nextcloud.collabora.retrust.err.log
.gitignore
.logs/com.nextcloud.collabora.retrust.out.log

25
Caddyfile Normal file
View File

@@ -0,0 +1,25 @@
nextcloud.test {
tls internal
encode zstd gzip
reverse_proxy nextcloud-aio-apache:11000
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "no-referrer"
-Server
}
}
nextcloud.localhost {
tls internal
encode zstd gzip
reverse_proxy nextcloud-aio-apache:11000
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "no-referrer"
-Server
}
}

63
compose.yaml Normal file
View File

@@ -0,0 +1,63 @@
name: nextcloud-aio-collabora
services:
caddy:
image: caddy:2-alpine
container_name: caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
edge:
aliases:
- nextcloud.test
- nextcloud.localhost
nextcloud-aio-mastercontainer:
image: ${AIO_IMAGE}
container_name: nextcloud-aio-mastercontainer
restart: unless-stopped
init: true
ports:
- "${AIO_APACHE_PORT}:8443"
- "${AIO_INTERFACE_BIND}:${AIO_DOCKER_API_PROXY_PORT}:8080"
environment:
APACHE_PORT: ${AIO_NC_APACHE_PORT}
APACHE_IP_BINDING: ${AIO_NC_APACHE_BINDING}
APACHE_ADDITIONAL_NETWORK: ${AIO_NETWORK_NAME}
NEXTCLOUD_DATADIR: ${NEXTCLOUD_DATADIR}
NEXTCLOUD_MOUNT: ${NEXTCLOUD_MOUNT}
NEXTCLOUD_MEMORY_LIMIT: ${NEXTCLOUD_MEMORY_LIMIT}
NEXTCLOUD_UPLOAD_LIMIT: ${NEXTCLOUD_UPLOAD_LIMIT}
SKIP_DOMAIN_VALIDATION: "${SKIP_DOMAIN_VALIDATION}"
TALK_PORT: ${TALK_PORT}
WATCHTOWER_DOCKER_SOCKET_PATH: /var/run/docker.sock
volumes:
- nextcloud_aio_mastercontainer:/mnt/docker-aio-config
- /var/run/docker.sock:/var/run/docker.sock
- ${NEXTCLOUD_MOUNT}:/mnt/nc-data:ro
networks:
- edge
healthcheck:
test: ["CMD", "curl", "-kfsS", "https://127.0.0.1:8080/setup"]
interval: 30s
timeout: 5s
retries: 10
start_period: 30s
security_opt:
- no-new-privileges:true
networks:
edge:
name: ${AIO_NETWORK_NAME}
volumes:
nextcloud_aio_mastercontainer:
name: ${AIO_MASTERCONFIG_VOLUME}
caddy_data:
caddy_config:

View File

@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -euo pipefail
LABEL="com.nextcloud.collabora.retrust"
PLIST_DIR="$HOME/Library/LaunchAgents"
PLIST_PATH="$PLIST_DIR/$LABEL.plist"
WORKDIR="$(cd "$(dirname "$0")/.." && pwd)"
SCRIPT_PATH="$WORKDIR/scripts/retrust-collabora-caddy-ca.sh"
LOG_DIR="$WORKDIR/.logs"
STDOUT_LOG="$LOG_DIR/$LABEL.out.log"
STDERR_LOG="$LOG_DIR/$LABEL.err.log"
mkdir -p "$PLIST_DIR" "$LOG_DIR"
cat > "$PLIST_PATH" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>$LABEL</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>$SCRIPT_PATH</string>
</array>
<key>WorkingDirectory</key>
<string>$WORKDIR</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>300</integer>
<key>StandardOutPath</key>
<string>$STDOUT_LOG</string>
<key>StandardErrorPath</key>
<string>$STDERR_LOG</string>
</dict>
</plist>
PLIST
launchctl bootout "gui/$(id -u)/$LABEL" >/dev/null 2>&1 || true
if launchctl bootstrap "gui/$(id -u)" "$PLIST_PATH" >/dev/null 2>&1; then
launchctl enable "gui/$(id -u)/$LABEL" >/dev/null 2>&1 || true
launchctl kickstart -k "gui/$(id -u)/$LABEL" >/dev/null 2>&1 || true
MODE="bootstrap"
else
launchctl unload "$PLIST_PATH" >/dev/null 2>&1 || true
launchctl load -w "$PLIST_PATH"
MODE="load"
fi
echo "Installed launchd job: $LABEL (mode: $MODE)"
echo "Plist: $PLIST_PATH"
echo "Logs: $STDOUT_LOG and $STDERR_LOG"

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
CADDY_CONTAINER="caddy"
COLLABORA_CONTAINER="nextcloud-aio-collabora"
TARGET_CERT_PATH="/usr/local/share/ca-certificates/caddy-local.crt"
TARGET_BUNDLE="/etc/ssl/certs/ca-certificates.crt"
MARKER_BEGIN="# CADDY_LOCAL_CA_BEGIN"
MARKER_END="# CADDY_LOCAL_CA_END"
if ! command -v docker >/dev/null 2>&1; then
echo "docker is required but not found" >&2
exit 1
fi
if ! docker ps --format '{{.Names}}' | grep -qx "$CADDY_CONTAINER"; then
echo "container '$CADDY_CONTAINER' is not running" >&2
exit 1
fi
if ! docker ps --format '{{.Names}}' | grep -qx "$COLLABORA_CONTAINER"; then
echo "container '$COLLABORA_CONTAINER' is not running" >&2
exit 1
fi
tmp_cert="$(mktemp)"
trap 'rm -f "$tmp_cert"' EXIT
docker exec "$CADDY_CONTAINER" sh -lc 'cat /data/caddy/pki/authorities/local/root.crt' > "$tmp_cert"
docker cp "$tmp_cert" "$COLLABORA_CONTAINER:$TARGET_CERT_PATH" >/dev/null
docker exec --user root "$COLLABORA_CONTAINER" sh -lc "
if ! grep -Fq '$MARKER_BEGIN' '$TARGET_BUNDLE'; then
{
echo
echo '$MARKER_BEGIN'
cat '$TARGET_CERT_PATH'
echo '$MARKER_END'
} >> '$TARGET_BUNDLE'
fi
"
docker exec "$COLLABORA_CONTAINER" sh -lc "curl -fsS --connect-timeout 5 --max-time 15 https://nextcloud.test/status.php >/dev/null"
echo "Collabora now trusts Caddy local CA for https://nextcloud.test"

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
LABEL="com.nextcloud.collabora.retrust"
PLIST_PATH="$HOME/Library/LaunchAgents/$LABEL.plist"
launchctl bootout "gui/$(id -u)/$LABEL" >/dev/null 2>&1 || true
rm -f "$PLIST_PATH"
echo "Uninstalled launchd job: $LABEL"