-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclean-env.sh
More file actions
executable file
·112 lines (94 loc) · 5.15 KB
/
Copy pathclean-env.sh
File metadata and controls
executable file
·112 lines (94 loc) · 5.15 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ── Logging ──────────────────────────────────────────────────────────────────
log() {
echo -e "\033[0;32m[$(date '+%H:%M:%S')] $1\033[0m"
}
# ── Parse arguments ──────────────────────────────────────────────────────────
CLEAN_BUILD=false
PRUNE_IMAGES=false
while [[ $# -gt 0 ]]; do
case "$1" in
--build)
CLEAN_BUILD=true
shift
;;
--prune)
PRUNE_IMAGES=true
shift
;;
*)
log "Unknown argument: $1"
exit 1
;;
esac
done
# ── Load environment ─────────────────────────────────────────────────────────
source "$SCRIPT_DIR/lib/env.sh"
load_env "$SCRIPT_DIR"
# ── Resolve nigiri binary ────────────────────────────────────────────────────
if [[ -n "${NIGIRI_BRANCH:-}" ]]; then
NIGIRI="$SCRIPT_DIR/_build/nigiri/build/nigiri"
elif command -v nigiri &>/dev/null; then
NIGIRI="nigiri"
else
NIGIRI="$SCRIPT_DIR/_build/nigiri/build/nigiri"
fi
# ── Export vars for docker-compose interpolation ─────────────────────────────
export ARKD_IMAGE ARKD_WALLET_IMAGE ARK_CONTAINER
export BOLTZ_LND_IMAGE FULMINE_IMAGE BOLTZ_IMAGE NGINX_IMAGE
export BOLTZ_LND_P2P_PORT BOLTZ_LND_RPC_PORT FULMINE_GRPC_PORT FULMINE_API_PORT FULMINE_HTTP_PORT
export BOLTZ_GRPC_PORT BOLTZ_API_PORT BOLTZ_WS_PORT NGINX_PORT
export LNURL_IMAGE WALLET_IMAGE LNURL_PORT WALLET_PORT
export DELEGATOR_GRPC_PORT DELEGATOR_API_PORT DELEGATOR_HTTP_PORT
export EMULATOR_IMAGE EMULATOR_PORT EMULATOR_SECRET_KEY EMULATOR_ARKD_URL EMULATOR_LOG_LEVEL
# ── Stop emulator overlay if it was started ──────────────────────────────────
if docker ps -a --format '{{.Names}}' | grep -q '^emulator$'; then
log "Removing emulator overlay..."
docker compose -f "$SCRIPT_DIR/docker/docker-compose.emulator.yml" down --volumes --remove-orphans 2>/dev/null || true
fi
# ── Stop arkd override if custom image was used ──────────────────────────────
if docker ps -a --format '{{.Names}}' | grep -qE "^(ark|arkd|${ARK_CONTAINER})$" && \
[ -n "$(docker inspect "${ARK_CONTAINER}" --format '{{.Config.Image}}' 2>/dev/null | grep -v 'nigiri')" ]; then
log "Stopping custom arkd override containers..."
docker compose -f "$SCRIPT_DIR/docker/docker-compose.arkd-override.yml" down --volumes --remove-orphans 2>/dev/null || true
fi
# ── Stop ark overlay stack ───────────────────────────────────────────────────
log "Stopping ark overlay stack..."
docker compose -f "$SCRIPT_DIR/docker/docker-compose.ark.yml" down --volumes --remove-orphans || true
# ── Stop nigiri ──────────────────────────────────────────────────────────────
NIGIRI_DATA="${HOME}/.nigiri"
# Normalize volume ownership first. nigiri stop --delete runs its rm as the
# current user, but container workloads (e.g. postgres) write files as root or
# as an in-container UID, so those files can't be removed without sudo. Chown
# via a throwaway root container so nigiri's own cleanup succeeds cleanly.
if [ -d "$NIGIRI_DATA/volumes" ]; then
docker run --rm -v "$NIGIRI_DATA/volumes:/vol" alpine \
chown -R "$(id -u):$(id -g)" /vol 2>/dev/null || true
fi
log "Stopping nigiri..."
$NIGIRI stop --delete || true
# Belt-and-braces: if nigiri's delete still left anything behind, wipe it via
# a root container.
if [ -d "$NIGIRI_DATA/volumes" ]; then
log "Removing nigiri volumes..."
docker run --rm -v "$NIGIRI_DATA/volumes:/vol" alpine sh -c 'rm -rf /vol/* /vol/.[!.]*' 2>/dev/null || true
rm -rf "$NIGIRI_DATA/volumes" 2>/dev/null || true
fi
# Remove compose file and config so nigiri regenerates them from its template
# on next start. Prevents stale compose files (e.g. system vs dev nigiri mismatch).
rm -f "$NIGIRI_DATA/docker-compose.yml" "$NIGIRI_DATA/nigiri.config.json" 2>/dev/null || true
# ── Optionally remove _build/ ────────────────────────────────────────────────
if [[ "$CLEAN_BUILD" = true ]]; then
log "Removing _build/ directory..."
rm -rf "$SCRIPT_DIR/_build"
fi
# Remove any dangling images that may have been left behind by build scripts
if [[ "$PRUNE_IMAGES" = true ]]; then
log "Removing dangling Docker images..."
docker image prune -f
log "Removing dangling Docker volumes..."
docker volume prune -f
fi
log "Clean-up complete."