Add `--devcontainer` flag to `rails new` command

:wave: Hello all, I’m writing this post to see if there is any interest for an idea I had.

Recently I’ve been using devcontainers in my team and I think they offer a lot of value. In particular when working in a team context (no more “I don’t have XYZ installed” problems).

I noted we have a .devcontainer in the rails repository itself, to me this indicates that the core team see value in using devcontainers as well.

I think it would be nice to have a --devcontainer flag in the rails new command. e.g.

rails new app --devcontainer

By default this command would be set to false but when included this command would setup a .devcontainer directory.

I have some ideas about what I’d like to be included in this directory, by default, but I don’t want to be overly prescriptive so would like to gather people’s thoughts on both:

  • if they think this is a good idea,
  • and if so what they think ought to be included?

At a minimum, we could include the ruby feature.

Despite what I said above, one overly prescriptive idea I had would be to use Docker in Docker to spin up a mysql container alongside the devcontainer, given the recent enthusiasm for mysql.

I have started making an experimental fork on this which has the basic functionality of creating a template, but want to check if there’s any interest in this idea or if it’s a complete non-starter before taking it any further.

Thank you, Gary. :bowing_man:

2 Likes

Better dev container integration is planned by Rafael, will likely come for 7.2.

2 Likes

Thanks @byroot! I’d love to contribute.

(Presuming you are referring to) @rafaelfranca - how can I help?

Hey, @Gary-H9! Thanks for creating the discussion. Am I right, that we will be able to develop a project in the GitHub Codespaces in this case?

Hi @kalashnikovisme. :wave:t2:

Adding the --devcontainer flag to the rails new command isn’t strictly necessary to develop Rails projects in GitHub Codespaces.

You can already set up a Rails development environment in Codespaces without this flag.

The flag would just make the process more streamlined and straightforward initially.

I would love to offer support and learn more about it.

I’ve already attempted twice to replicate the same work/development experience as with the ‘normal’ Docker Compose (something like Ruby on Whales: Dockerizing Ruby and Rails development—Martian Chronicles, Evil Martians’ team blog, but I use a sophisticated version). Typically, I use a template for my new Rails projects, enabling me to perform all the tasks locally that I would do with a standard Rails project. However, I’m encountering some issues in devcontainers.

  1. Initially, using it directly in VS Code results in a new VS Code setup without any extensions installed. I haven’t investigated thoroughly yet, but it’s likely that you can install specific extensions locally without including them in the devcontainers setup for all developers.

  2. Utilizing Installing and working with the devcontainer CLI comes with several limitations. One example is that you cannot even run something like devcontainer down. I might be missing something due to a lack of knowledge, but I haven’t found a solution for this yet. Also, you do not have easy overview and management of your volumes, as you have with normal docker compose.

So fare, I was ending up twice to not work with devcontainers, as my usual setup is much better experience.

1 Like

I’m not sure to be honest, I think Rafael has his own idea, you can follow Generate devcontainer files by default · Issue #50566 · rails/rails · GitHub

1 Like

Not sure who is following the related PR, but what you think about the following comment?

This feature was added in this PR.