Skip to content

Commit 51e7e5c

Browse files
committed
improve develop.sh
1 parent 7f77831 commit 51e7e5c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

scripts/develop.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ set -x
55

66
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
77
PROJECT_ROOT=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
8+
set +u
9+
CODER_DEV_ADMIN_PASSWORD="${CODER_DEV_ADMIN_PASSWORD:-password}"
10+
set -u
11+
12+
# Preflight check: make sure nothing is listening on port 3000 or 8080
13+
nc -z 127.0.0.1 3000 && echo '== ERROR: something is listening on port 3000. Kill it and re-run this script.' && exit 1
14+
nc -z 127.0.0.1 8080 && echo '== ERROR: something is listening on port 8080. Kill it and re-run this script.' && exit 1
815

916
echo '== Run "make build" before running this command to build binaries.'
1017
echo '== Without these binaries, workspaces will fail to start!'
@@ -17,18 +24,19 @@ echo '== Without these binaries, workspaces will fail to start!'
1724
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
1825
(
1926
cd "${PROJECT_ROOT}"
20-
21-
trap 'kill 0' SIGINT
27+
# Send an interrupt signal to all processes in this subshell on exit
2228
CODERV2_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev &
2329
go run -tags embed cmd/coder/main.go server --in-memory --tunnel &
2430

25-
# Just a minor sleep to ensure the first user was created to make the member.
26-
sleep 2
31+
echo '== Waiting for Coder to become ready'
32+
timeout 60s bash -c 'until nc -z 127.0.0.1 3000 > /dev/null 2>&1; do sleep 1; done'
2733

2834
# create the first user, the admin
29-
go run cmd/coder/main.go login http://127.0.0.1:3000 --username=admin --email=admin@coder.com --password=password || true
35+
go run cmd/coder/main.go login http://127.0.0.1:3000 --username=admin --email=admin@coder.com --password=password \
36+
|| echo 'Failed to create admin user. To troubleshoot, try running this command manually.'
3037

31-
# || yes to always exit code 0. If this fails, whelp.
32-
go run cmd/coder/main.go users create --email=member@coder.com --username=member --password="${CODER_DEV_ADMIN_PASSWORD}" || true
38+
# || true to always exit code 0. If this fails, whelp.
39+
go run cmd/coder/main.go users create --email=member@coder.com --username=member --password="${CODER_DEV_ADMIN_PASSWORD}" \
40+
|| echo 'Failed to create regular user. To troubleshoot, try running this command manually.'
3341
wait
3442
)

0 commit comments

Comments
 (0)