Skip to content

Commit 9d4591c

Browse files
committed
feat: Allow workspace proxy spawn in develop.sh
1 parent 9c37e16 commit 9d4591c

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

cli/server.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
163163
var (
164164
cfg = new(codersdk.DeploymentValues)
165165
opts = cfg.Options()
166+
// For the develop.sh script, it is helpful to make this key deterministic.
167+
devAppSecurityKey string
168+
)
169+
opts.Add(
170+
clibase.Option{
171+
Name: "App Security Key (Development Only)",
172+
Description: "Used to override the app security key stored in the database. This should never be used in production.",
173+
Flag: "dangerous-dev-app-security-key",
174+
Default: "",
175+
Value: clibase.StringOf(&devAppSecurityKey),
176+
Annotations: clibase.Annotations{}.Mark("secret", "true"),
177+
Hidden: true,
178+
},
166179
)
167180
serverCmd := &clibase.Cmd{
168181
Use: "server",
@@ -621,6 +634,17 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
621634
}
622635
}
623636

637+
if devAppSecurityKey != "" {
638+
_, err := workspaceapps.KeyFromString(devAppSecurityKey)
639+
if err != nil {
640+
return xerrors.Errorf("invalid dev app security key: %w", err)
641+
}
642+
err = tx.UpsertAppSecurityKey(ctx, devAppSecurityKey)
643+
if err != nil {
644+
return xerrors.Errorf("Insert dev app security key: %w", err)
645+
}
646+
}
647+
624648
// Read the app signing key from the DB. We store it hex encoded
625649
// since the config table uses strings for the value and we
626650
// don't want to deal with automatic encoding issues.

enterprise/cli/workspaceproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (r *RootCmd) deleteProxy() *clibase.Cmd {
6969
return xerrors.Errorf("delete workspace proxy %q: %w", inv.Args[0], err)
7070
}
7171

72-
_, _ = fmt.Fprintln(inv.Stdout, "Workspace proxy %q deleted successfully", inv.Args[0])
72+
_, _ = fmt.Fprintf(inv.Stdout, "Workspace proxy %q deleted successfully\n", inv.Args[0])
7373
return nil
7474
},
7575
}

scripts/develop.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ set -euo pipefail
1616
DEFAULT_PASSWORD="SomeSecurePassword!"
1717
password="${CODER_DEV_ADMIN_PASSWORD:-${DEFAULT_PASSWORD}}"
1818
use_proxy=0
19+
# Hard coded app security key for the proxy to also use.
20+
app_security_key=bea458bcfb31990fb70f14a7003c0aad4f371f19653f3a632bc9d3492004cd95e0e542c30e5f158f26728373190bfc802b1c1549f52c149af8ad7f5b12ea1ee0995b95de3b86ae78f021c17437649224cd2dcf1b298d180811cf36f4dcb8f33e
1921

2022
args="$(getopt -o "" -l use-proxy,agpl,password: -- "$@")"
2123
eval set -- "$args"
@@ -131,7 +133,7 @@ fatal() {
131133
trap 'fatal "Script encountered an error"' ERR
132134

133135
cdroot
134-
start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "http://127.0.0.1:3000" --experiments "*" "$@"
136+
start_cmd API "" "${CODER_DEV_SHIM}" server --http-address 0.0.0.0:3000 --swagger-enable --access-url "http://127.0.0.1:3000" --dangerous-dev-app-security-key ${app_security_key} --experiments "*" "$@"
135137

136138
echo '== Waiting for Coder to become ready'
137139
# Start the timeout in the background so interrupting this script
@@ -178,10 +180,15 @@ fatal() {
178180
fi
179181

180182
if [ "${use_proxy}" -gt "0" ]; then
181-
# Create the proxy
182-
"${CODER_DEV_SHIM}" proxy register --name=local-proxy --display-name="Local Proxy" --icon="/emojis/1f4bb.png" --access-url=http://localhost:3010 --only-token
183-
# Start the proxy
184-
start_cmd PROXY proxy "" "${CODER_DEV_SHIM}" proxy --listen-addr
183+
log "Using external workspace proxy"
184+
(
185+
# Attempt to delete the proxy first, in case it already exists.
186+
"${CODER_DEV_SHIM}" proxy delete name=local-proxy
187+
# Create the proxy
188+
proxy_session_token=$("${CODER_DEV_SHIM}" proxy register --name=local-proxy --display-name="Local Proxy" --icon="/emojis/1f4bb.png" --access-url=http://localhost:3010 --only-token)
189+
# Start the proxy
190+
start_cmd PROXY "" "${CODER_DEV_SHIM}" proxy server --http-address=localhost:3010 --proxy-session-token=${proxy_session_token} --primary-access-url=http://localhost:3000 --app-security-key=${app_security_key}
191+
) || echo "Failed to create workspace proxy. No workspace proxy created."
185192
fi
186193

187194
# Start the frontend once we have a template up and running
@@ -208,6 +215,11 @@ fatal() {
208215
for iface in "${interfaces[@]}"; do
209216
log "$(printf "== Web UI: http://%s:8080%$((space_padding - ${#iface}))s==" "$iface" "")"
210217
done
218+
if [ "${use_proxy}" -gt "0" ]; then
219+
for iface in "${interfaces[@]}"; do
220+
log "$(printf "== Proxy: http://%s:3010%$((space_padding - ${#iface}))s==" "$iface" "")"
221+
done
222+
fi
211223
log "== =="
212224
log "== Use ./scripts/coder-dev.sh to talk to this instance! =="
213225
log "$(printf "== alias cdr=%s/scripts/coder-dev.sh%$((space_padding - ${#PWD}))s==" "$PWD" "")"

0 commit comments

Comments
 (0)