-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Make devcontainers opt in and create a devcontainer command #51880
Conversation
d9a666b
to
019bc15
Compare
railties/lib/rails/generators/rails/db/system/change/change_generator.rb
Outdated
Show resolved
Hide resolved
|
||
module Rails | ||
module Command | ||
class DevcontainerCommand < Base # :nodoc: |
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.
Do we need a command? I think rails g devcontainer
should be enough.
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.
rails g devcontainer
would work if you pass options to it, or get the default options. But the command is what knows about booting the application and looking at it to figure out what options are needed.
I am thinking about how I could move that into the generator. I think we would need another option for the generator to tell it to generate based on the current application, rather than the passed options (or just the defaults). So I guess we could make that option true
by default (otherwise user has to do rails g devcontainer --infer-options
), and then we can set it to false
when we call it in the application generator.
What do you think about that?
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.
Let's keep the command then
67d55c2
to
7759c1d
Compare
For Rails 7.2 we will make devcontainer and opt-in feature for new applications. When creating a new app, you can generate a devcontainer by passing the --devcontainer flag.
This refactoring prepares the way to implement a devcontainer command to add an devcontainer to an existing app.
Instead of relying on the template to be dev container aware and generate the correct configuration, let's just update the configuration in place when running the DevcontainerGenerator. This will allow the devcontainer command to update this file with the configuration needed for devcontainers without overwriting the entire file.
Postgresql's database.yml has devcontainer specific logic that should only appear when the app has a devcontainer. We need the DevcontainerGenerator to update database.yml, so when it is called by the devcontainer command the database.yml will have the right configuration. This commit also fixes db:system:change to make sure it updates the database.yml with the correct devcontainer configuration.
7759c1d
to
5bce6b9
Compare
This command boots the application, and generates a Dev Container setup based on the current configuration of the application.
5bce6b9
to
df203b2
Compare
Make devcontainers opt in and create a devcontainer command
Motivation / Background
This Pull Request has been created because we have decided for Rails 7.2 dev containers will be an opt in feature. So, new apps will only get a devcontainer if you pass the
--devcontainer
flag torails new
. Additionally, you will be able to generate a devcontainer for an existing app withbin/rails devcontainer
.Detail
There are a few commits here to make this work. First, I refactored the application generator to make dev container opt in. Then I extracted all the devcontainer logic from the application generator into a dedicated devcontainer generator. That allows the logic to be shared by the
new
command and thedevcontainer
command.For the
devcontainer
command, I boot the app and check on the state of the application to decide what options are needed for the devcontainer, similar to the app update command.Additional information
Previously, we had devcontainer specific logic in
application_system_test_case.rb.tt
. I removed that logic, and instead, now the devcontainer generator updatesapplication_system_test_case.rb
in place when generating a dev container. That way, we do not need to overwrite the entire file when generating a devcontainer for an existing app.Similarily, there is devcontainer specific logic in
postgresql.yml.tt
. The devcontainer will update thedatabase.yml
for an existing app to make sure thedatabase.yml
is up-to-date. I also fixed this for thedb:system:change
generator, which previously was not updating thedatabase.yml
to include the devcontainer specific config.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]