redmine-installer 1.0.7 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +3 -15
  5. data/README.md +49 -177
  6. data/bin/redmine +4 -5
  7. data/lib/redmine-installer/backup.rb +13 -40
  8. data/lib/redmine-installer/cli.rb +92 -61
  9. data/lib/redmine-installer/command.rb +63 -117
  10. data/lib/redmine-installer/configuration.rb +148 -0
  11. data/lib/redmine-installer/database.rb +204 -0
  12. data/lib/redmine-installer/environment.rb +21 -0
  13. data/lib/redmine-installer/errors.rb +7 -0
  14. data/lib/redmine-installer/install.rb +37 -42
  15. data/lib/redmine-installer/logger.rb +83 -0
  16. data/lib/redmine-installer/package.rb +180 -0
  17. data/lib/redmine-installer/patches/ruby.rb +35 -0
  18. data/lib/redmine-installer/patches/tty.rb +16 -0
  19. data/lib/redmine-installer/profile.rb +24 -55
  20. data/lib/redmine-installer/redmine.rb +551 -0
  21. data/lib/redmine-installer/spec/spec.rb +81 -0
  22. data/lib/redmine-installer/task.rb +18 -77
  23. data/lib/redmine-installer/task_module.rb +12 -0
  24. data/lib/redmine-installer/upgrade.rb +51 -59
  25. data/lib/redmine-installer/utils.rb +46 -233
  26. data/lib/redmine-installer/version.rb +2 -4
  27. data/lib/redmine-installer.rb +69 -56
  28. data/redmine-installer.gemspec +20 -19
  29. data/spec/custom_matchers.rb +21 -0
  30. data/spec/installer_helper.rb +107 -0
  31. data/spec/installer_process.rb +82 -0
  32. data/spec/lib/backup_restore_spec.rb +81 -0
  33. data/spec/lib/install_spec.rb +125 -36
  34. data/spec/lib/upgrade_spec.rb +73 -52
  35. data/spec/packages/redmine-3.1.0.zip +0 -0
  36. data/spec/packages/redmine-3.2.0.zip +0 -0
  37. data/spec/packages/redmine-3.3.0-bad-migration.zip +0 -0
  38. data/spec/packages/redmine-3.3.0.zip +0 -0
  39. data/spec/packages/something-else.zip +0 -0
  40. data/spec/packages_helper.rb +19 -0
  41. data/spec/shared_contexts.rb +13 -0
  42. data/spec/spec_helper.rb +34 -18
  43. metadata +62 -63
  44. data/lib/redmine-installer/config_param.rb +0 -100
  45. data/lib/redmine-installer/error.rb +0 -5
  46. data/lib/redmine-installer/exec.rb +0 -158
  47. data/lib/redmine-installer/ext/module.rb +0 -7
  48. data/lib/redmine-installer/ext/string.rb +0 -15
  49. data/lib/redmine-installer/git.rb +0 -51
  50. data/lib/redmine-installer/helper.rb +0 -5
  51. data/lib/redmine-installer/helpers/generate_config.rb +0 -29
  52. data/lib/redmine-installer/locales/cs.yml +0 -147
  53. data/lib/redmine-installer/locales/en.yml +0 -154
  54. data/lib/redmine-installer/plugin.rb +0 -9
  55. data/lib/redmine-installer/plugins/base.rb +0 -24
  56. data/lib/redmine-installer/plugins/database.rb +0 -180
  57. data/lib/redmine-installer/plugins/email_sending.rb +0 -82
  58. data/lib/redmine-installer/plugins/redmine_plugin.rb +0 -82
  59. data/lib/redmine-installer/plugins/web_server.rb +0 -26
  60. data/lib/redmine-installer/step.rb +0 -16
  61. data/lib/redmine-installer/steps/backup.rb +0 -125
  62. data/lib/redmine-installer/steps/base.rb +0 -79
  63. data/lib/redmine-installer/steps/database_config.rb +0 -15
  64. data/lib/redmine-installer/steps/email_config.rb +0 -11
  65. data/lib/redmine-installer/steps/env_check.rb +0 -20
  66. data/lib/redmine-installer/steps/install.rb +0 -23
  67. data/lib/redmine-installer/steps/load_package.rb +0 -226
  68. data/lib/redmine-installer/steps/move_redmine.rb +0 -22
  69. data/lib/redmine-installer/steps/redmine_root.rb +0 -52
  70. data/lib/redmine-installer/steps/upgrade.rb +0 -57
  71. data/lib/redmine-installer/steps/validation.rb +0 -38
  72. data/lib/redmine-installer/steps/webserver_config.rb +0 -22
  73. data/spec/load_redmine.rb +0 -24
