fix(apps): honor custom lifecycle paths

This commit is contained in:
okxlin
2026-07-22 22:37:19 +08:00
parent 058cb457b4
commit 5ff4612b79
14 changed files with 334 additions and 72 deletions
+39 -8
View File
@@ -1,13 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
paths=(
"${CONFIG_PATH:-./data/config}"
)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
mkdir -p "${paths[@]}"
for path in "${paths[@]}"; do
case "$path" in
./*|../*) chown -R 1000:1000 "$path" 2>/dev/null || true ;;
read_env_value() {
local key="$1"
[[ -f "$ENV_FILE" ]] || return 0
local value
value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
done
printf '%s\n' "$value"
}
configured_value() {
local key="$1"
local default_value="$2"
local value
value="${!key:-}"
if [[ -z "$value" ]]; then
value="$(read_env_value "$key")"
fi
printf '%s\n' "${value:-$default_value}"
}
resolve_app_path() {
local raw="$1"
if [[ "$raw" = /* ]]; then
printf '%s\n' "$raw"
else
printf '%s\n' "$ROOT_DIR/${raw#./}"
fi
}
config_path_value="$(configured_value CONFIG_PATH ./data/config)"
config_path="$(resolve_app_path "$config_path_value")"
mkdir -p -- "$config_path"
case "$config_path_value" in
./*|../*) chown -R 1000:1000 -- "$config_path" 2>/dev/null || true ;;
esac
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${ENV_FILE:-./.env}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
generate_secret() {
if [[ -r /dev/urandom ]]; then
@@ -32,8 +33,8 @@ ensure_env_default() {
current="$(sed -n -E "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
current="${current%\"}"
current="${current#\"}"
current="${current%'}"
current="${current#'}"
current="${current%\'}"
current="${current#\'}"
if [[ "$fill_empty" == "true" && -z "$current" ]]; then
sed -i -E "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
echo "Updated empty $key"
+39 -8
View File
@@ -1,13 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
paths=(
"${CONFIG_PATH:-./data/config}"
)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
mkdir -p "${paths[@]}"
for path in "${paths[@]}"; do
case "$path" in
./*|../*) chown -R 1000:1000 "$path" 2>/dev/null || true ;;
read_env_value() {
local key="$1"
[[ -f "$ENV_FILE" ]] || return 0
local value
value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
done
printf '%s\n' "$value"
}
configured_value() {
local key="$1"
local default_value="$2"
local value
value="${!key:-}"
if [[ -z "$value" ]]; then
value="$(read_env_value "$key")"
fi
printf '%s\n' "${value:-$default_value}"
}
resolve_app_path() {
local raw="$1"
if [[ "$raw" = /* ]]; then
printf '%s\n' "$raw"
else
printf '%s\n' "$ROOT_DIR/${raw#./}"
fi
}
config_path_value="$(configured_value CONFIG_PATH ./data/config)"
config_path="$(resolve_app_path "$config_path_value")"
mkdir -p -- "$config_path"
case "$config_path_value" in
./*|../*) chown -R 1000:1000 -- "$config_path" 2>/dev/null || true ;;
esac
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${ENV_FILE:-./.env}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
generate_secret() {
if [[ -r /dev/urandom ]]; then
@@ -32,8 +33,8 @@ ensure_env_default() {
current="$(sed -n -E "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
current="${current%\"}"
current="${current#\"}"
current="${current%'}"
current="${current#'}"
current="${current%\'}"
current="${current#\'}"
if [[ "$fill_empty" == "true" && -z "$current" ]]; then
sed -i -E "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
echo "Updated empty $key"
+38 -3
View File
@@ -1,8 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail
DATA_DIR="${APP_DATA_DIR:-./data}"
mkdir -p \
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
read_env_value() {
local key="$1"
[[ -f "$ENV_FILE" ]] || return 0
local value
value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
printf '%s\n' "$value"
}
configured_value() {
local key="$1"
local default_value="$2"
local value
value="${!key:-}"
if [[ -z "$value" ]]; then
value="$(read_env_value "$key")"
fi
printf '%s\n' "${value:-$default_value}"
}
resolve_app_path() {
local raw="$1"
if [[ "$raw" = /* ]]; then
printf '%s\n' "$raw"
else
printf '%s\n' "$ROOT_DIR/${raw#./}"
fi
}
DATA_DIR="$(resolve_app_path "$(configured_value APP_DATA_DIR ./data)")"
mkdir -p -- \
"${DATA_DIR}/images" \
"${DATA_DIR}/uploads" \
"${DATA_DIR}/logs" \
@@ -11,7 +46,7 @@ mkdir -p \
"${DATA_DIR}/meilisearch" \
"${DATA_DIR}/pgvector"
chown -R 1000:1000 \
chown -R 1000:1000 -- \
"${DATA_DIR}/images" \
"${DATA_DIR}/uploads" \
"${DATA_DIR}/logs" \
+38 -3
View File
@@ -1,8 +1,43 @@
#!/usr/bin/env bash
set -euo pipefail
DATA_DIR="${APP_DATA_DIR:-./data}"
mkdir -p \
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
read_env_value() {
local key="$1"
[[ -f "$ENV_FILE" ]] || return 0
local value
value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
printf '%s\n' "$value"
}
configured_value() {
local key="$1"
local default_value="$2"
local value
value="${!key:-}"
if [[ -z "$value" ]]; then
value="$(read_env_value "$key")"
fi
printf '%s\n' "${value:-$default_value}"
}
resolve_app_path() {
local raw="$1"
if [[ "$raw" = /* ]]; then
printf '%s\n' "$raw"
else
printf '%s\n' "$ROOT_DIR/${raw#./}"
fi
}
DATA_DIR="$(resolve_app_path "$(configured_value APP_DATA_DIR ./data)")"
mkdir -p -- \
"${DATA_DIR}/images" \
"${DATA_DIR}/uploads" \
"${DATA_DIR}/logs" \
@@ -11,7 +46,7 @@ mkdir -p \
"${DATA_DIR}/meilisearch" \
"${DATA_DIR}/pgvector"
chown -R 1000:1000 \
chown -R 1000:1000 -- \
"${DATA_DIR}/images" \
"${DATA_DIR}/uploads" \
"${DATA_DIR}/logs" \
+39 -8
View File
@@ -1,13 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
paths=(
"${CONFIG_PATH:-./data/config}"
)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
mkdir -p "${paths[@]}"
for path in "${paths[@]}"; do
case "$path" in
./*|../*) chown -R 1000:1000 "$path" 2>/dev/null || true ;;
read_env_value() {
local key="$1"
[[ -f "$ENV_FILE" ]] || return 0
local value
value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
done
printf '%s\n' "$value"
}
configured_value() {
local key="$1"
local default_value="$2"
local value
value="${!key:-}"
if [[ -z "$value" ]]; then
value="$(read_env_value "$key")"
fi
printf '%s\n' "${value:-$default_value}"
}
resolve_app_path() {
local raw="$1"
if [[ "$raw" = /* ]]; then
printf '%s\n' "$raw"
else
printf '%s\n' "$ROOT_DIR/${raw#./}"
fi
}
config_path_value="$(configured_value CONFIG_PATH ./data/config)"
config_path="$(resolve_app_path "$config_path_value")"
mkdir -p -- "$config_path"
case "$config_path_value" in
./*|../*) chown -R 1000:1000 -- "$config_path" 2>/dev/null || true ;;
esac
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${ENV_FILE:-./.env}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
generate_secret() {
if [[ -r /dev/urandom ]]; then
@@ -32,8 +33,8 @@ ensure_env_default() {
current="$(sed -n -E "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
current="${current%\"}"
current="${current#\"}"
current="${current%'}"
current="${current#'}"
current="${current%\'}"
current="${current#\'}"
if [[ "$fill_empty" == "true" && -z "$current" ]]; then
sed -i -E "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
echo "Updated empty $key"
@@ -1,13 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
paths=(
"${CONFIG_PATH:-./data/config}"
)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
mkdir -p "${paths[@]}"
for path in "${paths[@]}"; do
case "$path" in
./*|../*) chown -R 1000:1000 "$path" 2>/dev/null || true ;;
read_env_value() {
local key="$1"
[[ -f "$ENV_FILE" ]] || return 0
local value
value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
done
printf '%s\n' "$value"
}
configured_value() {
local key="$1"
local default_value="$2"
local value
value="${!key:-}"
if [[ -z "$value" ]]; then
value="$(read_env_value "$key")"
fi
printf '%s\n' "${value:-$default_value}"
}
resolve_app_path() {
local raw="$1"
if [[ "$raw" = /* ]]; then
printf '%s\n' "$raw"
else
printf '%s\n' "$ROOT_DIR/${raw#./}"
fi
}
config_path_value="$(configured_value CONFIG_PATH ./data/config)"
config_path="$(resolve_app_path "$config_path_value")"
mkdir -p -- "$config_path"
case "$config_path_value" in
./*|../*) chown -R 1000:1000 -- "$config_path" 2>/dev/null || true ;;
esac
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${ENV_FILE:-./.env}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
generate_secret() {
if [[ -r /dev/urandom ]]; then
@@ -32,8 +33,8 @@ ensure_env_default() {
current="$(sed -n -E "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
current="${current%\"}"
current="${current#\"}"
current="${current%'}"
current="${current#'}"
current="${current%\'}"
current="${current#\'}"
if [[ "$fill_empty" == "true" && -z "$current" ]]; then
sed -i -E "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
echo "Updated empty $key"
+39 -8
View File
@@ -1,13 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
paths=(
"${CONFIG_PATH:-./data/config}"
)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
mkdir -p "${paths[@]}"
for path in "${paths[@]}"; do
case "$path" in
./*|../*) chown -R 1000:1000 "$path" 2>/dev/null || true ;;
read_env_value() {
local key="$1"
[[ -f "$ENV_FILE" ]] || return 0
local value
value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
done
printf '%s\n' "$value"
}
configured_value() {
local key="$1"
local default_value="$2"
local value
value="${!key:-}"
if [[ -z "$value" ]]; then
value="$(read_env_value "$key")"
fi
printf '%s\n' "${value:-$default_value}"
}
resolve_app_path() {
local raw="$1"
if [[ "$raw" = /* ]]; then
printf '%s\n' "$raw"
else
printf '%s\n' "$ROOT_DIR/${raw#./}"
fi
}
config_path_value="$(configured_value CONFIG_PATH ./data/config)"
config_path="$(resolve_app_path "$config_path_value")"
mkdir -p -- "$config_path"
case "$config_path_value" in
./*|../*) chown -R 1000:1000 -- "$config_path" 2>/dev/null || true ;;
esac
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${ENV_FILE:-./.env}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
generate_secret() {
if [[ -r /dev/urandom ]]; then
@@ -32,8 +33,8 @@ ensure_env_default() {
current="$(sed -n -E "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
current="${current%\"}"
current="${current#\"}"
current="${current%'}"
current="${current#'}"
current="${current%\'}"
current="${current#\'}"
if [[ "$fill_empty" == "true" && -z "$current" ]]; then
sed -i -E "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
echo "Updated empty $key"
+39 -8
View File
@@ -1,13 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail
paths=(
"${CONFIG_PATH:-./data/config}"
)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
mkdir -p "${paths[@]}"
for path in "${paths[@]}"; do
case "$path" in
./*|../*) chown -R 1000:1000 "$path" 2>/dev/null || true ;;
read_env_value() {
local key="$1"
[[ -f "$ENV_FILE" ]] || return 0
local value
value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
done
printf '%s\n' "$value"
}
configured_value() {
local key="$1"
local default_value="$2"
local value
value="${!key:-}"
if [[ -z "$value" ]]; then
value="$(read_env_value "$key")"
fi
printf '%s\n' "${value:-$default_value}"
}
resolve_app_path() {
local raw="$1"
if [[ "$raw" = /* ]]; then
printf '%s\n' "$raw"
else
printf '%s\n' "$ROOT_DIR/${raw#./}"
fi
}
config_path_value="$(configured_value CONFIG_PATH ./data/config)"
config_path="$(resolve_app_path "$config_path_value")"
mkdir -p -- "$config_path"
case "$config_path_value" in
./*|../*) chown -R 1000:1000 -- "$config_path" 2>/dev/null || true ;;
esac
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${ENV_FILE:-./.env}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
generate_secret() {
if [[ -r /dev/urandom ]]; then
@@ -32,8 +33,8 @@ ensure_env_default() {
current="$(sed -n -E "s/^${key}=//p" "$ENV_FILE" | tail -n 1)"
current="${current%\"}"
current="${current#\"}"
current="${current%'}"
current="${current#'}"
current="${current%\'}"
current="${current#\'}"
if [[ "$fill_empty" == "true" && -z "$current" ]]; then
sed -i -E "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
echo "Updated empty $key"