Project

General

Profile

Initialising Redmine DB from console after install in docker environment linked with mysql docker image

Added by Ozgur Cagdas about 8 years ago

Hi,

I am trying to automatise the installation and deployment of redmine servers. Currently, I am using redmine's official docker image together with official mysql docker image. It all works smoothly but I'd want to carry out some automated post install inits/db operations which I am not sure how.

So, the things I am trying to automatise from the console are;

- Skip the step which requires changing the admin password on first login. I can either leave the default password or assign a new one.
- Enforce the Administration - > Load Default Configuration operation
- Also, when I connect to mysql, I see that all the tables are created and I can view their schemas but appears like some/most tables are yet empty. For example, the 'settings'. As soon as I update a field under the Settings menu and save it, I see that the settings table is filled with all the values I see on the UI, even most are defaults but until this first update, the whole table is empty. I presume redmine holds a flag somewhere if defaults have changed and if not, it doesn't go through the DB but uses the default values. I want to force this 'defaults changed' situation and get all the relevant tables populated, not just settings if possible.

One obvious solution could be going through the UI, getting the DB to the desired state, dump it, load it after first install and modify from the cli as needed. However, I'd really prefer not to bundle and version manage a DB file with my modest auto deploy system.

These might be really obvious questions or I might be being too picky, so, if this is the case, apologies in advance.

Regards,

Ozgur


Replies (5)

RE: Initialising Redmine DB from console after install in docker environment linked with mysql docker image - Added by Felix Schäfer about 8 years ago

See RedmineInstall for adding the default data. Is that what you are looking for in step 2?

Regarding the settings, more than one entry are written to the database when you change and save a setting because all the values on the setting page you are saving will be written to the DB. The defaults are in the config/settings.yml and they are use to populate the values in the settings forms, but once you save a settings page all those settings on that page will be reified in the DB, even if you haven't changed them from the default.

The first step is a little more involved, as there's not "automated" way to do that. You have to drop to the rails runner, which will execute some ruby code in the context of the Redmine application. Something like rails runner 'u = User.where(login: "admin").first; u.password = "thepassword"; u.save' should work.

Shameless plug: If you're looking for fire and forget Redmine instances, we'd be happy to welcome you as a customer at Planio, we offer one-click hosted Redmine with git, svn and email integration as well as a few additional features.

RE: Initialising Redmine DB from console after install in docker environment linked with mysql docker image - Added by Ozgur Cagdas about 8 years ago

Hi Felix,

Thank you very much for your reply.

1- Your suggestion is good enough to update the password and can easily be scripted. My main concern was clearing the 'Must changed password at next logon' requirement for the admin from the console and the 'update users set must_change_passwd='0' where login="admin";' line does what I want on mysql and can still be scripted, so, I can combine both. [Done]

2- Yes, this is exactly what I needed. [Done]

3- What you described regarding how the settings are saved to DB seems to match my initial understanding. However, on a fresh install, until you hit save on the UI, the actual DB table is totally empty. So, I need a way to simulate the UI Settings - > Update - > Save operation from the console. Maybe another rails magic similar to step 2? [Pending]

Regarding Planio, I don't want to make this sound like a scripted ad post but I've used it before through my employers in the past and if you need a professional Redmine solution, I think there is no point in trying to set it up on your own but mine is totally for experimental and hobby purposes but yet with full automation and repeatability in mind.

Regards,

Ozgur

RE: Initialising Redmine DB from console after install in docker environment linked with mysql docker image - Added by Felix Schäfer about 8 years ago

Ozgur Cagdas wrote:

1- Your suggestion is good enough to update the password and can easily be scripted. My main concern was clearing the 'Must changed password at next logon' requirement for the admin from the console and the 'update users set must_change_passwd='0' where login="admin";' line does what I want on mysql and can still be scripted, so, I can combine both. [Done]

I, had not thought of that attribute. You can add that in the line and make sure to use Redmine code instead of meddling with the DB directly (Rails applications are notoriously sensitive to meddling with the DB instead of going through the app): rails runner 'u = User.where(login: "admin").first; u.password = "thepassword"; u.must_change_passwd = '0'; u.save'

3- What you described regarding how the settings are saved to DB seems to match my initial understanding. However, on a fresh install, until you hit save on the UI, the actual DB table is totally empty. So, I need a way to simulate the UI Settings - > Update - > Save operation from the console. Maybe another rails magic similar to step 2? [Pending]

I'm not quite sure why you would need to add the default settings to the DB? As I said they are the same for every Redmine installation (at least of the same version) in config/settings.yml. I haven't tested this, but something like rails runner 'Setting.available_settings.each_key {|k| Setting[k] = Setting[k]}' should do the trick (this looks like a no-op, but the assignment also saves the value to the DB). Note that this will send emails to administrators for security sensitive settings.

Regarding Planio, I don't want to make this sound like a scripted ad post but I've used it before through my employers in the past and if you need a professional Redmine solution, I think there is no point in trying to set it up on your own but mine is totally for experimental and hobby purposes but yet with full automation and repeatability in mine.

Thanks for the praise :-)

RE: Initialising Redmine DB from console after install in docker environment linked with mysql docker image - Added by Ozgur Cagdas about 8 years ago

Adding the 'must_change_passwd' to the rails runner line is definitely a much cleaner solution.

Regarding updating the settings table, yes, I now realise that there is no point in trying to write everything into the DB. I initially wasn't aware of a rails way of updating fields, that's why wanted to populate the DB through rails first, then modify individual fields as required but in this case, something like ```rails runner 'Setting.welcome_text="Just a welcome text"' -e production``` would do the trick for me. ```config/settings.yml``` lists all the fields, if somebody else needs reference too.

That's all my problems solved cleanly :)

Thanks very much.

    (1-5/5)