-
Notifications
You must be signed in to change notification settings - Fork 887
fix: develop.sh: do not clobber existing login, pre-build coder binary #2750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ site/out/ | |
|
||
.vscode/*.log | ||
**/*.swp | ||
.coderv2/* | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This is a shim for developing and dogfooding Coder so that we don't | ||
# overwrite an existing session in ~/.config/coderv2 | ||
set -euo pipefail | ||
|
||
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") | ||
# shellcheck disable=SC1091 | ||
source "${SCRIPT_DIR}/lib.sh" | ||
PROJECT_ROOT=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel) | ||
|
||
CODER_DEV_DIR="$PROJECT_ROOT/.coderv2/" | ||
CODER_DEV_BIN="${CODER_DEV_DIR}/coder" | ||
if [[ ! -d "${CODER_DEV_DIR}" ]]; then | ||
mkdir -p "${CODER_DEV_DIR}" | ||
fi | ||
|
||
if [[ ! -x "${CODER_DEV_BIN}" ]]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idea: Should we try to detect outdated binaries (e.g. long running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds fun! |
||
echo "Run this command first:" | ||
echo "go build -o ${CODER_DEV_BIN} ${PROJECT_ROOT}/cmd/coder" | ||
exit 1 | ||
fi | ||
|
||
exec "${CODER_DEV_BIN}" --global-config "${CODER_DEV_DIR}" "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") | |
# shellcheck disable=SC1091 | ||
source "${SCRIPT_DIR}/lib.sh" | ||
PROJECT_ROOT=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel) | ||
CODER_DEV_BIN="${PROJECT_ROOT}/.coderv2/coder" | ||
set +u | ||
CODER_DEV_ADMIN_PASSWORD="${CODER_DEV_ADMIN_PASSWORD:-password}" | ||
set -u | ||
|
@@ -27,6 +28,11 @@ if [[ ! -e ./site/out/bin/coder.sha1 && ! -e ./site/out/bin/coder.tar.zst ]]; th | |
exit 1 | ||
fi | ||
|
||
# Compile the CLI binary once just so we don't waste time compiling things multiple times | ||
go build -o "${CODER_DEV_BIN}" "${PROJECT_ROOT}/cmd/coder" | ||
# Use the coder dev shim so we don't overwrite the user's existing Coder config. | ||
CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh" | ||
|
||
# Run yarn install, to make sure node_modules are ready to go | ||
"$PROJECT_ROOT/scripts/yarn_install.sh" | ||
|
||
|
@@ -36,33 +42,33 @@ fi | |
( | ||
# If something goes wrong, just bail and tear everything down | ||
# rather than leaving things in an inconsistent state. | ||
trap 'kill -INT -$$' ERR | ||
trap 'kill -TERM -$$' ERR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will prevent graceful shutdown of the server (e.g. resource cleanup), do we want to avoid that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should only trigger on an error and if we encounter an error then stuff hasn't even managed to start, so we should be fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, that makes sense! Ignore me. 😄 |
||
cdroot | ||
CODER_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev || kill -INT -$$ & | ||
go run -tags embed cmd/coder/main.go server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -$$ & | ||
"${CODER_DEV_SHIM}" server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -$$ & | ||
|
||
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' | ||
|
||
# create the first user, the admin | ||
go run cmd/coder/main.go login http://127.0.0.1:3000 --username=admin --email=admin@coder.com --password="${CODER_DEV_ADMIN_PASSWORD}" || | ||
"${CODER_DEV_SHIM}" 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.' | ||
|
||
# || 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}" || | ||
"${CODER_DEV_SHIM}" 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.' | ||
|
||
# If we have docker available, then let's try to create a template! | ||
template_name="" | ||
if docker info >/dev/null 2>&1; then | ||
temp_template_dir=$(mktemp -d) | ||
echo code-server | go run "${PROJECT_ROOT}/cmd/coder/main.go" templates init "${temp_template_dir}" | ||
echo code-server | "${CODER_DEV_SHIM}" templates init "${temp_template_dir}" | ||
# shellcheck disable=SC1090 | ||
source <(go env | grep GOARCH) | ||
DOCKER_HOST=$(docker context inspect --format '{{.Endpoints.docker.Host}}') | ||
printf 'docker_arch: "%s"\ndocker_host: "%s"\n' "${GOARCH}" "${DOCKER_HOST}" | tee "${temp_template_dir}/params.yaml" | ||
template_name="docker-${GOARCH}" | ||
go run "${PROJECT_ROOT}/cmd/coder/main.go" templates create "${template_name}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes | ||
"${CODER_DEV_SHIM}" templates create "${template_name}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes | ||
rm -rfv "${temp_template_dir}" | ||
fi | ||
|
||
|
@@ -75,6 +81,7 @@ fi | |
if [[ -n "${template_name}" ]]; then | ||
log "== ==" | ||
log "== Docker template ${template_name} is ready to use! ==" | ||
log "== Use ./scripts/coder-dev.sh to talk to this instance! ==" | ||
log "== ==" | ||
fi | ||
log "=======================================================================" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ storybook-static | |
test-results | ||
**/*.typegen.ts | ||
**/*.swp | ||
.coderv2/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ storybook-static/ | |
test-results/ | ||
|
||
**/*.swp | ||
.coderv2/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Should we call this
coderOSS
? That way it aligns with the name we use in the docs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just called it that because we already store stuff in
~/.config/coderv2
-- should we rename this config dir as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha! I would vote yes 👍🏼 but curious to hear what others think.
(I only bring this up because yesterday @Kira-Pilot and I had a conversation and were referring to the same thing as V2/OSS. So thinking consistency in docs & code might be a small win)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like
coderOSS
!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsjoeio is there an issue for this possible rename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I know of - just something I thought of now. Would you like me to make one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please, thanks!
It's probably eaiser to do sooner than later! Might be good to bring up in grooming next-next-week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! #2768