Skip to content

Commit dc7d6de

Browse files
authored
improve develop.sh (#2572)
- Running make dev now prompts you to run ./scripts/develop.sh manually, as GNU make does not appear to pass SIGINT to subprocesses. - Added checks to develop.sh to ensure that coderd is listening before running our initial setup steps - Add some more troubleshooting/debugging output to develop.sh
1 parent 7f77831 commit dc7d6de

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ coderd/database/dump.sql: $(wildcard coderd/database/migrations/*.sql)
6060
coderd/database/querier.go: coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
6161
coderd/database/generate.sh
6262

63+
# This target is deprecated, as GNU make has issues passing signals to subprocesses.
6364
dev:
64-
./scripts/develop.sh
65+
@echo Please run ./scripts/develop.sh manually.
6566
.PHONY: dev
6667

6768
fmt/prettier:

scripts/develop.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#!/usr/bin/env bash
22

3+
# Allow toggling verbose output
4+
[[ -n ${VERBOSE:-""} ]] && set -x
35
set -euo pipefail
4-
set -x
56

67
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
8+
# shellcheck disable=SC1091
9+
source "${SCRIPT_DIR}/lib.sh"
710
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
819

920
echo '== Run "make build" before running this command to build binaries.'
1021
echo '== Without these binaries, workspaces will fail to start!'
@@ -16,19 +27,20 @@ echo '== Without these binaries, workspaces will fail to start!'
1627
# to kill both at the same time. For more details, see:
1728
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
1829
(
30+
SCRIPT_PID=$$
1931
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} &
2034

21-
trap 'kill 0' SIGINT
22-
CODERV2_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 2
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'
2737

2838
# 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.'
3041

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
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.'
3345
wait
3446
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy