Skip to content

Commit

Permalink
Default umbrel-dev to host networking in WSL
Browse files Browse the repository at this point in the history
On Windows, the dev environment works best with WSL, but doing so adds
one more layer of encapsulation. To simplify the process, add a sensible
default that undoes one layer by using Docker host networking within
WSL, so Umbrel OS is passed through to the WSL interface with no need to
publish particular ports within the Docker container.

This behavior can be overridden by setting `UMBREL_DEV_OPTIONS` on the
command line, which is then preferred over the default.

Also adds a new `npm run recreate` command to allow recreating existing
instances with the latest WSL network changes applied.

---------

Co-authored-by: Luke Childs <lukechilds123@gmail.com>
  • Loading branch information
dcodeIO and lukechilds authored Oct 7, 2024
1 parent d2f6982 commit bbf4dc9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scripts/umbrel-dev
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set -euo pipefail
# http://umbrel-dev-apps.local
INSTANCE_ID_PREFIX="umbrel-dev"
INSTANCE_ID="${INSTANCE_ID_PREFIX}${UMBREL_DEV_INSTANCE:+-$UMBREL_DEV_INSTANCE}"
INSTANCE_OPTIONS="${UMBREL_DEV_OPTIONS:-}"

show_help() {
cat << EOF
Expand All @@ -28,6 +29,7 @@ Commands:
exec -- <command> Execute a command inside the running dev environment
client -- <rpc> [<args>] Query the umbreld RPC server via a CLI client
rebuild Rebuild the operating system image from source and reboot the dev environment into it
recreate Recreate the dev environment using the existing operating system image
restart Restart the dev environment
stop Stop the dev environment
reset Reset the dev environment to a fresh state
Expand All @@ -36,6 +38,7 @@ Commands:
Environment Variables:
UMBREL_DEV_INSTANCE The instance id of the dev environment. Allows running multiple instances of
umbrel-dev in different namespaces.
UMBREL_DEV_OPTIONS Optional custom parameters passed to 'docker run' when creating the dev environment.
Note: umbrel-dev requires a Docker environment that exposes container IPs to the host. This is how Docker
natively works on Linux and can be done with OrbStack on macOS. On Windows this should work with WSL 2.
Expand All @@ -48,6 +51,13 @@ build_os_image() {
}

create_instance() {
# --network host is used when running Docker within WSL, effectively undoing one
# level of encapsulation, with umbrelOS accessible at `wsl.exe hostname -i`.
if grep --quiet "WSL" /proc/sys/kernel/osrelease 2> /dev/null
then
INSTANCE_OPTIONS="${INSTANCE_OPTIONS:-"--network host"}"
fi

# --privileged is needed for systemd to work inside the container.
#
# We mount a named volume namespaced to the instance id at /data to immitate
Expand Down Expand Up @@ -75,6 +85,7 @@ create_instance() {
--volume "${PWD}:/umbrel-dev:ro" \
--label "dev.orbstack.http-port=80" \
--label "dev.orbstack.domains=${INSTANCE_ID}.local" \
${INSTANCE_OPTIONS} \
"${INSTANCE_ID}" \
/sbin/init
}
Expand Down Expand Up @@ -215,6 +226,16 @@ then
exit
fi

if [[ "${command}" = "recreate" ]]
then
echo "Recreating the dev environment with the existing image..."
stop_instance || true
remove_instance || true
create_instance

exit
fi

if [[ "${command}" = "destroy" ]]
then
echo "Destroying the dev environment..."
Expand Down

0 comments on commit bbf4dc9

Please sign in to comment.