Add app start script
This commit is contained in:
parent
fe19f200d7
commit
950ec6ae55
3 changed files with 96 additions and 0 deletions
72
scripts/start.sh
Executable file
72
scripts/start.sh
Executable file
|
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
frontend_dir="${root_dir}/frontend"
|
||||
|
||||
load_env_file() {
|
||||
local env_file="$1"
|
||||
[[ -f "${env_file}" ]] || return 0
|
||||
|
||||
while IFS= read -r line || [[ -n "${line}" ]]; do
|
||||
line="${line#"${line%%[![:space:]]*}"}"
|
||||
line="${line%"${line##*[![:space:]]}"}"
|
||||
[[ -z "${line}" || "${line}" == \#* ]] && continue
|
||||
|
||||
local key="${line%%=*}"
|
||||
local value="${line#*=}"
|
||||
key="${key%"${key##*[![:space:]]}"}"
|
||||
key="${key#export }"
|
||||
value="${value#"${value%%[![:space:]]*}"}"
|
||||
value="${value%"${value##*[![:space:]]}"}"
|
||||
if [[ "${value}" == \"*\" && "${value}" == *\" ]]; then
|
||||
value="${value:1:-1}"
|
||||
elif [[ "${value}" == \'*\' && "${value}" == *\' ]]; then
|
||||
value="${value:1:-1}"
|
||||
fi
|
||||
|
||||
if [[ -z "${!key+x}" ]]; then
|
||||
export "${key}=${value}"
|
||||
fi
|
||||
done < "${env_file}"
|
||||
}
|
||||
|
||||
load_env_file "${root_dir}/.env"
|
||||
load_env_file "${root_dir}/.env.local"
|
||||
|
||||
if [[ -x "${root_dir}/.venv/bin/python" ]]; then
|
||||
python_cmd="${root_dir}/.venv/bin/python"
|
||||
else
|
||||
python_cmd="${PYTHON_BIN:-python3}"
|
||||
fi
|
||||
|
||||
if [[ -n "${BUN_BIN:-}" ]]; then
|
||||
bun_cmd="${BUN_BIN}"
|
||||
elif [[ -x "${HOME}/.bun/bin/bun" ]]; then
|
||||
bun_cmd="${HOME}/.bun/bin/bun"
|
||||
else
|
||||
bun_cmd="bun"
|
||||
fi
|
||||
|
||||
host="${HOST:-0.0.0.0}"
|
||||
port="${PORT:-8000}"
|
||||
|
||||
if ! command -v "${python_cmd}" >/dev/null 2>&1; then
|
||||
echo "Python runtime not found: ${python_cmd}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v "${bun_cmd}" >/dev/null 2>&1; then
|
||||
echo "Bun runtime not found: ${bun_cmd}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "==> Building frontend"
|
||||
(
|
||||
cd "${frontend_dir}"
|
||||
"${bun_cmd}" run build
|
||||
)
|
||||
|
||||
echo "==> Starting backend on ${host}:${port}"
|
||||
cd "${root_dir}"
|
||||
exec "${python_cmd}" -m uvicorn app:app --host "${host}" --port "${port}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue