Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/local-pkgsite/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Local Go Pkgsite",
"id": "local-pkgsite",
"version": "0.1.4",
"version": "0.1.5",
"description": "A local Go pkgsite serving the module documentation, with automatic browser refresh.",
"options": {
"port": {
Expand Down
33 changes: 28 additions & 5 deletions src/local-pkgsite/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,47 @@ INT_PORT=$(comm -23 <(seq $(cat /proc/sys/net/ipv4/ip_local_port_range | tr ' '
<(netstat -ntl | awk '/LISTEN/ {split($4,a,":"); print a[2]}' | sort -u) 2>/dev/null \
| shuf | head -n 1)

wait_for_process_logfile() {
local name=\$1
local file=\$2
local now=\$(date +%s)
local end=\$((now + 5))
while true; do
if [ -s "\${file}" ]; then
echo "...\${name} started"
break
fi
now=\$(date +%s)
if [ "\${now}" -ge "\${end}" ]; then
echo "ERROR: \${name} did not start"
break
fi
sleep 0.25
done
}

# Start browser-sync in the background to proxy from the local pkgsite on a
# random/ephemeral HTTP port that the determined above to the "public" port
# where browser want to connect to.
nohup bash -c "\
BROWSYNC_LOGFILE=/tmp/nohup-local-pkgsite-browser-sync.log
setsid --fork bash -c "\
browser-sync start \
--port ${PORT} \
--proxy localhost:\${INT_PORT} \
--reload-delay ${RELOAD_DELAY} \
--reload-debounce ${RELOAD_DEBOUNCE} \
--no-ui \
--no-open \
" >/tmp/nohup-local-pkgsite-browser-sync.log 2>&1 &
>\${BROWSYNC_LOGFILE} 2>&1"
wait_for_process_logfile "browser-sync" \${BROWSYNC_LOGFILE}

# Monitor for any *.go or (heaven forbid) our go.mod to change, then first
# terminate the already running local pkgsite and restart it; as before, serve
# the local pkgsite on a random/ephemeral HTTP port that the determined above.
# Then trigger a reload in connected browsers. Please note that we run nodemon
# and it will then run "browser-sync reload" on demand, as well as ).
nohup bash -c "\
# and it will then run "browser-sync reload" on demand, as well as pkgsite).
NODEM_LOGFILE=/tmp/nohup-local-pkgsite-nodemon.log
setsid --fork bash -c "\
nodemon \
--signal SIGTERM \
--watch './**/*' \
Expand All @@ -182,7 +204,8 @@ nohup bash -c "\
browser-sync --port ${PORT} reload \
&& ${PKGSITE_BIN} -http=localhost:\${INT_PORT} .
\" \
&" >/tmp/nohup-local-pkgsite-nodemon.log 2>&1
>\${NODEM_LOGFILE} 2>&1"
wait_for_process_logfile "nodemon" \${NODEM_LOGFILE}
EOF
chmod 0755 "${PKGSITE_SERVE_PATH}"

Expand Down
8 changes: 5 additions & 3 deletions test/local-pkgsite/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"image": "ghcr.io/almalinux/almalinux:9",
"features": {
"local-pkgsite": {}
}
},
"postCreateCommand": "yum install -y procps"
},
"debian": {
"image": "mcr.microsoft.com/devcontainers/base:debian-12",
Expand All @@ -25,6 +26,7 @@
"image": "fedora",
"features": {
"local-pkgsite": {}
}
},
"postCreateCommand": "yum install -y procps"
}
}
}
5 changes: 5 additions & 0 deletions test/local-pkgsite/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ cat /tmp/nohup-local-pkgsite-browser-sync.log
check "nodemon nohup log exists" bash -c "[ -f /tmp/nohup-local-pkgsite-nodemon.log ]"
cat /tmp/nohup-local-pkgsite-nodemon.log

echo
ps -o pid,comm,command --forest -e
check "browser-sync process still exists" bash -c "ps -o pid,command --forest -e | grep -v grep | grep -E '/browser-sync start --port'"
check "nodemon process still exists" bash -c "ps -o pid,command --forest -e | grep -v grep | grep -E '/nodemon --signal SIGTERM'"

CMD=$(cat <<EOF
curl --output /dev/null \
--retry-connrefused --retry-delay 1 --retry 5 \
Expand Down