Skip to content

Conversation

@pablobm
Copy link
Contributor

@pablobm pablobm commented Oct 7, 2025

Another extraction from #6424

In order:

  1. Extract the code of the oauth:register_apps task into a method, to allow reuse.
  2. Use this to create an initial user admin.
  3. Run yarn install in bin/setup, or it may not work.
    • Related enough to this work. I was trying to get a user created by running bin/setup, which includes db:prepare and in turn runs db:seed.

This takes inspiration from @mmd's https://gist.github.com/mmd-osm/a3a0b5a8799a333e7fae578038aa7a93, but is much simpler. We can think about adding more in the future.

Also related to @gravitystorm's #3101 (I should have a look at that).

@tomhughes
Copy link
Member

If we're going to use db:seed to set things up then do we still need oauth:register_apps as well?

bin/setup Outdated

puts "== Installing dependencies =="
system("bundle check") || system!("bundle install")
system("bin/yarn check") || system!("bin/yarn install")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rails template actually has this if node support is enabled:

  # Install JavaScript dependencies
  system("yarn install --check-files")

Not sure if the difference is meaningful though...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I suspect that it's a bit faster as it won't traverse the dependency graph twice. In any case, when in doubt I prefer to do exactly as provided by Rails. Changed now.

@pablobm
Copy link
Contributor Author

pablobm commented Oct 8, 2025

I think that oauth:register_apps is still useful for people who don't through the bin/setup route, or if something goes wrong and the rake task still needs to be run.


# Install JavaScript dependencies
system("yarn install --check-files")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use bundle exec bin/yarn install in the install notes, Docker file, and vagrant provisioning, and so I would expect this to be consistent with those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about going the other way around?

All this is in the spirit of trying to stay as similar to stock Rails as possible, which will help in future updates.

Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to align with upstream. My main concern, by far, is to make sure that what is written in the install notes (including any options) is as close to possible as what is done in CI. We've had so many cases over the years where the install notes don't work, and we haven't noticed because CI was doing something subtly different, and who knows how many people tried and failed before anyone contacted us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍 In that case: happy for me to leave this as is and update the install note in this PR?

Tangentially: I should review the install notes. I think I noticed some inconsistencies there. But that'd be separate work.

email = "admin_#{SecureRandom.uuid}@example.com"
role = "administrator"

admin = User.find_or_create_by!(:display_name => display_name) do |user|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid putting non-essential data into the seeds file. This file should only contain the data that's essential to running the site, in all deployments, since the seeds can be run in all environments (test, development and production). These seeds can end up in production databases, perhaps inadvertently, depending on which commands a sysadmin users to set up the database.

See #3030 (comment) for more details on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'm thinking of two options:

  1. I turn this into a dev:populate task, with guards to avoid running on production.
  2. I remove this script (keeping the refactor and the bin/yarn thing), and we focus on getting your dev:populate task (Create a dev:populate task to add fake data to your dev environment #3101) through. This can be augmented with the new Oauth::Util.register_apps utility.

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

Successfully merging this pull request may close these issues.

3 participants