mirror of
https://github.com/internetee/registry.git
synced 2025-06-03 19:27:29 +02:00
Improve setup and seed (#1352)
bin/setup.deps for installing dependencies before running setup rework bin/setup for initial setup improved db:seed
This commit is contained in:
parent
625294f610
commit
6fb8767aef
3 changed files with 129 additions and 13 deletions
29
bin/setup
Normal file → Executable file
29
bin/setup
Normal file → Executable file
|
@ -1,29 +1,32 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
|
||||
# path to your application root.
|
||||
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
||||
|
||||
|
||||
def system!(*args)
|
||||
system(*args) || abort("\n== Command #{args} failed ==")
|
||||
end
|
||||
|
||||
Dir.chdir APP_ROOT do
|
||||
# This script is a starting point to setup your application.
|
||||
# Add necessary setup steps to this file:
|
||||
|
||||
puts "== Installing dependencies =="
|
||||
system "gem install bundler --conservative"
|
||||
system "bundle check || bundle install"
|
||||
puts '== Installing dependencies with bundler =='
|
||||
system! 'gem install bundler --conservative'
|
||||
system('bundle check') || system!('bundle install')
|
||||
|
||||
# puts "\n== Copying sample files =="
|
||||
# unless File.exist?("config/database.yml")
|
||||
# system "cp config/database.yml.sample config/database.yml"
|
||||
# end
|
||||
puts "\n== Copying sample development database config files =="
|
||||
unless File.exist?('config/database.yml')
|
||||
system! 'cp config/database-example-development.yml config/database.yml'
|
||||
end
|
||||
|
||||
puts "\n== Preparing database =="
|
||||
system "bin/rake db:setup"
|
||||
system! 'bin/rake db:setup'
|
||||
|
||||
puts "\n== Removing old logs and tempfiles =="
|
||||
system "rm -f log/*"
|
||||
system "rm -rf tmp/cache"
|
||||
system! 'bin/rails log:clear tmp:clear'
|
||||
|
||||
puts "\n== Restarting application server =="
|
||||
system "touch tmp/restart.txt"
|
||||
system! 'bin/rails restart'
|
||||
end
|
||||
|
|
56
bin/setup_with_build_deps
Executable file
56
bin/setup_with_build_deps
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
|
||||
# path to your application root.
|
||||
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
||||
|
||||
|
||||
def system!(*args)
|
||||
system(*args) || abort("\n== Command #{args} failed ==")
|
||||
end
|
||||
|
||||
def effective_user_id
|
||||
uid = `id -u`
|
||||
uid.strip!
|
||||
end
|
||||
|
||||
Dir.chdir APP_ROOT do
|
||||
puts '== Installing application build deps =='
|
||||
sudo_prefix = ''
|
||||
sudo_prefix = "sudo" unless effective_user_id == '0'
|
||||
system! "#{sudo_prefix} apt-get update && #{sudo_prefix} apt-get -y --no-install-recommends install libxml2 libxml2-dev postgresql-client postgresql-client-common libpq-dev"
|
||||
|
||||
puts "== Installing rbenv ruby manager to #{ENV['HOME']} =="
|
||||
unless Dir.exist?("#{ENV['HOME']}/.rbenv/")
|
||||
system! 'git clone https://github.com/sstephenson/rbenv.git $HOME/.rbenv'
|
||||
system! 'echo export PATH="$HOME/.rbenv/bin:$PATH" >> ~/.bashrc'
|
||||
system! "echo 'eval $(rbenv init -)' >> ~/.bashrc"
|
||||
end
|
||||
|
||||
unless Dir.exist?("#{ENV['HOME']}/.rbenv/plugins/ruby-build/")
|
||||
system! 'git clone https://github.com/sstephenson/ruby-build.git $HOME/.rbenv/plugins/ruby-build'
|
||||
system! 'echo export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH" >> ~/.bashrc'
|
||||
end
|
||||
unless Dir.exist?("#{ENV['HOME']}/.rbenv/plugins/rbenv-default-gems/")
|
||||
system! 'git clone https://github.com/rbenv/rbenv-default-gems.git $HOME/.rbenv/plugins/rbenv-default-gems'
|
||||
unless File.exist?("#{ENV['HOME']}/.rbenv/default-gems")
|
||||
system! 'echo "bundler" > ~/.rbenv/default-gems'
|
||||
end
|
||||
end
|
||||
|
||||
# Include RBENV in path
|
||||
ENV['PATH'] = ENV['HOME'] + "/.rbenv/bin:" + ENV['HOME'] + "/.rbenv/plugins/ruby-build/bin:" + ENV['PATH']
|
||||
NEEDED_RUBY_VERSION = `cat .ruby-version`.freeze
|
||||
|
||||
if `!bundle check` == false
|
||||
system! "#{SUDO_PREFIX} apt-get -y --no-install-recommends install libreadline-dev"
|
||||
puts 'Installing Ruby: ' + NEEDED_RUBY_VERSION
|
||||
system!('rbenv install ' + NEEDED_RUBY_VERSION)
|
||||
system!('rbenv rehash')
|
||||
else
|
||||
puts 'Ruby ' + NEEDED_RUBY_VERSION + 'already installed'
|
||||
end
|
||||
puts 'Now running setup'
|
||||
exec('./bin/setup')
|
||||
end
|
57
db/seeds.rb
57
db/seeds.rb
|
@ -1,2 +1,59 @@
|
|||
# This file should contain all the record creation needed to seed the database with its default values.
|
||||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
||||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
||||
ActiveRecord::Base.transaction do
|
||||
AdminUser.where(username: 'admin').first_or_create!(
|
||||
username: 'admin',
|
||||
email: 'admin@domain.tld',
|
||||
password: 'adminadmin',
|
||||
password_confirmation: 'adminadmin',
|
||||
identity_code: '38001085718',
|
||||
country_code: 'EE',
|
||||
roles: ['admin']
|
||||
)
|
||||
# Required for creating registrar
|
||||
Setting.where(var: 'registry_vat_prc').first_or_create(
|
||||
value: '0.2'
|
||||
)
|
||||
# First registrar
|
||||
Registrar.where(name: 'Registrar First').first_or_create!(
|
||||
name: 'Registrar First',
|
||||
reg_no: '90010019',
|
||||
accounting_customer_code: '1234',
|
||||
language: 'EE',
|
||||
reference_no: '11',
|
||||
# vat_rate: '0.2',
|
||||
vat_no: 'EE101286464',
|
||||
address_country_code: 'EE',
|
||||
address_state: 'Harjumaa',
|
||||
address_city: 'Tallinn',
|
||||
address_street: 'Tänav 1',
|
||||
address_zip: '1234546',
|
||||
email: 'registrar@first.tld',
|
||||
code: 'REG1'
|
||||
)
|
||||
|
||||
# registrar.accounts.create!(account_type: Account::CASH, currency: 'EUR')
|
||||
|
||||
# ApiUser.create!(
|
||||
# username: 'api_first',
|
||||
# password: 'api_first',
|
||||
# identity_code: '38001085718',
|
||||
# active: true,
|
||||
# registrar: registrar,
|
||||
# roles: ['epp']
|
||||
# )
|
||||
|
||||
|
||||
|
||||
# ZonefileSetting.create!(
|
||||
# origin: 'tld',
|
||||
# ttl: 43200,
|
||||
# refresh: 3600,
|
||||
# retry: 900,
|
||||
# expire: 1209600,
|
||||
# minimum_ttl: 3600,
|
||||
# email: 'admin.domain.tld',
|
||||
# master_nameserver: 'ns.tld'
|
||||
# )
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue