@biffo/cli 0.250.2 → 0.250.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/pg-test-db.sh +48 -0
package/package.json
CHANGED
package/scripts/pg-test-db.sh
CHANGED
|
@@ -157,6 +157,54 @@ psql_db() { psql -q -h "$HOST" -p "$PORT" -U "$USER_" -d "$DB" "$@"; }
|
|
|
157
157
|
#
|
|
158
158
|
# Started here rather than assumed, because "docker run one yourself" is exactly
|
|
159
159
|
# the tribal knowledge this script replaces. An already-running server is reused.
|
|
160
|
+
# ── Reap abandoned sibling containers ────────────────────────────────────────
|
|
161
|
+
#
|
|
162
|
+
# The container name is keyed to the CHECKOUT (see `CONTAINER` above), which is
|
|
163
|
+
# what makes reuse work -- and also what makes them accumulate: every worktree
|
|
164
|
+
# ever created leaves one behind, running, forever. Nothing ever removed them.
|
|
165
|
+
# Measured on one workstation: 76 live `biffo-pg-test-*` containers holding
|
|
166
|
+
# ~5.4 GiB, the oldest four days old (tabsii-platform#703). That is not merely
|
|
167
|
+
# untidy -- they compete for the same page cache and I/O as the lane being
|
|
168
|
+
# timed, so a leak like this shows up as the pg gate drifting toward its own
|
|
169
|
+
# timeout, which is the failure #703 was actually filed about.
|
|
170
|
+
#
|
|
171
|
+
# Age is the only signal available. Docker records when a container was CREATED,
|
|
172
|
+
# not when it was last used, and `docker ps --filter until=` is a prune filter
|
|
173
|
+
# that this daemon rejects on `ps` -- so the comparison is done here.
|
|
174
|
+
#
|
|
175
|
+
# Reaping something still wanted is cheap and self-correcting: the next run
|
|
176
|
+
# recreates it, which this script's own header prices at ~4s against ~0.3s for
|
|
177
|
+
# reuse. Being wrong therefore costs four seconds, once. Leaving them costs a
|
|
178
|
+
# gigabyte a day.
|
|
179
|
+
#
|
|
180
|
+
# NEVER reaps this checkout's own container, is skipped entirely when the date
|
|
181
|
+
# maths is unavailable rather than guessing, and never fails the run: a
|
|
182
|
+
# housekeeping step that can break a test lane is worse than the mess it clears.
|
|
183
|
+
BIFFO_PG_REAP_HOURS="${BIFFO_PG_REAP_HOURS:-24}"
|
|
184
|
+
if [ "$BIFFO_PG_REAP_HOURS" -gt 0 ] 2>/dev/null && command -v docker >/dev/null 2>&1; then
|
|
185
|
+
# GNU first, then BSD/macOS. If neither answers, say so and skip -- a silent
|
|
186
|
+
# skip here would be the same fail-open this estate keeps finding.
|
|
187
|
+
_reap_cutoff=$(date -u -d "-${BIFFO_PG_REAP_HOURS} hours" +%Y-%m-%dT%H:%M:%S 2>/dev/null) ||
|
|
188
|
+
_reap_cutoff=$(date -u -v-"${BIFFO_PG_REAP_HOURS}"H +%Y-%m-%dT%H:%M:%S 2>/dev/null) || _reap_cutoff=""
|
|
189
|
+
if [ -z "$_reap_cutoff" ]; then
|
|
190
|
+
say "cannot compute a reap cutoff on this date(1); skipping container reaping"
|
|
191
|
+
else
|
|
192
|
+
_reaped=0
|
|
193
|
+
for _c in $(docker ps -a --filter "name=biffo-pg-test-" --format '{{.Names}}' 2>/dev/null); do
|
|
194
|
+
[ "$_c" = "$CONTAINER" ] && continue
|
|
195
|
+
_made=$(docker inspect -f '{{.Created}}' "$_c" 2>/dev/null | cut -c1-19)
|
|
196
|
+
[ -z "$_made" ] && continue
|
|
197
|
+
# Both are UTC ISO-8601 to the second, so a string compare IS a time
|
|
198
|
+
# compare -- no epoch conversion, and portable across date(1) flavours.
|
|
199
|
+
if awk -v a="$_made" -v b="$_reap_cutoff" 'BEGIN { exit !(a < b) }'; then
|
|
200
|
+
docker rm -f "$_c" >/dev/null 2>&1 && _reaped=$((_reaped + 1))
|
|
201
|
+
fi
|
|
202
|
+
done
|
|
203
|
+
[ "$_reaped" -gt 0 ] &&
|
|
204
|
+
say "reaped $_reaped container(s) unused for over ${BIFFO_PG_REAP_HOURS}h (set BIFFO_PG_REAP_HOURS=0 to disable)"
|
|
205
|
+
fi
|
|
206
|
+
fi
|
|
207
|
+
|
|
160
208
|
if ! psql_admin -c 'SELECT 1' >/dev/null 2>&1; then
|
|
161
209
|
if ! command -v docker >/dev/null 2>&1; then
|
|
162
210
|
say "no Postgres at $HOST:$PORT and docker is not installed."
|