@@ -1,5 +1,3 @@
1
- module Redmine
2
- module Installer
3
- VERSION = '1.0.7'
4
- end
1
+ module RedmineInstaller
2
+ VERSION = '2.0.0.rc1'
5
3
  end
@@ -1,62 +1,75 @@
1
- module Redmine
2
- module Installer
3
- autoload :CLI, 'redmine-installer/cli'
4
- autoload :Task, 'redmine-installer/task'
5
- autoload :Utils, 'redmine-installer/utils'
6
- autoload :Step, 'redmine-installer/step'
7
- autoload :ConfigParams, 'redmine-installer/config_param'
8
- autoload :Plugin, 'redmine-installer/plugin'
9
- autoload :Helper, 'redmine-installer/helper'
10
- autoload :Command, 'redmine-installer/command'
11
- autoload :Exec, 'redmine-installer/exec'
12
- autoload :Profile, 'redmine-installer/profile'
13
- autoload :Git, 'redmine-installer/git'
14
-
15
- # Root of the gem
16
- def self.root_path
17
- @root_path ||= File.expand_path('..', File.dirname(__FILE__))
18
- end
19
-
20
- # Path to locales dir
21
- def self.locales_path
22
- @locales_path ||= File.join(root_path, 'lib', 'redmine-installer', 'locales')
23
- end
24
-
25
- # Locales for I18n
26
- def self.locales
27
- @locales ||= Dir.glob(File.join(locales_path, '*.yml'))
28
- end
29
-
30
- # Default configurations fo I18n gem
31
- def self.set_i18n
32
- I18n.enforce_available_locales = false
33
- I18n.load_path = Redmine::Installer.locales
34
- I18n.locale = :en
35
- I18n.default_locale = :en
36
- end
37
-
38
- def self.print_logo
39
- $stdout.puts <<-PRINT
40
- __ _
41
- _______ ___/ /_ _ (_)__ ___
42
- / __/ -_) _ / ' \\/ / _ \\/ -_)
43
- /_/ \\__/\\_,_/_/_/_/_/_//_/\\__/
44
-
45
-
46
- #{I18n.translate(:powered_by)}
47
-
48
- PRINT
49
- end
1
+ require 'fileutils'
2
+ require 'tempfile'
3
+ require 'bundler'
4
+ require 'ostruct'
5
+ require 'tmpdir'
6
+ require 'pastel'
7
+ require 'yaml'
8
+ require 'zip'
50
9
 
10
+ require 'tty-progressbar'
11
+ require 'tty-spinner'
12
+ require 'tty-prompt'
13
+
14
+ module RedmineInstaller
15
+ autoload :CLI, 'redmine-installer/cli'
16
+ autoload :Task, 'redmine-installer/task'
17
+ autoload :Install, 'redmine-installer/install'
18
+ autoload :Utils, 'redmine-installer/utils'
19
+ autoload :Logger, 'redmine-installer/logger'
20
+ autoload :TaskModule, 'redmine-installer/task_module'
21
+ autoload :Environment, 'redmine-installer/environment'
22
+ autoload :Redmine, 'redmine-installer/redmine'
23
+ autoload :Package, 'redmine-installer/package'
24
+ autoload :Database, 'redmine-installer/database'
25
+ autoload :Configuration, 'redmine-installer/configuration'
26
+ autoload :Upgrade, 'redmine-installer/upgrade'
27
+ autoload :Command, 'redmine-installer/command'
28
+ autoload :Profile, 'redmine-installer/profile'
29
+ autoload :Backup, 'redmine-installer/backup'
30
+
31
+ # Settings
32
+ MIN_SUPPORTED_RUBY = '2.1.0'
33
+
34
+ def self.logger
35
+ @logger ||= RedmineInstaller::Logger.new
36
+ end
37
+
38
+ def self.prompt
39
+ @prompt ||= TTY::Prompt.new
40
+ end
41
+
42
+ def self.pastel
43
+ @pastel ||= Pastel.new
44
+ end
45
+
46
+ def self.print_logo
47
+ puts <<-PRINT
48
+ __ _
49
+ _______ ___/ /_ _ (_)__ ___
50
+ / __/ -_) _ / ' \\/ / _ \\/ -_)
51
+ /_/ \\__/\\_,_/_/_/_/_/_//_/\\__/
52
+
53
+
54
+ Powered by EasyRedmine
55
+
56
+ PRINT
51
57
  end
