forked from mtusi2026/mtusi2026lab7
59 lines
1.6 KiB
Bash
Executable File
59 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
repo_dir=$(CDPATH= cd -- "$script_dir/.." && pwd)
|
|
env_file=${1:-$repo_dir/lab7.env.example}
|
|
|
|
if [ ! -f "$env_file" ]; then
|
|
echo "environment file not found: $env_file" >&2
|
|
exit 2
|
|
fi
|
|
|
|
compose() {
|
|
docker compose --project-directory "$repo_dir" --env-file "$env_file" "$@"
|
|
}
|
|
|
|
if [ ! -f "$repo_dir/.runtime/security/openbao/tls.crt" ]; then
|
|
"$repo_dir/infra/pki/bootstrap.sh"
|
|
fi
|
|
|
|
"$script_dir/openbao-seed.sh" "$env_file"
|
|
compose up -d security-bootstrap openbao-permissions openbao
|
|
if [ -z "${BAO_ADDR:-}" ]; then
|
|
openbao_address=$(compose port openbao 8200)
|
|
BAO_ADDR="https://$openbao_address"
|
|
fi
|
|
BAO_CACERT="$repo_dir/.runtime/security/openbao/ca.crt"
|
|
export BAO_ADDR BAO_CACERT ENV_FILE="$env_file"
|
|
|
|
remaining=60
|
|
until curl --silent --show-error --cacert "$BAO_CACERT" \
|
|
--output /dev/null "$BAO_ADDR/v1/sys/health"; do
|
|
remaining=$((remaining - 1))
|
|
[ "$remaining" -gt 0 ] || {
|
|
echo "OpenBao did not start" >&2
|
|
exit 1
|
|
}
|
|
sleep 1
|
|
done
|
|
|
|
ENV_FILE="$env_file" "$script_dir/openbao-init.sh"
|
|
ENV_FILE="$env_file" "$script_dir/openbao-unseal.sh"
|
|
remaining=60
|
|
until curl --fail --silent --show-error --cacert "$BAO_CACERT" \
|
|
--output /dev/null "$BAO_ADDR/v1/sys/health"; do
|
|
remaining=$((remaining - 1))
|
|
[ "$remaining" -gt 0 ] || {
|
|
echo "OpenBao did not become active after unseal" >&2
|
|
exit 1
|
|
}
|
|
sleep 1
|
|
done
|
|
ENV_FILE="$env_file" "$script_dir/openbao-bootstrap.sh" \
|
|
"$repo_dir/.runtime/openbao/seed/api.json" \
|
|
"$repo_dir/.runtime/openbao/seed/worker.json"
|
|
|
|
compose up -d --build --scale api=2 --wait --wait-timeout 240
|