1
1
#! /usr/bin/env bash
2
2
3
+ # Allow toggling verbose output
4
+ [[ -n ${VERBOSE:- " " } ]] && set -x
3
5
set -euo pipefail
4
- set -x
5
6
6
7
SCRIPT_DIR=$( dirname " ${BASH_SOURCE[0]} " )
8
+ # shellcheck disable=SC1091
9
+ source " ${SCRIPT_DIR} /lib.sh"
7
10
PROJECT_ROOT=$( cd " $SCRIPT_DIR " && git rev-parse --show-toplevel)
11
+ set +u
12
+ CODER_DEV_ADMIN_PASSWORD=" ${CODER_DEV_ADMIN_PASSWORD:- password} "
13
+ set -u
14
+
15
+ # Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080
16
+ dependencies curl git go make nc yarn
17
+ nc -z 127.0.0.1 3000 > /dev/null 2>&1 && echo ' == ERROR: something is listening on port 3000. Kill it and re-run this script.' && exit 1
18
+ nc -z 127.0.0.1 8080 > /dev/null 2>&1 && echo ' == ERROR: something is listening on port 8080. Kill it and re-run this script.' && exit 1
8
19
9
20
echo ' == Run "make build" before running this command to build binaries.'
10
21
echo ' == Without these binaries, workspaces will fail to start!'
@@ -16,19 +27,20 @@ echo '== Without these binaries, workspaces will fail to start!'
16
27
# to kill both at the same time. For more details, see:
17
28
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
18
29
(
30
+ SCRIPT_PID=$$
19
31
cd " ${PROJECT_ROOT} "
32
+ CODERV2_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev || kill -INT -${SCRIPT_PID} &
33
+ go run -tags embed cmd/coder/main.go server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -${SCRIPT_PID} &
20
34
21
- trap ' kill 0' SIGINT
22
- CODER_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev &
23
- go run -tags embed cmd/coder/main.go server --in-memory --tunnel &
24
-
25
- # Just a minor sleep to ensure the first user was created to make the member.
26
- sleep 5
35
+ echo ' == Waiting for Coder to become ready'
36
+ timeout 60s bash -c ' until curl -s --fail http://localhost:3000 > /dev/null 2>&1; do sleep 0.5; done'
27
37
28
38
# 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
39
+ go run cmd/coder/main.go login http://127.0.0.1:3000 --username=admin --email=admin@coder.com --password=" ${CODER_DEV_ADMIN_PASSWORD} " ||
40
+ echo ' Failed to create admin user. To troubleshoot, try running this command manually.'
30
41
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=password || true
42
+ # || true to always exit code 0. If this fails, whelp.
43
+ go run cmd/coder/main.go users create --email=member@coder.com --username=member --password=" ${CODER_DEV_ADMIN_PASSWORD} " ||
44
+ echo ' Failed to create regular user. To troubleshoot, try running this command manually.'
33
45
wait
34
46
)
0 commit comments