Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/workspaces/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Work through these in order:

## `ddev describe` shows `*.ddev.site` URLs

Those URLs only work inside the workspace. Run `ddev coder-setup` in the project and restart it; `ddev describe` and `ddev launch` then show the `coder.ddev.com` URLs. URLs for a newly added add-on show up in `ddev describe` after one more `ddev restart`.
Those URLs only work inside the workspace. Run `ddev coder-setup` in the project and restart it; `ddev start`, `ddev describe`, `ddev list` and `ddev launch` then show the `coder.ddev.com` URLs, including those of add-ons and `web_extra_exposed_ports`. `ddev coder-setup` writes them as `external_url_template` and `external_urls` in `.ddev/config.coder.yaml`. With a DDEV version older than the one that added those settings, only `ddev describe` and `ddev launch` show `coder.ddev.com` URLs, and a newly added add-on's URL appears in `ddev describe` after one more `ddev restart`.

## The site redirects to `*.ddev.site` or `http://`

Expand Down
5 changes: 5 additions & 0 deletions drupal-contrib/template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ project_tld: "$CODER_DOMAIN"
use_dns_when_possible: false
host_webserver_port: "8080"
host_mailpit_port: "8025"
# URLs that 'ddev start', 'ddev describe' and 'ddev list' show, keyed by the
# web and Mailpit ports. DDEV versions without external_urls ignore this.
external_urls:
"8080": "https://drupal-site--$${CODER_WORKSPACE_NAME}--$${CODER_WORKSPACE_OWNER_NAME}.$CODER_DOMAIN"
"8025": "https://mailpit--$${CODER_WORKSPACE_NAME}--$${CODER_WORKSPACE_OWNER_NAME}.$CODER_DOMAIN"
hooks:
post-start:
- exec-host: 'echo "" && echo " Site: https://drupal-site--$${CODER_WORKSPACE_NAME}--$${CODER_WORKSPACE_OWNER_NAME}.$CODER_DOMAIN" && echo " Mailpit: https://mailpit--$${CODER_WORKSPACE_NAME}--$${CODER_WORKSPACE_OWNER_NAME}.$CODER_DOMAIN" && echo ""'
Expand Down
5 changes: 5 additions & 0 deletions drupal-core/template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,11 @@ host_webserver_port: "80"
# Bind mailpit directly to workspace localhost (ddev-router is omitted in this template).
# Without this, mailpit is only reachable inside the DDEV web container.
host_mailpit_port: "8025"
# URLs that 'ddev start', 'ddev describe' and 'ddev list' show, keyed by the
# web and Mailpit ports. DDEV versions without external_urls ignore this.
external_urls:
"80": "https://drupal-site--$${CODER_WORKSPACE_NAME}--$${CODER_WORKSPACE_OWNER_NAME}.$CODER_DOMAIN"
"8025": "https://mailpit--$${CODER_WORKSPACE_NAME}--$${CODER_WORKSPACE_OWNER_NAME}.$CODER_DOMAIN"
# Show Coder URLs after every ddev start/restart (appended after DDEV's own message).
hooks:
post-start:
Expand Down
9 changes: 8 additions & 1 deletion image/scripts/.ddev/commands/host/coder-routes
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,14 @@ fi
# in this script for why this only covers real compose services, not
# web_extra_exposed_ports rows. DDEV_APPROOT is provided by DDEV for host commands
# (their cwd is wherever `ddev` was invoked from, not the project root).
if [ -n "${DDEV_APPROOT:-}" ] && [ -n "$WEB_URL" ]; then
# DDEV sets DDEV_PRIMARY_EXTERNAL_URL when it understands the external_urls that
# coder-setup writes, and then shows every Coder URL itself, so this file would
# only repeat them.
if [ -n "${DDEV_PRIMARY_EXTERNAL_URL:-}" ]; then
if [ -n "${DDEV_APPROOT:-}" ]; then
rm -f "${DDEV_APPROOT}/.ddev/docker-compose.coder-describe.yaml"
fi
elif [ -n "${DDEV_APPROOT:-}" ] && [ -n "$WEB_URL" ]; then
DESCRIBE_FILE="${DDEV_APPROOT}/.ddev/docker-compose.coder-describe.yaml"
{
echo "#ddev-silent-no-warn"
Expand Down
89 changes: 47 additions & 42 deletions image/scripts/.ddev/commands/host/coder-setup
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ fi
if [ -z "${VSCODE_PROXY_URI:-}" ]; then
echo "Warning: VSCODE_PROXY_URI not set — web container will not have it available"
fi

_WORKSPACE="${CODER_WORKSPACE_NAME:-}"
_OWNER="${CODER_WORKSPACE_OWNER_NAME:-}"
_AGENT="${CODER_WORKSPACE_AGENT_NAME:-${CODER_AGENT_NAME:-main}}"
_DOMAIN=""
if [ -n "${VSCODE_PROXY_URI:-}" ]; then
_DOMAIN=$(echo "$VSCODE_PROXY_URI" | sed -E 's|https?://[^.]+\.(.+?)(/.*)?$|\1|')
elif [ -n "${CODER_AGENT_URL:-}" ]; then
_DOMAIN=$(echo "$CODER_AGENT_URL" | sed -E 's|https?://(.+?)(/.*)?$|\1|')
fi
_SLUG=""
if [ -n "${DDEV_SITENAME:-}" ]; then
_SLUG=$(echo "$DDEV_SITENAME" | tr '[:upper:]' '[:lower:]' | tr '._' '--' | tr -s '-')
fi

# external_url_template/external_urls make 'ddev start', 'ddev describe',
# 'ddev list' and 'ddev launch' show Coder URLs instead of *.ddev.site. Any router
# port is reachable at Coder's port-forwarding URL, which coder-routes routes with
# PathPrefix. Router ports 8080/8025/8143 are shared by every project in the
# workspace, so they use the per-project coder_app slugs the templates define
# (and coder-routes routes by Host) instead. DDEV versions without these keys ignore them.
_EXTERNAL_URLS=""
if [ -n "$_WORKSPACE" ] && [ -n "$_OWNER" ] && [ -n "$_DOMAIN" ] && [ -n "$_SLUG" ]; then
_SUFFIX="--${_WORKSPACE}--${_OWNER}.${_DOMAIN}"
_EXTERNAL_URLS="external_url_template: \"https://{{port}}--${_AGENT}${_SUFFIX}\"
external_urls:
\"8080\": \"https://${_SLUG}${_SUFFIX}\"
\"8025\": \"https://mailpit-${_SLUG}${_SUFFIX}\"
\"8143\": \"https://xhgui-${_SLUG}${_SUFFIX}\""
fi

cat > .ddev/config.coder.yaml << EOF
#ddev-silent-no-warn
# Coder-specific DDEV hooks (auto-generated by ddev coder-setup, do not edit)
Expand All @@ -38,6 +69,7 @@ web_environment:
- CODER_WORKSPACE_NAME=${CODER_WORKSPACE_NAME:-}
- CODER_WORKSPACE_OWNER_NAME=${CODER_WORKSPACE_OWNER_NAME:-}
- VSCODE_PROXY_URI=${VSCODE_PROXY_URI:-}
${_EXTERNAL_URLS}
hooks:
post-start:
- exec-host: ddev coder-routes
Expand All @@ -46,56 +78,29 @@ hooks:
EOF
echo "✓ Wrote .ddev/config.coder.yaml"

# Write an initial docker-compose.coder-describe.yaml covering just the primary
# web service + Mailpit, so 'ddev describe' shows a working Coder URL even before
# the project has ever been started. Everything else — xhgui, adminer, or any other
# add-on/custom service that gets its own router — is handled dynamically by
# `coder-routes` (which runs on every post-start) rather than hardcoded here: it
# already discovers every real service from the merged Traefik config, computes
# each one's Coder URL for routing, and rewrites this same file with an entry per
# service it finds.
#
# Note the one-restart lag: DDEV only reads x-ddev.describe-url-port from the
# compose config it built during the *last* `ddev start`/`ddev restart`, not fresh
# on every `ddev describe` call. So a service coder-routes discovers during THIS
# start's post-start hook won't show its Coder URL in `ddev describe` until the
# NEXT start/restart — confirmed empirically: after one `ddev restart`, a newly
# discovered service's row was still missing its Coder URL; a second restart
# picked it up. This bootstrap block covers the primary web+Mailpit URLs (the only
# ones computable without a running project) so that pair is right from the very
# first start; every other service converges one restart after coder-routes first
# sees it, same as this block already required before this change.
# DDEV versions that understand external_urls show the Coder URLs above
# themselves, so the docker-compose.coder-describe.yaml fallback is removed there.
#
# Note this mechanism only applies to real docker-compose services. It cannot fix
# the separate "web_extra_exposed_ports" rows some add-ons contribute to
# 'ddev describe' (e.g. ddev-playwright's "playwright" row, a VNC add-on's
# "kasmvnc" row): cmd/ddev/cmd/describe.go's WebExtraExposedPorts stanza always
# builds that row's URL itself (https://<project-hostname>:<https_port>) and never
# consults describe-url-port. Those rows will keep showing the raw *.ddev.site URL
# — unreachable through Coder's proxy — until ddev/ddev adds support for overriding
# them; that's a separate upstream feature request against https://github.com/ddev/ddev.
_WORKSPACE="${CODER_WORKSPACE_NAME:-}"
_OWNER="${CODER_WORKSPACE_OWNER_NAME:-}"
_DOMAIN=""
if [ -n "${VSCODE_PROXY_URI:-}" ]; then
_DOMAIN=$(echo "$VSCODE_PROXY_URI" | sed -E 's|https?://[^.]+\.(.+?)(/.*)?$|\1|')
elif [ -n "${CODER_AGENT_URL:-}" ]; then
_DOMAIN=$(echo "$CODER_AGENT_URL" | sed -E 's|https?://(.+?)(/.*)?$|\1|')
fi
if [ -n "$_WORKSPACE" ] && [ -n "$_OWNER" ] && [ -n "$_DOMAIN" ] && [ -n "${DDEV_SITENAME:-}" ]; then
_SLUG=$(echo "$DDEV_SITENAME" | tr '[:upper:]' '[:lower:]' | tr '._' '--' | tr -s '-')
_WEB_URL="https://${_SLUG}--${_WORKSPACE}--${_OWNER}.${_DOMAIN}"
_MAILPIT_URL="https://mailpit-${_SLUG}--${_WORKSPACE}--${_OWNER}.${_DOMAIN}"
# Older DDEV ignores external_urls, so for those write
# docker-compose.coder-describe.yaml with x-ddev.describe-url-port for the primary
# web service and Mailpit, so 'ddev describe' shows a working Coder URL before the
# first start. coder-routes rewrites it on every post-start with an entry per
# service it routes. DDEV reads describe-url-port from the compose config built at
# the last start, so a newly discovered service shows up one restart later. It
# cannot fix web_extra_exposed_ports rows, which DDEV builds without consulting it.
if ddev describe -j 2>/dev/null | jq -e '.raw.primary_external_url // empty' >/dev/null 2>&1; then
rm -f .ddev/docker-compose.coder-describe.yaml
elif [ -n "$_EXTERNAL_URLS" ]; then
cat > .ddev/docker-compose.coder-describe.yaml << EOF
#ddev-silent-no-warn
# Auto-generated by ddev coder-setup — do not edit.
# Superseded by coder-routes after the first 'ddev start' (see comment above).
# Superseded by coder-routes after the first 'ddev start'.
services:
web:
x-ddev:
describe-url-port: |
${_WEB_URL}
Mailpit: ${_MAILPIT_URL}
https://${_SLUG}${_SUFFIX}
Mailpit: https://mailpit-${_SLUG}${_SUFFIX}
describe-info: "Use: ddev launch"
EOF
echo "✓ Wrote .ddev/docker-compose.coder-describe.yaml"
Expand Down
46 changes: 35 additions & 11 deletions image/scripts/.ddev/commands/host/launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#ddev-silent-no-warn

## Description: Show Coder URLs for this DDEV project (replaces browser-open in cloud)
## Usage: launch [path] [-m|--mailpit]
## Example: "ddev launch" or "ddev launch /admin" or "ddev launch -m"
## Usage: launch [path|:port] [-m|--mailpit]
## Example: "ddev launch" or "ddev launch /admin" or "ddev launch :8036" or "ddev launch -m"
## Flags: [{"Name":"mailpit","Shorthand":"m","Usage":"ddev launch -m shows the Mailpit URL"}]

# Parse flags/path before anything else, so both the DDEV_DEBUG branch below
# and the interactive branches further down agree on the same target.
MAILPIT=false
PATH_SUFFIX=""
PORT_ARG=""

while :; do
case ${1:-} in
Expand All @@ -23,7 +24,9 @@ while :; do
shift
done

if [ -n "${1:-}" ]; then
if [[ "${1:-}" =~ ^:[0-9]+$ ]]; then
PORT_ARG="${1#:}"
elif [ -n "${1:-}" ]; then
PATH_SUFFIX="/${1#/}"
fi

Expand All @@ -42,6 +45,8 @@ if [ "${DDEV_DEBUG:-}" = "true" ] || [ "${DDEV_VERBOSE:-}" = "true" ]; then
else
FULLURL="${FULLURL%:[0-9]*}:${DDEV_MAILPIT_PORT}"
fi
elif [ -n "${PORT_ARG}" ]; then
FULLURL="${FULLURL%:[0-9]*}:${PORT_ARG}"
else
FULLURL="${FULLURL%/}${PATH_SUFFIX}"
fi
Expand Down Expand Up @@ -78,23 +83,35 @@ fi

# DDEV_SITENAME is the DDEV project name (may differ from the Coder workspace name).
PROJECT="${DDEV_SITENAME}"
AGENT="${CODER_AGENT_NAME:-main}"
AGENT="${CODER_WORKSPACE_AGENT_NAME:-${CODER_AGENT_NAME:-main}}"

# A router port: use the external URL DDEV knows for it (from the external_urls
# that coder-setup writes), else Coder's port-forwarding URL for that port.
if [ -n "${PORT_ARG}" ]; then
url=""
if [ -n "${DDEV_PRIMARY_EXTERNAL_URL:-}" ]; then
url=$(ddev describe -j 2>/dev/null | jq -r --arg p "${PORT_ARG}" '.raw.external_urls[$p] // empty')
fi
echo "$(hyperlink "${url:-https://${PORT_ARG}--${AGENT}--${WORKSPACE}--${OWNER}.${DOMAIN}}")"
exit 0
fi

# drupal-core/drupal-contrib omit ddev-router and bind the web container directly
# to a fixed host port, so there's no Traefik merged config for coder-routes to
# read. They register fixed `coder_app` slugs (ddev-web, mailpit) instead, whose
# read. They register fixed `coder_app` slugs (drupal-site, mailpit) instead, whose
# subdomain URLs follow Coder's named-app pattern (no agent segment, since these
# templates define a single agent) — see docs/reference/coder-url-patterns.md.
ROUTER_DISABLED=$(ddev describe -j 2>/dev/null | jq -r '.raw.router_disabled // false')

if [ "$ROUTER_DISABLED" = "true" ]; then
if [ "${MAILPIT}" = "true" ]; then
echo "$(hyperlink "https://mailpit--${WORKSPACE}--${OWNER}.${DOMAIN}")"
echo "$(hyperlink "${DDEV_MAILPIT_EXTERNAL_URL:-https://mailpit--${WORKSPACE}--${OWNER}.${DOMAIN}}")"
exit 0
fi
web_url="${DDEV_PRIMARY_EXTERNAL_URL:-https://drupal-site--${WORKSPACE}--${OWNER}.${DOMAIN}}"
echo ""
echo "Coder URL for project '${PROJECT}':"
echo " Web: $(hyperlink "https://ddev-web--${WORKSPACE}--${OWNER}.${DOMAIN}${PATH_SUFFIX}")"
echo " Web: $(hyperlink "${web_url%/}${PATH_SUFFIX}")"
echo ""
exit 0
fi
Expand All @@ -111,6 +128,10 @@ PROJECT_SLUG=$(echo "$PROJECT" | tr '[:upper:]' '[:lower:]' | tr '._' '--' | tr
WEB_ROUTER="${PROJECT}-coder-${PROJECT_SLUG}"

if [ "${MAILPIT}" = "true" ]; then
if [ -n "${DDEV_MAILPIT_EXTERNAL_URL:-}" ]; then
echo "$(hyperlink "${DDEV_MAILPIT_EXTERNAL_URL}")"
exit 0
fi
if [ -f "$CODER_ROUTES" ]; then
mailpit_rule=$(yq e ".http.routers.\"${PROJECT}-coder-mailpit-${PROJECT_SLUG}\".rule // \"\"" "$CODER_ROUTES" 2>/dev/null)
if [ -n "$mailpit_rule" ] && [ "$mailpit_rule" != "null" ]; then
Expand Down Expand Up @@ -150,14 +171,17 @@ while IFS= read -r router; do
host=$(echo "$rule" | sed -E 's/Host\(`(.+)`\)/\1/')
if [ "$router" = "$WEB_ROUTER" ]; then
WEB_LINE=" Web: $(hyperlink "https://${host}${PATH_SUFFIX}")"
elif [ "$slug" = "mailpit" ]; then
elif [ "$slug" = "mailpit-${PROJECT_SLUG}" ]; then
MAILPIT_LINE=" Mailpit: $(hyperlink "https://${host}")"
else
OTHER_LINES="${OTHER_LINES} ${slug}: $(hyperlink "https://${host}")\n"
OTHER_LINES="${OTHER_LINES} ${slug%-${PROJECT_SLUG}}: $(hyperlink "https://${host}")\n"
fi
else
# PathPrefix rule — dynamic add-on, accessible via Coder port-forwarding URL
OTHER_LINES="${OTHER_LINES} ${slug}: $(hyperlink "https://${ext_port}--${AGENT}--${WORKSPACE}--${OWNER}.${DOMAIN}")\n"
# PathPrefix rule — dynamic add-on, accessible via Coder port-forwarding URL.
# slug is {service}-{container port}; extra ports on web read as web:{port}.
label="${slug%-*}"
[ "$label" = "web" ] && label="web:${slug##*-}"
OTHER_LINES="${OTHER_LINES} ${label}: $(hyperlink "https://${ext_port}--${AGENT}--${WORKSPACE}--${OWNER}.${DOMAIN}")\n"
fi
done < <(yq e '.http.routers | keys | .[]' "$CODER_ROUTES" 2>/dev/null)

Expand Down
Loading