Skip to content

Commit 1256ec4

Browse files
committed
fix: Misc improvements to scripts/develop.sh
* Use new `/healthz` endpoint for checking API liveness * Improved credential handling/retrying in failure scenarios * Separate site (`vite`) logs with prefix and date, additionally this method also disables the `vite` clearing of the screen * Show all interfaces coder API is listening on (due to `0.0.0.0`)
1 parent d64c73d commit 1256ec4

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

scripts/develop.sh

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Coder enterprise features).
77

88
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
9-
# shellcheck disable=SC1091,SC1090
9+
# shellcheck source=scripts/lib.sh
1010
source "${SCRIPT_DIR}/lib.sh"
1111

1212
# Allow toggling verbose output
@@ -62,18 +62,24 @@ CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh"
6262
"${CODER_DEV_SHIM}" server --address 0.0.0.0:3000 || kill -INT -$$ &
6363

6464
echo '== Waiting for Coder to become ready'
65-
timeout 60s bash -c 'until curl -s --fail http://localhost:3000 > /dev/null 2>&1; do sleep 0.5; done'
65+
timeout 60s bash -c 'until curl -s --fail http://localhost:3000/healthz > /dev/null 2>&1; do sleep 0.5; done'
66+
67+
# Check if credentials are already set up to avoid setting up again.
68+
"${CODER_DEV_SHIM}" list >/dev/null 2>&1 && touch "${PROJECT_ROOT}/.coderv2/developsh-did-first-setup"
6669

6770
if [ ! -f "${PROJECT_ROOT}/.coderv2/developsh-did-first-setup" ]; then
6871
# Try to create the initial admin user.
69-
"${CODER_DEV_SHIM}" login http://127.0.0.1:3000 --first-user-username=admin --first-user-email=admin@coder.com --first-user-password="${password}" ||
72+
if "${CODER_DEV_SHIM}" login http://127.0.0.1:3000 --first-user-username=admin --first-user-email=admin@coder.com --first-user-password="${password}"; then
73+
# Only create this file if an admin user was successfully
74+
# created, otherwise we won't retry on a later attempt.
75+
touch "${PROJECT_ROOT}/.coderv2/developsh-did-first-setup"
76+
else
7077
echo 'Failed to create admin user. To troubleshoot, try running this command manually.'
78+
fi
7179

7280
# Try to create a regular user.
73-
"${CODER_DEV_SHIM}" users create --email=member@coder.com --username=member --password="${password}" ||
74-
echo 'Failed to create regular user. To troubleshoot, try running this command manually.'
75-
76-
touch "${PROJECT_ROOT}/.coderv2/developsh-did-first-setup"
81+
"${CODER_DEV_SHIM}" users create --email=member@coder.com --username=member --password="${password}" \
82+
|| echo 'Failed to create regular user. To troubleshoot, try running this command manually.'
7783
fi
7884

7985
# If we have docker available and the "docker" template doesn't already
@@ -97,18 +103,35 @@ CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh"
97103
fi
98104

99105
# Start the frontend once we have a template up and running
100-
CODER_HOST=http://127.0.0.1:3000 yarn --cwd=./site dev || kill -INT -$$ &
101-
102-
log
103-
log "===================================================================="
104-
log "== =="
105-
log "== Coder is now running in development mode. =="
106-
log "== API: http://localhost:3000 =="
107-
log "== Web UI: http://localhost:8080 =="
108-
log "== =="
109-
log "== Use ./scripts/coder-dev.sh to talk to this instance! =="
110-
log "===================================================================="
111-
log
106+
CODER_HOST=http://127.0.0.1:3000 yarn --cwd=./site dev | {
107+
while read -r line; do
108+
echo "[SITE] $(date -Iseconds): $line"
109+
done
110+
} || kill -INT -$$ &
111+
112+
interfaces=(localhost)
113+
if which ip >/dev/null 2>&1; then
114+
# shellcheck disable=SC2207
115+
interfaces+=($(ip a | awk '/inet / {print $2}' | cut -d/ -f1))
116+
elif which ifconfig >/dev/null 2>&1; then
117+
# shellcheck disable=SC2207
118+
interfaces+=($(ifconfig | awk '/inet / {print $2}'))
119+
fi
120+
121+
log
122+
log "===================================================================="
123+
log "== =="
124+
log "== Coder is now running in development mode. =="
125+
for iface in "${interfaces[@]}"; do
126+
log "$(printf "== API: http://%s:3000%$((26 - ${#iface}))s==" "$iface" "")"
127+
done
128+
for iface in "${interfaces[@]}"; do
129+
log "$(printf "== Web UI: http://%s:3000%$((26 - ${#iface}))s==" "$iface" "")"
130+
done
131+
log "== =="
132+
log "== Use ./scripts/coder-dev.sh to talk to this instance! =="
133+
log "===================================================================="
134+
log
112135

113136
# Wait for both frontend and backend to exit.
114137
wait

0 commit comments

Comments
 (0)