Class: UpgradeChecker

Inherits:
Object
  • Object
show all
Includes:
Thor::Shell
Defined in:
lib/docker-sync/upgrade_check.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUpgradeChecker

Returns a new instance of UpgradeChecker.


9
10
11
# File 'lib/docker-sync/upgrade_check.rb', line 9

def initialize
  @config = DockerSync::GlobalConfig.load
end

Class Method Details

.get_current_versionObject


41
42
43
44
45
46
# File 'lib/docker-sync/upgrade_check.rb', line 41

def self.get_current_version
  path = File.expand_path('../../../', __FILE__)
  version = File.read("#{path}/VERSION")
  version.strip
  version
end

Instance Method Details

#check_and_warnObject


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/docker-sync/upgrade_check.rb', line 55

def check_and_warn
  return if ENV['DOCKER_SYNC_SKIP_UPGRADE']
  # this is the upgrade hook for the unison-unox introduction / rename of unison
  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.1.0')
    Thor::Shell::Basic.new.say_status 'warning', 'Please be aware that with the strategy "unison" is now called unison-onesided and you might need to migrate. See https://github.com/EugenMayer/docker-sync/wiki/Migration-Guide for more informations', :red
    unless Thor::Shell::Basic.new.yes?('Shall we continue? (y/N)')
      exit 1
    end
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.2.0')
    Thor::Shell::Basic.new.say_status 'warning', "A lot changed with 0.2.x! Unison is the default sync, unison-onesided has been REMOVED. If you have been using rsync, have been using unison excludes or you are not sure, please read the upgrade guide or your setup will go lala! : \n\n_Please_ read :): https://github.com/EugenMayer/docker-sync/wiki/1.2-Upgrade-Guide\n\n", :red
    unless Thor::Shell::Basic.new.yes?('Shall we continue - DID you read it? (y/N)')
      exit 1
    end
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.3.0')
    Thor::Shell::Basic.new.say_status 'warning', "The installation progress of docker-sync 0.3.0 has changed, brew is now mandatory - you need to uninstall unox ! : \n\n_Please_ read :): https://github.com/EugenMayer/docker-sync/wiki/1.2-Upgrade-Guide\n\n", :red

    cmd1 = 'sudo rm -f /usr/local/bin/unison-fsmonitor && brew tap eugenmayer/dockersync && brew install eugenmayer/dockersync/unox'
    Thor::Shell::Basic.new.say_status 'ok', cmd1, :rwhite

    if Thor::Shell::Basic.new.yes?('I will reinstall unox for you using the above command (y/N)')
      system cmd1
    else
      raise('Please reinstall docker-sync yourself')
    end
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.4.0')
    Thor::Shell::Basic.new.say_status 'warning', "docker-sync has a new superior default sync strategy native_osx - consider switching to it no matter if you used unison or rsync. \nIt does no longer need Unison/Unox on OSX - no brew needed either. And its a lot thriftier ! \n\n_Please_ read :): https://github.com/EugenMayer/docker-sync/wiki/1.2-Upgrade-Guide\n\n", :red

    unless Thor::Shell::Basic.new.yes?('Shall we continue - DID you read it - really :) ? (y/N)')
      exit 1
    end
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.4.1')
    Thor::Shell::Basic.new.say_status 'warning', "Please add :nocopy to every named-volume mount you defined in your docker-compose-dev.yml! \n\nWhy? : https://github.com/EugenMayer/docker-sync/wiki/2.-Configuration#why-nocopy-is-important\n\n", :red

    unless Thor::Shell::Basic.new.yes?('Did you fix your docker-compose-dev.yml? (y/N)')
      exit 1
    end
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.4.2')
    checker = UpdateChecker.new
    checker.check_unison_image

    Thor::Shell::Basic.new.say_status 'warning', "The native_osx is NOW ONLY for docker-for-mac, this is due to https://github.com/EugenMayer/docker-sync/issues/346\n\nThat means that unison is picked as a default automatically if you use docker-machine", :red

    unless Thor::Shell::Basic.new.yes?('Just wanted you to know that! (y/N)')
      exit 1
    end
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.4.3')
    checker = UpdateChecker.new
    checker.check_unison_image
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.4.4')
    checker = UpdateChecker.new
    checker.check_unison_image
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.4.5')
    checker = UpdateChecker.new
    checker.check_unison_image
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.5.5')
    checker = UpdateChecker.new
    checker.check_unison_image

    Thor::Shell::Basic.new.say_status 'warning', "There has been a major unison update. Please clean and restart all your stacks. If you are using the unison strategy, please upgrade unison by doing 'brew update && brew upgrade unison' to upgrade to 2.51.2", :red

    unless Thor::Shell::Basic.new.yes?('Just wanted you to know that! (y/N)')
      exit 1
    end
  end

  if Gem::Version.new(last_upgraded_version) <  Gem::Version.new('0.5.6')
    checker = UpdateChecker.new
    checker.check_unison_image

    Thor::Shell::Basic.new.say_status 'warning', "If you are upgrading from 0.5.4 or below, please run `brew update && brew upgrade unison` AND `docker-compose down && docker-sync clean` or `docker-sync-stack clean` since you need to recreate the sync container", :red

    unless Thor::Shell::Basic.new.yes?('Sync will fail otherwise. Continue? (y/N)')
      exit 1
    end
  end

  # update the upgrade_status
  @config.update! 'upgrade_status' => "#{UpgradeChecker.get_current_version}"
end

#docker_sync_update_checkObject


48
49
50
51
52
53
# File 'lib/docker-sync/upgrade_check.rb', line 48

def docker_sync_update_check
  gem_name = 'docker-sync'
  current_version = UpgradeChecker.get_current_version
  checker = GemUpdateChecker::Client.new(gem_name, current_version)
  return checker
end

#last_upgraded_versionObject


21
22
23
# File 'lib/docker-sync/upgrade_check.rb', line 21

def last_upgraded_version
  @config['upgrade_status']
end

#runObject


13
14
15
16
17
18
19
# File 'lib/docker-sync/upgrade_check.rb', line 13

def run
  return if ENV['DOCKER_SYNC_SKIP_UPGRADE']
  unless should_run
    return
  end
  check_and_warn
end

#should_runObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/docker-sync/upgrade_check.rb', line 25

def should_run
  # get the update_status which is the version of the update hook which has been run already
  upgrade_status = last_upgraded_version
  if upgrade_status == ''
    @config.update! 'upgrade_status' => "#{UpgradeChecker.get_current_version}"
    return
  end

  if Gem::Version.new(upgrade_status) < Gem::Version.new(UpgradeChecker.get_current_version) # thats how we compare the version
    return true
  end

  return false
end