Skip to content
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ serves the worktree and `https://acme.ddev.site` goes on serving the parent.
service's `VIRTUAL_HOST` into the mkcert SAN list too — verified on v1.25.2
with no hostshift config file on disk. Everything not named there keeps going
to `web`, so the canonical site stays reachable alongside the variant.
- **Mailpit.** `https://wt-a--acme.ddev.site:8026` is the worktree's own
Mailpit, so a test that reads mail from its base URL works on a variant. The
variants route to the proxy on 80 and 443 only, so `init` writes
`.ddev/traefik/config/hostshift-mailpit.yaml`, which DDEV merges into the
project's router config and which sends the Mailpit ports to `web`. The proxy
is not involved. After updating the add-on, run `ddev hostshift init` once (a
worktree's pre-start hook does it on the next start).
- **Multiple hostnames.** A multisite needs nothing extra. If the parent
declares `additional_hostnames`, `init` derives a variant for each one.
- **Keeping the two projects apart.** `HOSTSHIFT_WEB_HOSTS` narrows `web` back
Expand Down
43 changes: 42 additions & 1 deletion ddev/commands/host/hostshift
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ hostshift: listening on"*) logs_has_banner=1 ;;
stale=""
for f in .ddev/traefik/config/*.yaml; do
[ -f "$f" ] || continue
case "$(basename "$f" .yaml)" in "$name") ;; *) stale="${stale:+$stale }$f" ;; esac
case "$(basename "$f" .yaml)" in "$name"|hostshift-mailpit) ;; *) stale="${stale:+$stale }$f" ;; esac
done
if [ -n "$stale" ]; then
echo " This project carries router config for a name it no longer has:" >&2
Expand Down Expand Up @@ -3097,6 +3097,47 @@ cp -p .ddev/.env "$tmp"
mv "$tmp" .ddev/.env

echo "hostshift: wrote .ddev/.env" >&2

# Mailpit on the variants. They are on the hostshift service's VIRTUAL_HOST,
# which exposes 80 and 443 only, so `<variant>:8026` matched no router and
# answered 404. DDEV merges every other .yaml in .ddev/traefik/config/ into the
# project's router config, so two routers send those ports to web's Mailpit,
# Host unchanged.
#
# The service is DDEV's own, not a URL of ours: where DDEV chooses not to route
# Mailpit (hardened images, Let's Encrypt) it does not define it, and these
# routers then go nowhere instead of publishing the mail.
#
# No #ddev-generated: DDEV deletes a signed file here that no add-on installed.
# The ports are DDEV's to say, so without them (run by hand) nothing is written.
mailpit=.ddev/traefik/config/hostshift-mailpit.yaml
http_port="${DDEV_MAILPIT_HTTP_PORT:-${DDEV_MAILPIT_PORT:-}}"
https_port="${DDEV_MAILPIT_HTTPS_PORT:-}"
if [ -z "$variants" ]; then
rm -f "$mailpit"
elif [ -n "${DDEV_SITENAME:-}" ] && [ -n "$http_port" ] && [ -n "$https_port" ]; then
rule="$(printf '%s' "$variants" | tr ', ' '\n\n' \
| awk 'NF { printf "%sHost(`%s`)", (n++ ? " || " : ""), $0 }')"
mkdir -p "${mailpit%/*}"
cat > "$mailpit" <<YAML
#ddev-silent-no-warn
# Written by \`ddev hostshift init\`: Mailpit on this checkout's variant hostnames.
http:
routers:
${DDEV_SITENAME}-hostshift-mailpit-http:
entrypoints:
- http-${http_port}
rule: ${rule}
service: ${DDEV_SITENAME}-web-8025
tls: false
${DDEV_SITENAME}-hostshift-mailpit-https:
entrypoints:
- http-${https_port}
rule: ${rule}
service: ${DDEV_SITENAME}-web-8025
tls: true
YAML
fi
hostshift map --slug "$slug" "${map_args[@]+"${map_args[@]}"}" >&2

# And pick it up. init always leaves the project stale — that is what it is for —
Expand Down
2 changes: 2 additions & 0 deletions ddev/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ removal_actions:
# Paths relative to .ddev/, which is the cwd DDEV runs these actions in —
# documented at post_install_actions above, and got wrong here, which made
# this whole list dead on every removal. `..` is the project root.
# Ours alone, and it routes hostnames nothing serves once the add-on is gone.
rm -f traefik/config/hostshift-mailpit.yaml
left=""
[ -f docker-compose.hostshift-loopback.yaml ] && left="$left
.ddev/docker-compose.hostshift-loopback.yaml — pins production hostnames to 127.0.0.1 in web"
Expand Down
23 changes: 23 additions & 0 deletions test/addon-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2739,6 +2739,29 @@ contains "it works from a subdirectory" "HOSTSHIFT_VARIANTS=wt-a--acme.ddev.site

echo

echo "== mailpit on the variants"

mp=".ddev/traefik/config/hostshift-mailpit.yaml"
mailpit_init() {
(cd "$wt" && DDEV_SITENAME=acme-wt DDEV_MAILPIT_HTTP_PORT=8025 DDEV_MAILPIT_HTTPS_PORT=8026 \
"$cmd" init --slug wt-a "$@" >/dev/null 2>&1 || true)
}
mailpit_init --dry-run
[ ! -e "$wt/$mp" ] && pass "--dry-run writes no router file" || fail "--dry-run writes no router file" "$mp exists"
mailpit_init
router="$(cat "$wt/$mp" 2>/dev/null || true)"
contains "the https port is routed" "- http-8026" "$router"
contains "the http port is routed" "- http-8025" "$router"
contains "every variant is matched" 'rule: Host(`wt-a--acme.ddev.site`) || Host(`wt-a--nat.acme.ddev.site`)' "$router"
contains "to DDEV's own mailpit service" "service: acme-wt-web-8025" "$router"
# DDEV deletes a signed file in this directory that no add-on installed.
case "$router" in *"#ddev-generated"*) fail "the router file is not signed as DDEV's" "$router" ;;
*) pass "the router file is not signed as DDEV's" ;; esac
rm -f "$wt/$mp"
(cd "$wt" && "$cmd" init --slug wt-a >/dev/null 2>&1 || true)
[ ! -e "$wt/$mp" ] && pass "without DDEV's ports nothing is written" || fail "without DDEV's ports nothing is written" "$mp exists"

echo
echo "== copy-db --dry-run writes nothing"

# copy-db is the one destructive subcommand, and it exits before the file's only
Expand Down
5 changes: 5 additions & 0 deletions test/integration-ddev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ contains "the worktree's own hostname still serves the worktree" "PROJECT=worktr
# Mailpit rides web's VIRTUAL_HOST, which the add-on narrows.
code="$(curl -sk -o /dev/null -w '%{http_code}' --max-time 20 https://${tag}-wt-a.ddev.site:8026/ 2>/dev/null || true)"
[ "$code" = "200" ] && pass "mailpit still routes" || fail "mailpit still routes" "http $code"
# The variant goes to hostshift, not web, so its Mailpit ports are separate routes.
code="$(curl -sk -o /dev/null -w '%{http_code}' --max-time 20 https://wt-a--${tag}.ddev.site:8026/api/v1/info 2>/dev/null || true)"
[ "$code" = "200" ] && pass "mailpit routes on the variant" || fail "mailpit routes on the variant" "http $code"
code="$(curl -s -o /dev/null -w '%{http_code}' --max-time 20 http://wt-a--${tag}.ddev.site:8025/api/v1/info 2>/dev/null || true)"
[ "$code" = "200" ] && pass "mailpit routes on the variant over http" || fail "mailpit routes on the variant over http" "http $code"

out="$(cd "$wt" && ddev hostshift check 2>&1)" && pass "check passes a live worktree" \
|| fail "check passes a live worktree" "$out"
Expand Down
Loading