2022-01-18 21:13:19 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-06-22 13:02:31 +00:00
|
|
|
# Allow toggling verbose output
|
|
|
|
[[ -n ${VERBOSE:-""} ]] && set -x
|
2022-01-18 21:13:19 +00:00
|
|
|
set -euo pipefail
|
|
|
|
|
2022-05-27 17:15:19 +00:00
|
|
|
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
|
2022-06-22 13:02:31 +00:00
|
|
|
# shellcheck disable=SC1091
|
|
|
|
source "${SCRIPT_DIR}/lib.sh"
|
2022-05-27 17:15:19 +00:00
|
|
|
PROJECT_ROOT=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
|
2022-06-22 13:02:31 +00:00
|
|
|
set +u
|
|
|
|
CODER_DEV_ADMIN_PASSWORD="${CODER_DEV_ADMIN_PASSWORD:-password}"
|
|
|
|
set -u
|
|
|
|
|
|
|
|
# Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080
|
2022-06-22 18:04:12 +00:00
|
|
|
dependencies curl git go make yarn
|
|
|
|
curl --fail http://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
|
|
|
|
curl --fail http://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
|
2022-01-18 21:13:19 +00:00
|
|
|
|
2022-06-23 14:16:27 +00:00
|
|
|
if [[ ! -e ./site/out/bin/coder.sha1 && ! -e ./site/out/bin/coder.tar.zst ]]; then
|
|
|
|
log
|
|
|
|
log "======================================================================="
|
|
|
|
log "== Run 'make bin' before running this command to build binaries. =="
|
|
|
|
log "== Without these binaries, workspaces will fail to start! =="
|
|
|
|
log "======================================================================="
|
|
|
|
log
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-05-12 17:37:51 +00:00
|
|
|
|
2022-02-09 21:46:46 +00:00
|
|
|
# Run yarn install, to make sure node_modules are ready to go
|
2022-02-20 17:42:50 +00:00
|
|
|
"$PROJECT_ROOT/scripts/yarn_install.sh"
|
2022-02-09 21:46:46 +00:00
|
|
|
|
2022-01-18 21:13:19 +00:00
|
|
|
# This is a way to run multiple processes in parallel, and have Ctrl-C work correctly
|
|
|
|
# to kill both at the same time. For more details, see:
|
|
|
|
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
|
2022-02-02 02:02:59 +00:00
|
|
|
(
|
2022-06-22 13:02:31 +00:00
|
|
|
SCRIPT_PID=$$
|
2022-06-23 14:16:27 +00:00
|
|
|
cdroot
|
2022-06-22 13:02:31 +00:00
|
|
|
CODERV2_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev || kill -INT -${SCRIPT_PID} &
|
|
|
|
go run -tags embed cmd/coder/main.go server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -${SCRIPT_PID} &
|
2022-05-27 17:15:19 +00:00
|
|
|
|
2022-06-22 13:02:31 +00:00
|
|
|
echo '== Waiting for Coder to become ready'
|
|
|
|
timeout 60s bash -c 'until curl -s --fail http://localhost:3000 > /dev/null 2>&1; do sleep 0.5; done'
|
2022-06-15 21:02:18 +00:00
|
|
|
|
|
|
|
# create the first user, the admin
|
2022-06-22 13:02:31 +00:00
|
|
|
go run cmd/coder/main.go login http://127.0.0.1:3000 --username=admin --email=admin@coder.com --password="${CODER_DEV_ADMIN_PASSWORD}" ||
|
|
|
|
echo 'Failed to create admin user. To troubleshoot, try running this command manually.'
|
2022-06-15 21:02:18 +00:00
|
|
|
|
2022-06-22 13:02:31 +00:00
|
|
|
# || true to always exit code 0. If this fails, whelp.
|
|
|
|
go run cmd/coder/main.go users create --email=member@coder.com --username=member --password="${CODER_DEV_ADMIN_PASSWORD}" ||
|
|
|
|
echo 'Failed to create regular user. To troubleshoot, try running this command manually.'
|
2022-05-27 17:15:19 +00:00
|
|
|
wait
|
2022-02-02 02:02:59 +00:00
|
|
|
)
|