Skip to content

Commit 7f31127

Browse files
committed
Merge branch 'chore/local-pkgsite' into develop
2 parents c1d2458 + 34b2c99 commit 7f31127

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

src/local-pkgsite/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Local Go Pkgsite",
33
"id": "local-pkgsite",
4-
"version": "0.1.4",
4+
"version": "0.1.5",
55
"description": "A local Go pkgsite serving the module documentation, with automatic browser refresh.",
66
"options": {
77
"port": {

src/local-pkgsite/install.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,25 +154,47 @@ INT_PORT=$(comm -23 <(seq $(cat /proc/sys/net/ipv4/ip_local_port_range | tr ' '
154154
<(netstat -ntl | awk '/LISTEN/ {split($4,a,":"); print a[2]}' | sort -u) 2>/dev/null \
155155
| shuf | head -n 1)
156156
157+
wait_for_process_logfile() {
158+
local name=\$1
159+
local file=\$2
160+
local now=\$(date +%s)
161+
local end=\$((now + 5))
162+
while true; do
163+
if [ -s "\${file}" ]; then
164+
echo "...\${name} started"
165+
break
166+
fi
167+
now=\$(date +%s)
168+
if [ "\${now}" -ge "\${end}" ]; then
169+
echo "ERROR: \${name} did not start"
170+
break
171+
fi
172+
sleep 0.25
173+
done
174+
}
175+
157176
# Start browser-sync in the background to proxy from the local pkgsite on a
158177
# random/ephemeral HTTP port that the determined above to the "public" port
159178
# where browser want to connect to.
160-
nohup bash -c "\
179+
BROWSYNC_LOGFILE=/tmp/nohup-local-pkgsite-browser-sync.log
180+
setsid --fork bash -c "\
161181
browser-sync start \
162182
--port ${PORT} \
163183
--proxy localhost:\${INT_PORT} \
164184
--reload-delay ${RELOAD_DELAY} \
165185
--reload-debounce ${RELOAD_DEBOUNCE} \
166186
--no-ui \
167187
--no-open \
168-
" >/tmp/nohup-local-pkgsite-browser-sync.log 2>&1 &
188+
>\${BROWSYNC_LOGFILE} 2>&1"
189+
wait_for_process_logfile "browser-sync" \${BROWSYNC_LOGFILE}
169190
170191
# Monitor for any *.go or (heaven forbid) our go.mod to change, then first
171192
# terminate the already running local pkgsite and restart it; as before, serve
172193
# the local pkgsite on a random/ephemeral HTTP port that the determined above.
173194
# Then trigger a reload in connected browsers. Please note that we run nodemon
174-
# and it will then run "browser-sync reload" on demand, as well as ).
175-
nohup bash -c "\
195+
# and it will then run "browser-sync reload" on demand, as well as pkgsite).
196+
NODEM_LOGFILE=/tmp/nohup-local-pkgsite-nodemon.log
197+
setsid --fork bash -c "\
176198
nodemon \
177199
--signal SIGTERM \
178200
--watch './**/*' \
@@ -182,7 +204,8 @@ nohup bash -c "\
182204
browser-sync --port ${PORT} reload \
183205
&& ${PKGSITE_BIN} -http=localhost:\${INT_PORT} .
184206
\" \
185-
&" >/tmp/nohup-local-pkgsite-nodemon.log 2>&1
207+
>\${NODEM_LOGFILE} 2>&1"
208+
wait_for_process_logfile "nodemon" \${NODEM_LOGFILE}
186209
EOF
187210
chmod 0755 "${PKGSITE_SERVE_PATH}"
188211

test/local-pkgsite/scenarios.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"image": "ghcr.io/almalinux/almalinux:9",
1212
"features": {
1313
"local-pkgsite": {}
14-
}
14+
},
15+
"postCreateCommand": "yum install -y procps"
1516
},
1617
"debian": {
1718
"image": "mcr.microsoft.com/devcontainers/base:debian-12",
@@ -25,6 +26,7 @@
2526
"image": "fedora",
2627
"features": {
2728
"local-pkgsite": {}
28-
}
29+
},
30+
"postCreateCommand": "yum install -y procps"
2931
}
30-
}
32+
}

test/local-pkgsite/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ cat /tmp/nohup-local-pkgsite-browser-sync.log
1515
check "nodemon nohup log exists" bash -c "[ -f /tmp/nohup-local-pkgsite-nodemon.log ]"
1616
cat /tmp/nohup-local-pkgsite-nodemon.log
1717

18+
echo
19+
ps -o pid,comm,command --forest -e
20+
check "browser-sync process still exists" bash -c "ps -o pid,command --forest -e | grep -v grep | grep -E '/browser-sync start --port'"
21+
check "nodemon process still exists" bash -c "ps -o pid,command --forest -e | grep -v grep | grep -E '/nodemon --signal SIGTERM'"
22+
1823
CMD=$(cat <<EOF
1924
curl --output /dev/null \
2025
--retry-connrefused --retry-delay 1 --retry 5 \

0 commit comments

Comments
 (0)