-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-start
More file actions
executable file
·88 lines (76 loc) · 3.18 KB
/
Copy pathdocker-start
File metadata and controls
executable file
·88 lines (76 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
set -euo pipefail
repo_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
config_file="$repo_dir/config.json"
runtime_dir="$repo_dir/.runtime"
action=${1:-}
usage() {
echo "Usage: ./docker-start {up|visual|down|stop|start|restart|ps|logs|build|config} [ARGS...]"
}
if [[ ! -f "$config_file" ]]; then
echo "Missing $config_file; copy config.example.json to config.json and edit it." >&2
exit 2
fi
case "$action" in
up|visual|down|stop|start|restart|ps|logs|build|config) ;;
help|--help|-h|"") usage; exit 0 ;;
*) usage >&2; exit 2 ;;
esac
mkdir -p "$runtime_dir"
chmod 700 "$runtime_dir"
visual=configured
[[ "$action" == "up" ]] && visual=false
[[ "$action" == "visual" ]] && visual=true
eval "$(python3 - "$config_file" "$runtime_dir/config.docker.json" "$repo_dir" "$visual" <<'PY'
import json
from pathlib import Path
import shlex
import sys
source, destination, repo = Path(sys.argv[1]), Path(sys.argv[2]), Path(sys.argv[3])
visual_arg = sys.argv[4].lower()
config = json.loads(source.read_text(encoding="utf-8"))
visual = (config.get("visualization", {}).get("enabled", True)
if visual_arg == "configured" else visual_arg == "true")
paths = config.setdefault("paths", {})
processing = config.setdefault("processing", {})
def host_path(value, default):
path = Path(value or default).expanduser()
return path if path.is_absolute() else (repo / path).resolve()
stream = host_path(processing.get("enriched_stream_path"), "../urban-observation-processing/processing-output/observations.jsonl")
runtime = host_path(paths.get("runtime_root"), "./runtime")
results = host_path(paths.get("results_root"), "./results")
cache = host_path(paths.get("observation_cache_root"), "./cache").parent
for folder in (stream.parent, runtime, results, cache):
folder.mkdir(parents=True, exist_ok=True)
processing["enriched_stream_path"] = f"/streams/{stream.name}"
processing["enrichment_url"] = "http://enrichment:8770"
processing.pop("input_state_path", None)
paths.update({
"runtime_root": "/runtime", "results_root": "/results",
"observation_cache_root": "/cache/by_incident",
"real_observation_cache_root": "/cache/real_data",
})
config["visualization"] = {"enabled": visual, "url": "http://visualization:8000"}
destination.write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
destination.chmod(0o600)
values = {
"INCIDENTLENS_UID": str(repo.stat().st_uid),
"INCIDENTLENS_GID": str(repo.stat().st_gid),
"INCIDENTLENS_STREAM_FOLDER": str(stream.parent),
"INCIDENTLENS_RUNTIME_FOLDER": str(runtime),
"INCIDENTLENS_RESULTS_FOLDER": str(results),
"INCIDENTLENS_CACHE_FOLDER": str(cache),
"INCIDENTLENS_VISUALIZATION_PORT": str(config.get("visualization_port", 8000)),
}
for key, value in values.items():
print(f"export {key}={shlex.quote(value)}")
PY
)"
compose=(docker compose --project-directory "$repo_dir" -f "$repo_dir/compose.yaml")
shift
case "$action" in
up) exec "${compose[@]}" up -d --build pipeline "$@" ;;
visual) exec "${compose[@]}" --profile visualization up -d --build visualization pipeline "$@" ;;
config) exec "${compose[@]}" config --quiet ;;
*) exec "${compose[@]}" --profile visualization "$action" "$@" ;;
esac