mirror of
https://github.com/coder/coder.git
synced 2025-07-23 21:32:07 +00:00
chore: Add workspace proxy enterprise cli commands (#7176)
* feat: Add workspace proxy enterprise cli commands * chore: Handle custom workspace proxy options. Remove excess * chore: Add endpoint to register workspace proxies
This commit is contained in:
@ -15,8 +15,9 @@ set -euo pipefail
|
||||
|
||||
DEFAULT_PASSWORD="SomeSecurePassword!"
|
||||
password="${CODER_DEV_ADMIN_PASSWORD:-${DEFAULT_PASSWORD}}"
|
||||
use_proxy=0
|
||||
|
||||
args="$(getopt -o "" -l agpl,password: -- "$@")"
|
||||
args="$(getopt -o "" -l use-proxy,agpl,password: -- "$@")"
|
||||
eval set -- "$args"
|
||||
while true; do
|
||||
case "$1" in
|
||||
@ -28,6 +29,10 @@ while true; do
|
||||
password="$2"
|
||||
shift 2
|
||||
;;
|
||||
--use-proxy)
|
||||
use_proxy=1
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
@ -38,6 +43,10 @@ while true; do
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${CODER_BUILD_AGPL:-0}" -gt "0" ] && [ "${use_proxy}" -gt "0" ]; then
|
||||
echo '== ERROR: cannot use both external proxies and APGL build.' && exit 1
|
||||
fi
|
||||
|
||||
# Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080
|
||||
dependencies curl git go make yarn
|
||||
curl --fail http://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
|
||||
@ -168,6 +177,18 @@ fatal() {
|
||||
) || echo "Failed to create a template. The template files are in ${temp_template_dir}"
|
||||
fi
|
||||
|
||||
if [ "${use_proxy}" -gt "0" ]; then
|
||||
log "Using external workspace proxy"
|
||||
(
|
||||
# Attempt to delete the proxy first, in case it already exists.
|
||||
"${CODER_DEV_SHIM}" proxy delete local-proxy || true
|
||||
# Create the proxy
|
||||
proxy_session_token=$("${CODER_DEV_SHIM}" proxy create --name=local-proxy --display-name="Local Proxy" --icon="/emojis/1f4bb.png" --access-url=http://localhost:3010 --only-token)
|
||||
# Start the proxy
|
||||
start_cmd PROXY "" "${CODER_DEV_SHIM}" proxy server --http-address=localhost:3010 --proxy-session-token="${proxy_session_token}" --primary-access-url=http://localhost:3000
|
||||
) || echo "Failed to create workspace proxy. No workspace proxy created."
|
||||
fi
|
||||
|
||||
# Start the frontend once we have a template up and running
|
||||
CODER_HOST=http://127.0.0.1:3000 start_cmd SITE date yarn --cwd=./site dev --host
|
||||
|
||||
@ -192,6 +213,11 @@ fatal() {
|
||||
for iface in "${interfaces[@]}"; do
|
||||
log "$(printf "== Web UI: http://%s:8080%$((space_padding - ${#iface}))s==" "$iface" "")"
|
||||
done
|
||||
if [ "${use_proxy}" -gt "0" ]; then
|
||||
for iface in "${interfaces[@]}"; do
|
||||
log "$(printf "== Proxy: http://%s:3010%$((space_padding - ${#iface}))s==" "$iface" "")"
|
||||
done
|
||||
fi
|
||||
log "== =="
|
||||
log "== Use ./scripts/coder-dev.sh to talk to this instance! =="
|
||||
log "$(printf "== alias cdr=%s/scripts/coder-dev.sh%$((space_padding - ${#PWD}))s==" "$PWD" "")"
|
||||
|
Reference in New Issue
Block a user