Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "official" Github Codespaces support #3914

Closed
1 task done
cweagans opened this issue Jun 14, 2022 · 13 comments
Closed
1 task done

Add "official" Github Codespaces support #3914

cweagans opened this issue Jun 14, 2022 · 13 comments

Comments

@cweagans
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe

(follow up to #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:
config yaml — va gov-cms  Codespaces  2022-06-14 14-20-12

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

@rfay
Copy link
Member

rfay commented Jun 14, 2022

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.

@rachellawson
Copy link

Happy to test this if there are instructions how

@rfay
Copy link
Member

rfay commented Jul 5, 2022

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.

@rfay
Copy link
Member

rfay commented Aug 27, 2022

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.

@rfay rfay closed this as completed Aug 27, 2022
@bhanu951
Copy link

bhanu951 commented Aug 30, 2022

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.

ddev describe

ports

Only drawback is I am yet to find a way to access PHPMyAdmin and MailHog through UI.

@rfay
Copy link
Member

rfay commented Aug 30, 2022

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 rfay reopened this Aug 30, 2022
@bhanu951
Copy link

bhanu951 commented Sep 1, 2022

@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.
Before

After

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

@rfay
Copy link
Member

rfay commented Sep 1, 2022

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.

@rfay
Copy link
Member

rfay commented Nov 14, 2022

Github codespaces is now free to all for 60 hours/month, https://twitter.com/github/status/1590403103014420481?s=20&t=uYgWgYTRq0TSSj5iRq6XDg

@rfay
Copy link
Member

rfay commented Nov 14, 2022

I would love to help anybody who wants to finish this territory. We learned so much from gitpod that it shouldn't be hard.

@rachellawson
Copy link

So, what I know so far...

  1. 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`"
}
  1. I add my Platform CLI token as a secret that is added to the container
  2. Would prefer to create a feature than use the postCreateCommand
  3. Disabling the router helps
  4. I'm currently manually connecting to the right port(s). Use ddev describe

@rachellawson
Copy link

You are welcome to peruse https://github.com/rachellawson/rachelnorfolk

@rfay
Copy link
Member

rfay commented Dec 22, 2022

I'd love to have everybody here test

There are test instructions there...

@rfay rfay closed this as completed in 5679aaa Dec 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants