Ensure runtime derives env vars
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
"description": "Next-gen knowledge base that blends docs, whiteboards, and databases for self-hosted teams.",
|
"description": "Next-gen knowledge base that blends docs, whiteboards, and databases for self-hosted teams.",
|
||||||
"website": "https://affine.pro",
|
"website": "https://affine.pro",
|
||||||
"contactEmail": "support@affine.pro",
|
"contactEmail": "support@affine.pro",
|
||||||
"version": "0.1.4",
|
"version": "0.1.5",
|
||||||
"changelog": "Initial Cloudron packaging",
|
"changelog": "Initial Cloudron packaging",
|
||||||
"manifestVersion": 2,
|
"manifestVersion": 2,
|
||||||
"minBoxVersion": "7.0.0",
|
"minBoxVersion": "7.0.0",
|
||||||
|
|||||||
@@ -16,7 +16,91 @@ log() {
|
|||||||
printf '[%s] %s\n' "$(date --iso-8601=seconds)" "$*"
|
printf '[%s] %s\n' "$(date --iso-8601=seconds)" "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensure_database_env() {
|
||||||
|
if [ -n "${DATABASE_URL:-}" ] || [ -z "${CLOUDRON_POSTGRESQL_URL:-}" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local db_url="$CLOUDRON_POSTGRESQL_URL"
|
||||||
|
if [[ "$db_url" == postgres://* ]]; then
|
||||||
|
db_url="postgresql://${db_url#postgres://}"
|
||||||
|
fi
|
||||||
|
export DATABASE_URL="$db_url"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_redis_env() {
|
||||||
|
if [ -z "${CLOUDRON_REDIS_URL:-}" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local redis_info
|
||||||
|
redis_info=$(python3 - <<'PY'
|
||||||
|
import os
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
url = os.environ.get('CLOUDRON_REDIS_URL')
|
||||||
|
if not url:
|
||||||
|
raise SystemExit('redis url missing')
|
||||||
|
parsed = urlparse(url)
|
||||||
|
host = parsed.hostname or 'localhost'
|
||||||
|
port = parsed.port or 6379
|
||||||
|
password = parsed.password or ''
|
||||||
|
db = (parsed.path or '/0').lstrip('/') or '0'
|
||||||
|
username = parsed.username or ''
|
||||||
|
print(f"{host}\n{port}\n{password}\n{db}\n{username}")
|
||||||
|
PY
|
||||||
|
)
|
||||||
|
IFS=$'\n' read -r host port password db username <<<"$redis_info"
|
||||||
|
export REDIS_SERVER_HOST="${REDIS_SERVER_HOST:-$host}"
|
||||||
|
export REDIS_SERVER_PORT="${REDIS_SERVER_PORT:-$port}"
|
||||||
|
export REDIS_SERVER_PASSWORD="${REDIS_SERVER_PASSWORD:-$password}"
|
||||||
|
export REDIS_SERVER_DATABASE="${REDIS_SERVER_DATABASE:-$db}"
|
||||||
|
export REDIS_SERVER_USERNAME="${REDIS_SERVER_USERNAME:-$username}"
|
||||||
|
export REDIS_URL="${REDIS_URL:-$CLOUDRON_REDIS_URL}"
|
||||||
|
export REDIS_SERVER_URL="${REDIS_SERVER_URL:-$CLOUDRON_REDIS_URL}"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_mail_env() {
|
||||||
|
if [ -z "${CLOUDRON_MAIL_SMTP_SERVER:-}" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
export MAILER_HOST="${MAILER_HOST:-$CLOUDRON_MAIL_SMTP_SERVER}"
|
||||||
|
export MAILER_PORT="${MAILER_PORT:-${CLOUDRON_MAIL_SMTP_PORT:-587}}"
|
||||||
|
export MAILER_USER="${MAILER_USER:-${CLOUDRON_MAIL_SMTP_USERNAME:-}}"
|
||||||
|
export MAILER_PASSWORD="${MAILER_PASSWORD:-${CLOUDRON_MAIL_SMTP_PASSWORD:-}}"
|
||||||
|
export MAILER_SENDER="${MAILER_SENDER:-${CLOUDRON_MAIL_FROM:-AFFiNE <no-reply@cloudron.local>}}"
|
||||||
|
export MAILER_SERVERNAME="${MAILER_SERVERNAME:-AFFiNE Server}"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_server_env() {
|
||||||
|
if [ -n "${AFFINE_SERVER_EXTERNAL_URL:-}" ] || [ -z "${CLOUDRON_APP_ORIGIN:-}" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
export AFFINE_SERVER_EXTERNAL_URL="$CLOUDRON_APP_ORIGIN"
|
||||||
|
local host
|
||||||
|
host=$(python3 - <<PY
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
import os
|
||||||
|
url = os.environ.get('CLOUDRON_APP_ORIGIN', '')
|
||||||
|
parsed = urlparse(url)
|
||||||
|
print(parsed.hostname or '')
|
||||||
|
PY
|
||||||
|
)
|
||||||
|
export AFFINE_SERVER_HOST="$host"
|
||||||
|
if [[ "$CLOUDRON_APP_ORIGIN" == https://* ]]; then
|
||||||
|
export AFFINE_SERVER_HTTPS=true
|
||||||
|
else
|
||||||
|
export AFFINE_SERVER_HTTPS=false
|
||||||
|
fi
|
||||||
|
export AFFINE_INDEXER_ENABLED="${AFFINE_INDEXER_ENABLED:-false}"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_runtime_envs() {
|
||||||
|
ensure_database_env
|
||||||
|
ensure_redis_env
|
||||||
|
ensure_mail_env
|
||||||
|
ensure_server_env
|
||||||
|
}
|
||||||
|
|
||||||
log "Running AFFiNE pre-deployment migrations"
|
log "Running AFFiNE pre-deployment migrations"
|
||||||
|
ensure_runtime_envs
|
||||||
node ./scripts/self-host-predeploy.js
|
node ./scripts/self-host-predeploy.js
|
||||||
|
|
||||||
log "Starting AFFiNE server"
|
log "Starting AFFiNE server"
|
||||||
|
|||||||
Reference in New Issue
Block a user