chore: embed static files in debug builds (#12449)

This commit is contained in:
Dean Sheather 2024-03-07 01:23:28 -08:00 committed by GitHub
parent 3e6e1e6f10
commit bd752a6d8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 5 deletions

View File

@ -38,8 +38,9 @@ sign_darwin="${CODER_SIGN_DARWIN:-0}"
output_path=""
agpl="${CODER_BUILD_AGPL:-0}"
boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0}
debug=0
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,boringcrypto -- "$@")"
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,boringcrypto,debug -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
@ -76,6 +77,10 @@ while true; do
boringcrypto=1
shift
;;
--debug)
debug=1
shift
;;
--)
shift
break
@ -102,10 +107,12 @@ if [[ "$sign_darwin" == 1 ]]; then
fi
ldflags=(
-s
-w
-X "'github.com/coder/coder/v2/buildinfo.tag=$version'"
)
# Disable deubgger information if not building a binary for debuggers.
if [[ "$debug" == 0 ]]; then
ldflags+=(-s -w)
fi
# We use ts_omit_aws here because on Linux it prevents Tailscale from importing
# github.com/aws/aws-sdk-go-v2/aws, which adds 7 MB to the binary.
@ -122,6 +129,11 @@ if [[ "$agpl" == 1 ]]; then
fi
build_args+=(-ldflags "${ldflags[*]}")
# Disable optimizations if building a binary for debuggers.
if [[ "$debug" == 1 ]]; then
build_args+=(-gcflags "all=-N -l")
fi
# Compute default output path.
if [[ "$output_path" == "" ]]; then
mkdir -p "build"

View File

@ -32,6 +32,7 @@ pushd "$PROJECT_ROOT"
mkdir -p ./.coderv2
CODER_DEV_BIN="$(realpath "$RELATIVE_BINARY_PATH")"
CODER_DEV_DIR="$(realpath ./.coderv2)"
CODER_DELVE_DEBUG_BIN=$(realpath "./build/coder_debug_${GOOS}_${GOARCH}")
popd
case $BINARY_TYPE in
@ -59,7 +60,20 @@ esac
runcmd=("${CODER_DEV_BIN}")
if [[ "${DEBUG_DELVE}" == 1 ]]; then
set -x
runcmd=(dlv debug --headless --continue --listen 127.0.0.1:12345 --accept-multiclient ./cmd/coder --)
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" --)
fi
CGO_ENABLED=0 exec "${runcmd[@]}" --global-config "${CODER_DEV_DIR}" "$@"
exec "${runcmd[@]}" --global-config "${CODER_DEV_DIR}" "$@"