52
58
  end
53
59
 
60
+
54
61
  # Requirements
55
- require 'i18n'
56
62
  require 'redmine-installer/version'
57
- require 'redmine-installer/error'
58
- require 'redmine-installer/ext/string'
59
- require 'redmine-installer/ext/module'
60
- require 'redmine-installer/install'
61
- require 'redmine-installer/upgrade'
62
- require 'redmine-installer/backup'
63
+ require 'redmine-installer/errors'
64
+
65
+ # Patches
66
+ require 'redmine-installer/patches/ruby'
67
+ require 'redmine-installer/patches/tty'
68
+
69
+ if ENV['REDMINE_INSTALLER_SPEC']
70
+ require 'redmine-installer/spec/spec'
71
+ end
72
+
73
+ Kernel.at_exit do
74
+ RedmineInstaller.logger.finish
75
+ end
@@ -1,32 +1,33 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'redmine-installer/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "redmine-installer"
8
- spec.version = Redmine::Installer::VERSION
9
- spec.authors = ["Ondřej Moravčík"]
10
- spec.email = ["moravcik.ondrej@gmail.com"]
11
- spec.summary = %q{Easy way how install/upgrade redmine or plugin.}
12
- spec.description = %q{Redmine-installer can fully install/upgrade redmine and will
13
- generate template for different server. All actions can be saved
14
- for further use.}
15
- spec.homepage = "https://github.com/easyredmine/redmine-installer"
16
- spec.license = "MIT"
8
+ spec.name = 'redmine-installer'
9
+ spec.version = RedmineInstaller::VERSION
10
+ spec.authors = ['Ondřej Moravčík']
11
+ spec.email = ['moravcik.ondrej@gmail.com']
12
+ spec.summary = %q{Easy way how install/upgrade Redmine, EasyRedmine or EasyProject.}
13
+ spec.description = %q{}
14
+ spec.homepage = 'https://github.com/easyredmine/redmine-installer'
15
+ spec.license = 'MIT'
17
16
 
18
17
  spec.files = `git ls-files -z`.split("\x0")
19
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '>= 2.1.0'
22
23
 
23
- spec.add_runtime_dependency "ansi"
24
- spec.add_runtime_dependency "gli"
25
- spec.add_runtime_dependency "i18n"
26
- spec.add_runtime_dependency "notifier"
27
- spec.add_runtime_dependency "ruby-progressbar"
28
- spec.add_runtime_dependency "rubyzip"
24
+ spec.add_runtime_dependency 'commander'
25
+ spec.add_runtime_dependency 'tty-prompt', '~> 0.10.0'
26
+ spec.add_runtime_dependency 'tty-spinner', '~> 0.4.1'
27
+ spec.add_runtime_dependency 'tty-progressbar', '~> 0.10.1'
28
+ spec.add_runtime_dependency 'rubyzip'
29
+ spec.add_runtime_dependency 'pastel'
29
30
 
30
- spec.add_development_dependency "bundler", "~> 1.6"
31
- spec.add_development_dependency "rake"
31
+ spec.add_development_dependency 'bundler', '~> 1.11'
32
+ spec.add_development_dependency 'rake'
32
33
  end
