Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e149534

Browse files
authored
fix: develop.sh: do not clobber existing login, pre-build coder binary for speed (coder#2750)
1 parent 482feef commit e149534

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ site/out/
4040

4141
.vscode/*.log
4242
**/*.swp
43+
.coderv2/*

scripts/coder-dev.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# This is a shim for developing and dogfooding Coder so that we don't
4+
# overwrite an existing session in ~/.config/coderv2
5+
set -euo pipefail
6+
7+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
8+
# shellcheck disable=SC1091
9+
source "${SCRIPT_DIR}/lib.sh"
10+
PROJECT_ROOT=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
11+
12+
CODER_DEV_DIR="$PROJECT_ROOT/.coderv2/"
13+
CODER_DEV_BIN="${CODER_DEV_DIR}/coder"
14+
if [[ ! -d "${CODER_DEV_DIR}" ]]; then
15+
mkdir -p "${CODER_DEV_DIR}"
16+
fi
17+
18+
if [[ ! -x "${CODER_DEV_BIN}" ]]; then
19+
echo "Run this command first:"
20+
echo "go build -o ${CODER_DEV_BIN} ${PROJECT_ROOT}/cmd/coder"
21+
exit 1
22+
fi
23+
24+
exec "${CODER_DEV_BIN}" --global-config "${CODER_DEV_DIR}" "$@"

scripts/develop.sh

+13-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
88
# shellcheck disable=SC1091
99
source "${SCRIPT_DIR}/lib.sh"
1010
PROJECT_ROOT=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
11+
CODER_DEV_BIN="${PROJECT_ROOT}/.coderv2/coder"
1112
set +u
1213
CODER_DEV_ADMIN_PASSWORD="${CODER_DEV_ADMIN_PASSWORD:-password}"
1314
set -u
@@ -27,6 +28,11 @@ if [[ ! -e ./site/out/bin/coder.sha1 && ! -e ./site/out/bin/coder.tar.zst ]]; th
2728
exit 1
2829
fi
2930

31+
# Compile the CLI binary once just so we don't waste time compiling things multiple times
32+
go build -o "${CODER_DEV_BIN}" "${PROJECT_ROOT}/cmd/coder"
33+
# Use the coder dev shim so we don't overwrite the user's existing Coder config.
34+
CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh"
35+
3036
# Run yarn install, to make sure node_modules are ready to go
3137
"$PROJECT_ROOT/scripts/yarn_install.sh"
3238

@@ -36,33 +42,33 @@ fi
3642
(
3743
# If something goes wrong, just bail and tear everything down
3844
# rather than leaving things in an inconsistent state.
39-
trap 'kill -INT -$$' ERR
45+
trap 'kill -TERM -$$' ERR
4046
cdroot
4147
CODER_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev || kill -INT -$$ &
42-
go run -tags embed cmd/coder/main.go server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -$$ &
48+
"${CODER_DEV_SHIM}" server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -$$ &
4349

4450
echo '== Waiting for Coder to become ready'
4551
timeout 60s bash -c 'until curl -s --fail http://localhost:3000 > /dev/null 2>&1; do sleep 0.5; done'
4652

4753
# create the first user, the admin
48-
go run cmd/coder/main.go login http://127.0.0.1:3000 --username=admin [email protected] --password="${CODER_DEV_ADMIN_PASSWORD}" ||
54+
"${CODER_DEV_SHIM}" login http://127.0.0.1:3000 --username=admin [email protected] --password="${CODER_DEV_ADMIN_PASSWORD}" ||
4955
echo 'Failed to create admin user. To troubleshoot, try running this command manually.'
5056

5157
# || true to always exit code 0. If this fails, whelp.
52-
go run cmd/coder/main.go users create [email protected] --username=member --password="${CODER_DEV_ADMIN_PASSWORD}" ||
58+
"${CODER_DEV_SHIM}" users create [email protected] --username=member --password="${CODER_DEV_ADMIN_PASSWORD}" ||
5359
echo 'Failed to create regular user. To troubleshoot, try running this command manually.'
5460

5561
# If we have docker available, then let's try to create a template!
5662
template_name=""
5763
if docker info >/dev/null 2>&1; then
5864
temp_template_dir=$(mktemp -d)
59-
echo code-server | go run "${PROJECT_ROOT}/cmd/coder/main.go" templates init "${temp_template_dir}"
65+
echo code-server | "${CODER_DEV_SHIM}" templates init "${temp_template_dir}"
6066
# shellcheck disable=SC1090
6167
source <(go env | grep GOARCH)
6268
DOCKER_HOST=$(docker context inspect --format '{{.Endpoints.docker.Host}}')
6369
printf 'docker_arch: "%s"\ndocker_host: "%s"\n' "${GOARCH}" "${DOCKER_HOST}" | tee "${temp_template_dir}/params.yaml"
6470
template_name="docker-${GOARCH}"
65-
go run "${PROJECT_ROOT}/cmd/coder/main.go" templates create "${template_name}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes
71+
"${CODER_DEV_SHIM}" templates create "${template_name}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes
6672
rm -rfv "${temp_template_dir}"
6773
fi
6874

@@ -75,6 +81,7 @@ fi
7581
if [[ -n "${template_name}" ]]; then
7682
log "== =="
7783
log "== Docker template ${template_name} is ready to use! =="
84+
log "== Use ./scripts/coder-dev.sh to talk to this instance! =="
7885
log "== =="
7986
fi
8087
log "======================================================================="

site/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ storybook-static
1111
test-results
1212
**/*.typegen.ts
1313
**/*.swp
14+
.coderv2/*

site/.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ storybook-static/
1919
test-results/
2020

2121
**/*.swp
22+
.coderv2/*

0 commit comments

Comments
 (0)