Add "official" Github Codespaces support
Is there an existing issue for this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe
(follow up to https://github.com/drud/ddev/issues/3283, which was repurposed to focus on Gitpod)
We use ddev in Codespaces. It works really well if you set DDEV_PRETEND_GITPOD=true. We'd like ddev to auto-configure itself for Codespaces like it does for Gitpod.
Describe the solution you'd like
We'd like ddev to autodetect Codespaces in the same way that Gitpod is detected. In Github Codespaces, there are two envvars that you can look for:
CODESPACES=true
CODESPACE_NAME=department-of-veterans-affairs-va-gov-cms-5494gp3v5q5
In the port list, :8443 is properly discovered as the right port to attach a URL when we set DDEV_PRETEND_GITPOD=true:

so if it does exactly the same thing as DDEV_PRETEND_GITPOD=true when CODESPACES=true, we'll be all set.
Describe alternatives you've considered
No response
Additional context
No response
Very cool. My experience is that it's not too hard, but of course it requires effort and somebody paying attention. Gitpod was more work than I expected in the end, with a variety of things.
Happy to test this if there are instructions how
It's not hard. The one thing that is a little confusing is that the ddev-router is not really needed, since codespaces is doing its own reverse proxy. But just go ahead and install ddev as if it were any linux system, consider disabling omit-containers on the router, and expose the web port (and fix it). Take a look at a gitpod project, just start up https://gitpod.io/#DDEV_REPO=https%3A%2F%2Fgithub.com%2Fdrud%2Fd9simple,DDEV_ARTIFACTS=https%3A%2F%2Fgithub.com%2Fdrud%2Fd9simple-artifacts/https://github.com/drud/ddev-gitpod-launcher/ and then take a poke around. Look at the .ddev/config.yaml and the ~/.ddev/global_config.yaml.
I'm fine with a PR for this, but don't think this will be a priority any time soon. But contributions are welcome. Closing for now.
I tried to setup DDEV on GitHub Codespaces and I am able to set it up.
I used the default Linux images and included docker-in-docker feature and installed DDEV using apt-get commands.
Here is the link to my repo.
Once DDEV is setup the most important thing is to identify the correct url for the website. Fortunately we have a simple way to identify it.
run ddev describe it will list down the current application details.
Under All URLs section it will show both http and https urls.
Note down the port number of the http url and browse through the PORTS section in the terminal and click on the url adjacent to http port it will open website in the new tab.
Only drawback is I am yet to find a way to access PHPMyAdmin and MailHog through UI.
ddev can't know the URL because codespaces is in charge of it. But if you figure out how to get codespaces to tell you the URL for the right port, then we'll be somewhere.
You'll probably want to ddev config global --omit-containers=ddev-router so the router doesn't even run, and then use ddev config --http-port=80, then you'll be binding to port 80 directly with the web container, and the port 80 URL that codespaces is showing you will be the one you want.
I'll reopen if you're going to work on this.
@rfay thanks for the instructions. I tested by making above changes , but ddev web container is not yet bound to port 80,
After making those changes port 80 is not being displayed in the ports tab.

ddev config global --omit-containers=ddev-router
Global configuration:
instrumentation-opt-in=true
omit-containers=[ddev-router]
web-environment=[]
mutagen-enabled=false
nfs-mount-enabled=false
router-bind-all-interfaces=false
internet-detection-timeout-ms=3000
disable-http2=false
use-letsencrypt=false
letsencrypt-email=
table-style=default
simple-formatting=false
auto-restart-containers=false
use-hardened-images=false
fail-on-hook-fail=false
required-docker-compose-version=
use-docker-compose-from-path=false
no-bind-mounts=false
You may want to experiment with this a little locally. It's not a hard idea. You disable ddev-router, then in your project configuration, you use host_webserver_port: 80 (or whatever you want). 80 makes it easy to find. Then you have codespaces proxy that for you. You'll want to look at the available options if you want host_mailhog_port for example. Read through the config.yaml comments.
Oh, and you may need bind_all_interfaces: true based on how codespaces works. That tells ddev to bind not just to the localhost interface.
You may want to not do the mkcert -install because it's irrelevant mostly when codespaces is your reverse proxy.
That's most of it. You're just dumping the ddev-router, and then binding the ports you want directly to the web container.
Github codespaces is now free to all for 60 hours/month, https://twitter.com/github/status/1590403103014420481?s=20&t=uYgWgYTRq0TSSj5iRq6XDg
I would love to help anybody who wants to finish this territory. We learned so much from gitpod that it shouldn't be hard.
So, what I know so far...
- A .devcontainer folder containing just a dev container.json will get us ddev installed:
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:1": {}
},
"postCreateCommand": "curl https://apt.fury.io/drud/gpg.key | sudo apt-key add - && echo 'deb https://apt.fury.io/drud/ * *' | sudo tee -a /etc/apt/sources.list.d/ddev.list && sudo apt update && sudo apt install -y ddev && ddev config global --web-environment='PLATFORMSH_CLI_TOKEN='`echo $PLATFORM_CLI`"
}
- I add my Platform CLI token as a secret that is added to the container
- Would prefer to create a feature than use the postCreateCommand
- Disabling the router helps
- I'm currently manually connecting to the right port(s). Use
ddev describe
You are welcome to peruse https://github.com/rachellawson/rachelnorfolk
I'd love to have everybody here test
- https://github.com/drud/ddev/pull/4476
There are test instructions there...