Skip to content

Commit c8a3d7a

Browse files
committed
Integrate WSL2 and provide readme
1 parent ef8bdfe commit c8a3d7a

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
# Grab environment information (OSX vs Linux)
22
UNAME := $(shell uname)
33
DOCKER_COMPOSE_FILE := docker-compose.yml
4+
WSL := $(shell grep -q -i microsoft /proc/version && echo 1 || echo 0)
5+
DOCKER_HOST_IP := $(shell ping host.docker.internal -W 0 -c 1 | grep -Eo '([0-9]+\.){3}[0-9]+' | tail -1)
46

57
export PROJECT := $(shell basename $(CURDIR) | tr '[:upper:]' '[:lower:]')
68
export IMAGE_MAINTAINER := $(shell grep '^IMAGE_MAINTAINER' ./environment | sed 's/^.*=//g' | tr '[:upper:]' '[:lower:]')
79
LABLE_BASE := ${IMAGE_MAINTAINER}/${PROJECT}
810

11+
ifeq ($(DOCKER_HOST_IP), )
12+
export DOCKER_INTERNAL_IP=$(shell ip route | grep -E '(default|docker0)' | grep -Eo '([0-9]+\.){3}[0-9]+' | tail -1)
13+
else
14+
export DOCKER_INTERNAL_IP=host.docker.internal
15+
endif
16+
917
ifeq ($(UNAME), Linux)
10-
DOCKER_COMPOSE_FILE += -f docker-compose.linux.yml
18+
ifeq ($(WSL), 0)
19+
DOCKER_COMPOSE_FILE += -f docker-compose.linux.yml
20+
endif
1121
endif
1222

1323
INCLUDE_MAKEFILES=
@@ -24,7 +34,7 @@ help: # Show this help
2434
sort | \
2535
sed 's/^/\o033[32m/' | # Start Green color on first column \
2636
sed 's/,/\o033[0m,/' | # End Green color on first colum \
27-
column -N "Target,Description" -t -s ","
37+
column -c "Target,Description" -t -s ","
2838
@echo ""
2939
@echo "Example Usage"
3040
@echo "make <target>"

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,39 @@ standalone servers.
2424

2525
MacOS, Linux, or Windows
2626

27-
> Support for native Windows systems is coming soon. For now, use Toolbox on Windows.
27+
> Windows support can be achieved with WSL or WSL2 natively in this repository.
28+
> We recommend WSL2 due to the excellent speed and support using `make` commands to manage Docker natively.
2829
29-
Docker (https://www.docker.com/products/overview) or Docker Toolbox
30+
### Windows Setup
31+
Docker for Windows (https://www.docker.com/products/overview) will detect and use WSL2. Hypervisor is required for WSL **while it is not for WSL2**. For now, Windows 10 version 2004 and above are the only versions that have WSL2 available. Updates for Windows are being rolled out over the coming months, but to get it now, run the Update Assistant (see https://support.microsoft.com/en-us/help/3159635/windows-10-update-assistant)
32+
33+
For native-like speeds, add your code to a folder under the WSL2 OS you have set up. You may experience significant slowdown if you do not set up your project this way due to the fact that filesystem mounts in WSL2 are implemented as NFS. (see https://github.com/microsoft/WSL/issues/4197#issuecomment-650205399)
34+
35+
1. Install WSL (https://docs.microsoft.com/en-us/windows/wsl/install-win10)
36+
2. Run Docker for Windows (https://docs.docker.com/docker-for-windows/install/)
37+
3. Get the Linux distro you want (Debian in my case) from Windows Store.
38+
4. If using WSL1,
39+
1. Use `docker-compose` for now to start and stop the project. You may need to read through the Makefile to find out what all is needed to run in order for the project to work correctly.
40+
5. If using WSL2,
41+
1. Clone the repo from within WSL (e.g. Debian) but do NOT use the `/mnt/` folders. (https://github.com/microsoft/WSL/issues/4197)
42+
2. Configure your IDE as normal, but open the source under your `\\wsl$\` directory within Windows.
43+
6. Run the native `make` commands per normal in the following section of this document.
44+
45+
> Do you have PHPStorm support?
46+
47+
PHPStorm will work fine out of box with xdebug and detect paths automatically, but in order to get PHP interpretation (and thus error detection), PHPStorm has support for Docker containers.
48+
49+
To enable it, open this project and then hit `File > Settings > Languages & Frameworks > PHP`. Under this dialog, add a "CLI Interpreter" (`...` button, then `+` button on the next dialog) - Docker will be an option, and it will automatically pull the available Docker containers. Select the one marked `drupal-dev-docker-php`.
50+
51+
> PHPStorm wants to open the Windows Command Prompt instead of WSL.
52+
53+
You can select WSL to run instead of the default DOS prompt. Open this project and then hit `File > Tools > Terminal` and under `Application settings`, enter `C:\Windows\System32\wsl.exe` as the `Shell path`.
54+
55+
> PHPStorm's terminal opens the home directory, `$`
56+
57+
Attempting to use a drive letter mapping will not work correctly. Open the project in PHPStorm using the path at `\\wsl$\`
58+
59+
##
3060

3161
> On systems that don't ship with docker-compose (Linux), it should also be installed.
3262

docker-compose.linux.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ services:
33
php:
44
environment:
55
- CONNECTBACK=on
6+
extra_hosts:
7+
- "host.docker.internal:${DOCKER_INTERNAL_IP}"

docker-src/cms/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ RUN apk add --no-cache \
133133
&& echo "xdebug.remote_autostart=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
134134
# Remote connect_back only works on Linux systems because OSX abstracts it away into a VM
135135
&& echo 'xdebug.remote_connect_back="${CONNECTBACK}"' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
136-
# TODO: debug this solution on Windows
137-
&& echo "xdebug.remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
136+
&& echo "xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
138137
&& apk del .build-deps
139138

140139
# color avaiable thanks to ncurses packages above

0 commit comments

Comments
 (0)