2022-07-01 10:09:19 +00:00
|
|
|
#!/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]}")
|
2022-07-13 09:17:40 +00:00
|
|
|
# shellcheck disable=SC1091,SC1090
|
2022-07-01 10:09:19 +00:00
|
|
|
source "${SCRIPT_DIR}/lib.sh"
|
|
|
|
|
2022-09-07 16:40:17 +00:00
|
|
|
GOOS="$(go env GOOS)"
|
|
|
|
GOARCH="$(go env GOARCH)"
|
2024-03-05 13:29:08 +00:00
|
|
|
DEBUG_DELVE="${DEBUG_DELVE:-0}"
|
2023-07-13 08:51:53 +00:00
|
|
|
BINARY_TYPE=coder-slim
|
2023-08-01 15:50:43 +00:00
|
|
|
if [[ ${1:-} == server ]]; then
|
|
|
|
BINARY_TYPE=coder
|
|
|
|
fi
|
|
|
|
if [[ ${1:-} == wsproxy ]] && [[ ${2:-} == server ]]; then
|
2023-07-13 08:51:53 +00:00
|
|
|
BINARY_TYPE=coder
|
|
|
|
fi
|
2023-10-09 13:08:24 +00:00
|
|
|
if [[ ${1:-} == exp ]] && [[ ${2:-} == scaletest ]]; then
|
|
|
|
BINARY_TYPE=coder
|
|
|
|
fi
|
2023-12-07 16:59:13 +00:00
|
|
|
if [[ ${1:-} == provisionerd ]]; then
|
|
|
|
BINARY_TYPE=coder
|
|
|
|
fi
|
2023-07-13 08:51:53 +00:00
|
|
|
RELATIVE_BINARY_PATH="build/${BINARY_TYPE}_${GOOS}_${GOARCH}"
|
2022-09-07 16:40:17 +00:00
|
|
|
|
2022-09-13 17:31:33 +00:00
|
|
|
# To preserve the CWD when running the binary, we need to use pushd and popd to
|
|
|
|
# get absolute paths to everything.
|
|
|
|
pushd "$PROJECT_ROOT"
|
2022-09-07 16:40:17 +00:00
|
|
|
mkdir -p ./.coderv2
|
2022-09-13 17:31:33 +00:00
|
|
|
CODER_DEV_BIN="$(realpath "$RELATIVE_BINARY_PATH")"
|
2022-09-07 16:40:17 +00:00
|
|
|
CODER_DEV_DIR="$(realpath ./.coderv2)"
|
2024-03-07 09:23:28 +00:00
|
|
|
CODER_DELVE_DEBUG_BIN=$(realpath "./build/coder_debug_${GOOS}_${GOARCH}")
|
2022-09-13 17:31:33 +00:00
|
|
|
popd
|
2022-07-01 10:09:19 +00:00
|
|
|
|
2023-07-13 08:51:53 +00:00
|
|
|
case $BINARY_TYPE in
|
|
|
|
coder-slim)
|
|
|
|
# Ensure the coder slim binary is always up-to-date with local
|
|
|
|
# changes, this simplifies usage of this script for development.
|
|
|
|
make -j "${RELATIVE_BINARY_PATH}"
|
|
|
|
;;
|
|
|
|
coder)
|
|
|
|
if [[ ! -x "${CODER_DEV_BIN}" ]]; then
|
|
|
|
# A feature requiring the full binary was requested and the
|
|
|
|
# binary is missing, normally it's built by `develop.sh`, but
|
|
|
|
# it's an expensive operation, so we require manual action here.
|
|
|
|
echo "Running \"coder $1\" requires the full binary, please run \"develop.sh\" first or build the binary manually:" 1>&2
|
|
|
|
echo " make $RELATIVE_BINARY_PATH" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown binary type: $BINARY_TYPE"
|
2022-07-01 10:09:19 +00:00
|
|
|
exit 1
|
2023-07-13 08:51:53 +00:00
|
|
|
;;
|
|
|
|
esac
|
2022-07-01 10:09:19 +00:00
|
|
|
|
2024-03-05 13:29:08 +00:00
|
|
|
runcmd=("${CODER_DEV_BIN}")
|
|
|
|
if [[ "${DEBUG_DELVE}" == 1 ]]; then
|
|
|
|
set -x
|
2024-03-07 09:23:28 +00:00
|
|
|
build_flags=(
|
|
|
|
--os "$GOOS"
|
|
|
|
--arch "$GOARCH"
|
|
|
|
--output "$CODER_DELVE_DEBUG_BIN"
|
|
|
|
--debug
|
|
|
|
)
|
|
|
|
if [[ "$BINARY_TYPE" == "coder-slim" ]]; then
|
|
|
|
build_flags+=(--slim)
|
|
|
|
fi
|
|
|
|
# All the prerequisites should be built above when we refreshed the regular
|
|
|
|
# binary, so we can just build the debug binary here without having to worry
|
|
|
|
# about/use the makefile.
|
|
|
|
./scripts/build_go.sh "${build_flags[@]}"
|
|
|
|
runcmd=(dlv exec --headless --continue --listen 127.0.0.1:12345 --accept-multiclient "$CODER_DELVE_DEBUG_BIN" --)
|
2024-03-05 13:29:08 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-07 09:23:28 +00:00
|
|
|
exec "${runcmd[@]}" --global-config "${CODER_DEV_DIR}" "$@"
|