-
Notifications
You must be signed in to change notification settings - Fork 1k
Support for Development Containers (devcontainers) #6424
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
Conversation
|
Is it possible to mount a persistent volume in the container for gems, npms etc so that it will only have to install new ones when it started? |
|
Looking at it in more detail how exactly does the host/container split work? Is it mounting the checkout from the host to the In which case I guess the gems and npms are already persistent? Certainly npms but where exactly is it installing gems to at the moment? We'll need to replace The commit to get rid of |
|
NPM dependencies should be ok as they live in Ruby dependencies are handled with https://mise.jdx.dev and go in I have added a todo list to the description. Will go through these items in the next few days, a bit at a time. If others are able to test that this works in different environments, that'd be grand! |
|
Found something very annoying while fixing From what I can tell, Rails+Capybara don't properly "reset" the remote Selenium when running a test with a different First issue I see is that this is not scalable. Not a problem right now as there are only three configurations. Could be a problem in the future if for any reason we want to test more. |
|
Another funny one. Relevant commit: cf421c0. The test test/system/select_language_test.rb fails with remote Selenium because there is no HTTPS, and therefore it can't set "secure" cookies. I'm ignorant on this topic: should we bother with secure cookies? We force HTTPS anyway 🤔 Alternatively, we could have a setting in the JS that announces whether we are in production mode, and then set |
|
The point of the |
|
That code should probably just be |
|
I'm reading a bit more. I think the explanation (or at least one explanation) is that an attacker could impersonate the HTTP version of the site before the redirection to HTTPS. Hence we can't be sure that we are setting the cookie securely. I think |
|
We already send |
|
Right, that's all tests passing under the devcontainer, on my Mac and on CI. Other environments yet to be tested. I solved the issue with the cookies using Still a few todo items to go through, plus the open questions. Non-devcontainers tests are failing because I'm missing a cleanup: I didn't want to commit too much time on that, just in case there are concerns about the caveats. If you have opinions, I'd love to hear them! |
|
Correction: a bunch of errors on CI (devcontainer workflow), after a flawless one earlier... Oh my. |
|
Crisis averted. I had committed something silly. |
hlfan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the cookies clean up doesn't need that much of investigation ahead of pulling it into its own PR.
04182b5 to
d57b178
Compare
|
Cookies clean up extracted to #6430. Will remove from here when that is merged, as it's necessary for CI to pass. |
|
Selenium |
- Parallelel tests are not working with remote Selenium. For now let's detect the environment and disable parallel tests when remote. - When using remote Selenium, the browser doesn't reset properly when changing preferences. As a result these are not applied. As a workaround, on remote we'll run a Selenium instance per different set of settings we need. This is not scalable, but for now it should be ok as there are only 3 sets. - Tell WebMock not to interfere with requests between containers.
|
@waldyrious @danieldegroot2 - Since you left reviews... 😉 Have you tried this setup? Did you encounter any issues? |
Co-authored-by: danieldegroot2 <67521919+danieldegroot2@users.noreply.github.com> Co-authored-by: Waldir Pimenta <waldyrious@gmail.com>
|
@hlfan - Potential clue of what's going on with the failing test for the language selector. I tested the devcontainer again today and it failed. This is an excerpt of the screenshot I got:
This suggests that the browser gives the focus to the first element in the list (Afrikaans) instead of leaving it on the input box. If you try this on your browser (open the selector, press tab to move the focus) then you won't be able to type in the box any more, which is consistent with the test failure. As to what could possibly be moving the focus, I have no idea. |
No, I personally don't use code. |
|
I haven't used this either 😅 |
|
I've tried this out today, using devcontainers-cli specific notesThe port forwarding is not supported by @devcontainers/cli ( see https://github.com/devcontainers/cli/issues/186 and https://github.com/devcontainers/cli/issues/22) but this can be worked around. First, launch the server bound to all IP addresses, not just localhost within the container, i.e. `bundle exec rails server -b 0.0.0.0`. Secondly, add the port forwarding to the compose file, i.e. --- a/.devcontainer/compose.yaml
+++ b/.devcontainer/compose.yaml
@@ -6,6 +6,9 @@ services:
context: ..
dockerfile: .devcontainer/Dockerfile
+ ports:
+ - "3000:3000"
+
volumes:
- ../..:/workspaces:cached
- mise-cache:/home/vscode/.local/share/miseIt would be great if My next plan is to test with DevPod to see how the IDE integration side of things works. But from my side, this looks good to me. What are the current blockers, if any? Are there any other specific things you want tested? Since this PR is additive, should we merge this and iron out any kinks later? |
#6585 extends here as well, but I don't necessarily see that as blocking. |
|
Agreed with @hlfan - The test Regarding the actual development environment: it did something weird for me last month (#6424 (comment)), then it's working again this week. I think we can live with that and improve it over time. Something we could do is merge this, but disabling the workflow until we figure out what's going on with the language selector. I can create a separate issue to track that, including the detail I discovered at #6424 (comment) |
I've not made much progress with this today, but that's to do with things on the DevPod side of things, nothing in our repo.
Yes please. I'd like to see if/how things work with CodeSpaces at least, in the meantime. |
|
Created new issue to track the flaky test for the language selector: #6712 |
|
I have brought this out of draft now. @gravitystorm: should the port forwarding config you shared above be included? I just played a bit with @devcontainers/cli and couldn't get the server to work despite your instructions. I stopped before I sank too much time on it. The test suite ran well. If that's not an issue, then this might be ready to merge. Re: disabling the GHA workflow, I don't know that there's a way to do it with code. Would a maintainer disable it on the GitHub UI please? https://docs.github.com/en/actions/how-tos/manage-workflow-runs/disable-and-enable-workflows |
No, I don't think so. The lack of port forwarding (and/or the subtly different "port publishing") is a devcontainers-cli limitation, and I'm not sure what else might break if we start including that stuff as a workaround. So best leave it aside for now. |
Done. |
|
I haven't had any much luck trying to use this with codespaces... First it took forever to startup and then when it did it said there were migrations pending and offered to run them but that failed without telling me why - running them manually revealed that they had run but the schema dump at the end was failing as it was using pg_dump 15 against a postgres 16 server. After all that it's still not functional as far as I can see because there's no server running and no way that I can find to start one. |
My opinion is that we merge this, for the purposes of development. Then we can have a separate PR with a different config for the purposes of using with codespaces, which is apparently a thing (example at thoughtbot/administrate#2948). There could be a discussion along the lines of: "well if the codespaces config works better, why not use that". My answer at the moment is that I have no idea of what works better in which cases. I'm currently advocating to go with this PR because it follows Rails convention, in the sense that it works on top of what is provided by the generator |
|
I was basically doing it because it was the easy way for me to test it but it sounds like I'll have to bite the bullet and see if I can get something working locally 😢 |


Fixes #5264
This adds configuration for Development Containers, aka devcontainers (https://containers.dev/). This allows running a development environment in a container, using Docker or other tools, more easily than done with Docker manually and with integration with IDEs.
Misc notes:
bin/rails devcontainer, with minimal changes to adapt to this project../devcontainer/startneeds to runmise trust /workspaces/mise.local.tomlto avoid an interactive prompt asking whether this file can be trusted.apt-getcall. Hopefully I'm not missing any. Eg: the need forosmosisis not obvious as not covered by tests.DEVCONTAINER.mdfromDOCKER.md. There's a lot of duplication that I propose we address separately at DRY docs #6458:allow_localhost => trueis not true in that setting.Caveat: remote Selenium
From the point of view of the test suite, Selenium runs remotely, in a separate container. Unfortunately this causes two problems:
test/system/embed_test.rb, which runs the browser with different language configurations.Note that these issues only affect tests run within the containerised setup. Classic, local environments run Selenium "locally" and don't have these issues.
As a workaround for setting preferences, this runs several Selenium instances (
selenium-default,selenium-de,selenium-nolang), each with a set of preferences. This is not scalable, but right now it's ok as we only have three sets of preferences.To run Selenium this way, some additional options are required in the
driven_bycall. To avoid duplication, the new test helperdriven_by_seleniumcan be used, which sets things up correctly depending on the case.As a workaround for parallel tests, we detect that we are in a container by checking if
CAPYBARA_SERVER_PORTis set. If so, we don't callparallelize.