Programmatic configuration of a new Discourse site

Is it possible to programmatically configure a new site via the API?

What do you mean by “configure a new site”?

1 Like

I’m most interested in setting up admin users, running through the steps in the Admin Quick Start Guide, and configuring SSO.

If you’re fluent in Ruby, you can change pretty much everything by simply loading up the Discourse app in a Ruby script:

require "/path/to/discourse/config/environment"
SiteSetting.must_approve_users = true
u = User.new(username: "admin", email: "admin@example.com", ...)
u.save!

Obviously, this script must live and be executed inside Discourse’s docker container. Also, note that the first line loads the entire Discourse app into the script and is fairly time consuming.

2 Likes

Perfect – thank you @elberet!

I’ve come across the same requirement to programatically configure Discourse configuration. Unfortunately for me, i’m not fluent in Ruby. There must be some magic somewhere that I didn’t get yet.

In discourse code, at config/site_settings.yml which would be nice we could superseed via configuration files. So far, I know we can do a few things via a file we install from discourse_docker from samples/standalone.yml, and that we can extend keys from discourse at config/discourse_defaults.conf.

Is there a way to do the same with site_settings.yml?

Site settings are all in the database so you can easily set overrides by using our object model.

I was hoping there was a way to inject settings so that I dont need to use database to do it. If there is none, its OK :slight_smile:

not following are you looking to provision 1000s of sites :slight_smile:

you can change site settings in the UI, if you must pre-populate site settings you can add hook that runs post migration that forces a setting. you can not change defaults.

In fact i’m more interested in ways to declare which authorize URL I can go against for S3 settings. And it seems that if I don’t use Amazon AWS, I can’t do it. (maybe I missed the config key).

On a related note, here’s how I provision an app only container.