47 lines
938 B
Bash
47 lines
938 B
Bash
#!/usr/bin/env bash
|
||
set -Eeuo pipefail
|
||
|
||
ubuntu_dir() {
|
||
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd
|
||
}
|
||
repo_root() {
|
||
cd -- "$(ubuntu_dir)/../.." && pwd
|
||
}
|
||
|
||
compose_file() {
|
||
printf '%s/compose.yaml\n' "$(ubuntu_dir)"
|
||
}
|
||
|
||
require_command() {
|
||
command -v "$1" >/dev/null 2>&1 || {
|
||
printf '缺少命令:%s\n' "$1" >&2
|
||
exit 1
|
||
}
|
||
}
|
||
|
||
require_env_file() {
|
||
local file="$1"
|
||
[[ -f "$file" ]] || {
|
||
printf '环境文件不存在:%s\n' "$file" >&2
|
||
exit 1
|
||
}
|
||
local mode
|
||
mode="$(stat -c '%a' "$file")"
|
||
if [[ "$mode" != '600' && "$mode" != '400' ]]; then
|
||
printf '环境文件权限必须是 600 或 400,当前为 %s:%s\n' "$mode" "$file" >&2
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
env_value() {
|
||
local file="$1"
|
||
local key="$2"
|
||
sed -n "s/^${key}=//p" "$file" | tail -n 1
|
||
}
|
||
|
||
compose() {
|
||
local env_file="$1"
|
||
shift
|
||
docker compose --project-directory "$(ubuntu_dir)" --env-file "$env_file" -f "$(compose_file)" "$@"
|
||
}
|