Add app start script
This commit is contained in:
parent
fe19f200d7
commit
950ec6ae55
3 changed files with 96 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -2,6 +2,8 @@
|
||||||
__pycache__/
|
__pycache__/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
.ruff_cache/
|
.ruff_cache/
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
frontend/node_modules/
|
frontend/node_modules/
|
||||||
frontend/dist/
|
frontend/dist/
|
||||||
frontend/.vite/
|
frontend/.vite/
|
||||||
|
|
|
||||||
22
README.md
22
README.md
|
|
@ -19,6 +19,22 @@ python3 -m venv .venv
|
||||||
.venv/bin/python -m uvicorn app:app --reload
|
.venv/bin/python -m uvicorn app:app --reload
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Start App
|
||||||
|
|
||||||
|
Build the frontend and then serve the app from FastAPI:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./scripts/start.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The script automatically loads `.env` and `.env.local` if present.
|
||||||
|
|
||||||
|
Optional runtime overrides:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
HOST=0.0.0.0 PORT=8800 ./scripts/start.sh
|
||||||
|
```
|
||||||
|
|
||||||
Optional live Forgejo configuration:
|
Optional live Forgejo configuration:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
@ -27,6 +43,12 @@ export FORGEJO_TOKEN="your-forgejo-api-token"
|
||||||
export CALENDAR_FEED_URLS="webcal://example.com/calendar.ics,https://example.com/other.ics"
|
export CALENDAR_FEED_URLS="webcal://example.com/calendar.ics,https://example.com/other.ics"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or put those values in `.env`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
### Frontend
|
### Frontend
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
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