@@ -0,0 +1,21 @@
1
+ require 'rspec/expectations'
2
+
3
+ RSpec::Matchers.define :have_output do |text|
4
+ match do |process|
5
+ expect(process.get(text)).to include(text)
6
+ end
7
+
8
+ failure_message do |process|
9
+ "expected that \"#{process.last_get_return}\" would contains: #{text}"
10
+ end
11
+ end
12
+
13
+ RSpec::Matchers.define :have_output_in do |text, second|
14
+ match do |process|
15
+ expect(process.get(text, max_wait: second)).to include(text)
16
+ end
17
+
18
+ failure_message do |process|
19
+ "expected that \"#{process.last_get_return}\" would contains: #{text} in #{second}s"
20
+ end
21
+ end
@@ -0,0 +1,107 @@
1
+ module InstallerHelper
2
+
3
+ def db_username
4
+ ENV['SPEC_DB_USERNAME'].to_s
5
+ end
6
+
7
+ def db_password
8
+ ENV['SPEC_DB_PASSWORD'].to_s
9
+ end
10
+
11
+ def expected_output(text)
12
+ expect(@process).to have_output(text)
13
+ end
14
+
15
+ def expected_output_in(text, max_wait)
16
+ expect(@process).to have_output_in(text, max_wait)
17
+ end
18
+
19
+ def write(text)
20
+ @process.write(text + "\n")
21
+ end
22
+
23
+ # Be carefull - this could have later unpredictable consequences on stdin
24
+ def select_choice
25
+ @process.write(' ')
26
+ # @process.write("\r")
27
+ # @process.write("\r\n")
28
+ end
29
+
30
+ def go_down
31
+ write(TTY::Prompt::Reader::Codes::KEY_DOWN)
32
+ end
33
+
34
+ def expected_successful_configuration
35
+ expected_output('Creating database configuration')
36
+ expected_output('What database do you want use?')
37
+ expected_output('‣ MySQL')
38
+
39
+ write(TTY::Prompt::Reader::Codes::KEY_DOWN)
40
+ expected_output('‣ PostgreSQL')
41
+ select_choice
42
+
43
+ expected_output('Database:')
44
+ write('test')
45
+
46
+ expected_output('Host: (localhost)')
47
+ write('')
48
+
49
+ expected_output('Username:')
50
+ write(db_username)
51
+
52
+ expected_output('Password:')
53
+ write(db_password)
54
+
55
+ expected_output('Encoding: (utf8)')
56
+ write('')
57
+
58
+ expected_output('Port: (5432)')
59
+ write('')
60
+
61
+ expected_output('Creating email configuration')
62
+ expected_output('Which service to use for email sending?')
63
+ expected_output('‣ Nothing')
64
+ select_choice
65
+ end
66
+
67
+ def expected_successful_installation_or_upgrade(db_creating: false)
68
+ expected_output_in('--> Bundle install', 50)
69
+ expected_output_in('--> Database creating', 50) if db_creating
70
+ expected_output_in('--> Database migrating', 50)
71
+ expected_output_in('--> Plugins migration', 50)
72
+ expected_output_in('--> Generating secret token', 50)
73
+
74
+ expected_output('Cleaning root ... OK')
75
+ expected_output('Moving redmine to target directory ... OK')
76
+ expected_output('Cleanning up ... OK')
77
+ expected_output('Moving installer log ... OK')
78
+ end
79
+
80
+ def expected_successful_installation
81
+ expected_output('Redmine installing')
82
+ expected_successful_installation_or_upgrade(db_creating: true)
83
+ expected_output('Redmine was installed')
84
+ end
85
+
86
+ def expected_successful_upgrade
87
+ expected_output('Redmine upgrading')
88
+ expected_successful_installation_or_upgrade
89
+ expected_output('Redmine was upgraded')
90
+
91
+ expected_output('Do you want save steps for further use?')
92
+ write('n')
93
+ end
94
+
95
+ def expected_redmine_version(version)
96
+ Dir.chdir(@redmine_root) do
97
+ out = `rails runner "puts Redmine::VERSION.to_s"`
98
+ expect($?.success?).to be_truthy
99
+ expect(out).to include(version)
100
+ end
101
+ end
102
+
103
+ def wait_for_stdin_buffer
104
+ sleep 0.5
105
+ end
106
+
107
+ end
@@ -0,0 +1,82 @@
1
+ require 'childprocess'
2
+
3
+ class InstallerProcess
4
+
5
+ attr_reader :stdout, :last_get_return
6
+
7
+ def initialize(command, *args)
8
+ tempfile_out = File.open('redmine-installer-out', 'w')
9
+ tempfile_err = File.open('redmine-installer-err', 'w')
10
+
11
+ tempfile_out.sync = true
12
+ tempfile_err.sync = true
13
+
14
+ @process = ChildProcess.build('bin/redmine', command, *args.flatten.compact)
15
+ @process.io.stdout = tempfile_out
16
+ @process.io.stderr = tempfile_err
17
+ @process.environment['REDMINE_INSTALLER_SPEC'] = '1'
18
+ @process.environment['REDMINE_INSTALLER_LOGFILE'] = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log.log'))
19
+ @process.duplex = true
20
+ @process.detach = true
21
+
22
+ # Because of file description is shared with redmine installer
23
+ # so changing posiiotn has effect fot both processes
24
+ @stdout = File.open(tempfile_out.path)
25
+
26
+ @last_get_return = ''
27
+ @buffer = ''
28
+ @seek = 0
29
+ end
30
+
31
+ def run
32
+ start
33
+ yield
34
+ ensure
35
+ stop
36
+ end
37
+
38
+ def start
39
+ @process.start
40
+ end
41
+
42
+ def stop
43
+ @process.stop
44
+ end
45
+
46
+ def write(text)
47
+ @process.io.stdin << text
48
+
49
+ # @process.io.stdin.puts(text)
50
+ # @process.io.stdin.flush
51
+
52
+ # @process.io.stdin.syswrite(text + "\n")
53
+ # @process.io.stdin.flush
54
+
55
+ # @process.io.stdin.write_nonblock(text + "\n")
56
+ end
57
+
58
+ def get(*args)
59
+ @last_get_return = _get(*args)
60
+ end
61
+
62
+ private
63
+
64
+ # max_wait in s
65
+ def _get(text, max_wait: 10)
66
+ wait_to = Time.now + max_wait
67
+ while Time.now < wait_to
68
+ @buffer << @stdout.read
69
+ index = @buffer.rindex(text)
70
+
71
+ if index
72
+ break
73
+ # return @buffer.slice!(0, index+text.size)
74
+ else
75
+ sleep 0.5
76
+ end
77
+ end
78
+
79
+ @buffer
80
+ end
81
+
82
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ DATABASE_DUMP = File.join(Dir.tmpdir, 'redmine_installer_database_backup.sql')
4
+
5
+ RSpec.describe 'RedmineInstaller backup / restore', order: :defined do
6
+
7
+ let(:project_count) { 5 }
8
+
9
+ it 'create backup', :install_first, command: 'backup' do
10
+ # First ensure `project_count` project
11
+ Dir.chdir(@redmine_root) do
12
+ out = `rails runner "
13
+ Project.delete_all
14
+
15
+ #{project_count}.times do |i|
16
+ p = Project.new
17
+ p.name = 'Test ' + i.to_s
18
+ p.identifier = 'test_' + i.to_s
19
+ p.save(validate: false)
20
+ end
21
+
22
+ puts Project.count
23
+ "`
24
+
25
+ expect($?.success?).to be_truthy
26
+ expect(out.to_i).to eq(project_count)
27
+ end
28
+
29
+ # Backup database
30
+ expected_output('Path to redmine root:')
31
+ write(@redmine_root)
32
+ expected_output('Data backup')
33
+ go_down
34
+ expected_output('‣ Only database')
35
+ select_choice
36
+ expected_output('Where to save backup:')
37
+ write(@backup_dir)
38
+ expected_output('Database backuping')
39
+ expected_output('Database backed up')
40
+
41
+ # Ensure 0 project (database is shared with all tests)
42
+ Dir.chdir(@redmine_root) do
43
+ out = `rails runner "
44
+ Project.delete_all
45
+ puts Project.count
46
+ "`
47
+
48
+ expect($?.success?).to be_truthy
49
+ expect(out.to_i).to eq(0)
50
+ end
51
+
52
+ # Save backup (after test end - all backup will be deleted)
53
+ dump = Dir.glob(File.join(@backup_dir, '*', '*')).last
54
+ expect(dump).to end_with('test.sql')
55
+
56
+ FileUtils.rm_f(DATABASE_DUMP)
57
+ FileUtils.cp(dump, DATABASE_DUMP)
58
+ end
59
+
60
+ it 'restore', command: 'install', args: [package_v310, '--database-dump', DATABASE_DUMP] do
61
+ expected_output('Path to redmine root:')
62
+ write(@redmine_root)
63
+
64
+ expected_successful_configuration
65
+
66
+ expected_output('Database dump will be loaded.')
67
+ expected_output('‣ Skip dump loading')
68
+
69
+ go_down
70
+ expected_output('‣ I am aware of this.')
71
+ select_choice
72
+
73
+ expected_output_in('Redmine was installed', 500)
74
+
75
+ Dir.chdir(@redmine_root) do
76
+ out = `rails runner "puts Project.count"`
77
+ expect(out.to_i).to eq(project_count)
78
+ end
79
+ end
80
+
81
+ end