diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-12-20 11:47:01 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-12-20 11:47:01 +0000 |
commit | c111e2657df22c811191135369d599923dc89f54 (patch) | |
tree | 2de468666124191dcf815cf4dd92ea21fa76ca16 /db/fixtures/production/002_admin.rb | |
parent | cad0661aadff50b4d2c2b4cc7b012809b945213c (diff) | |
parent | 37c934e089508e053e6ad4cf075b00cfaab53f3c (diff) | |
download | gitlab-ce-c111e2657df22c811191135369d599923dc89f54.tar.gz |
Merge branch 'master' into 'feature/option-to-make-variables-protected'
Conflicts:
db/schema.rb
Diffstat (limited to 'db/fixtures/production/002_admin.rb')
-rw-r--r-- | db/fixtures/production/002_admin.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/db/fixtures/production/002_admin.rb b/db/fixtures/production/002_admin.rb new file mode 100644 index 00000000000..1c7c89f7bbd --- /dev/null +++ b/db/fixtures/production/002_admin.rb @@ -0,0 +1,40 @@ +user_args = { + email: ENV['GITLAB_ROOT_EMAIL'].presence || 'admin@example.com', + name: 'Administrator', + username: 'root', + admin: true +} + +if ENV['GITLAB_ROOT_PASSWORD'].blank? + user_args[:password_automatically_set] = true + user_args[:force_random_password] = true +else + user_args[:password] = ENV['GITLAB_ROOT_PASSWORD'] +end + +# Only admins can create other admin users in Users::CreateService so to solve +# the chicken-and-egg problem, we pass a non-persisted admin user to the service. +transient_admin = User.new(admin: true) +user = Users::CreateService.new(transient_admin, user_args.merge!(skip_confirmation: true)).execute + +if user.persisted? + puts "Administrator account created:".color(:green) + puts + puts "login: root".color(:green) + + if user_args.key?(:password) + puts "password: #{user_args[:password]}".color(:green) + else + puts "password: You'll be prompted to create one on your first visit.".color(:green) + end + puts +else + puts "Could not create the default administrator account:".color(:red) + puts + user.errors.full_messages.map do |message| + puts "--> #{message}".color(:red) + end + puts + + exit 1 +end |