Skip to content

Commit

Permalink
fix update check and introduce update check for 0.5.5, fix image down…
Browse files Browse the repository at this point in the history
…load for hostsync/unison since its only one now. Fix version parsing not stripping newlines and does not trim, fix exception if update_last_check is not set
  • Loading branch information
EugenMayer committed Mar 15, 2018
1 parent 29e545d commit 114252a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ rvm:
services: docker

before_install:
- docker pull eugenmayer/unison:hostsync_0.2
- docker pull eugenmayer/unison:latest
- docker pull eugenmayer/unison:2.51.2.0
- docker pull eugenmayer/rsync

script: bundle exec rspec --format=documentation
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.5
0.5.5
2 changes: 1 addition & 1 deletion lib/docker-sync/sync_strategy/native_osx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(sync_name, options)

# TODO: remove this when we have a more stable image, but for now, we need this
uc = UpdateChecker.new
uc.check_unison_hostsync_image(true)
uc.check_unison_image

begin
Dependencies::Docker.ensure!
Expand Down
18 changes: 3 additions & 15 deletions lib/docker-sync/update_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def run
# do not check the image if its the first run - since this it will be downloaded anyway
unless @config.first_run?
unless has_internet?
check_unison_hostsync_image
check_unison_image
check_rsync_image
# stop if there was an update
Expand All @@ -47,6 +46,8 @@ def has_internet?
def should_run
return false unless has_internet?
now = DateTime.now
return true if @config['update_last_check'].nil?

last_check = DateTime.iso8601(@config['update_last_check'])
check_after_days = 2
if now - last_check > check_after_days
Expand All @@ -69,24 +70,11 @@ def check_rsync_image

end

def check_unison_hostsync_image(silent = false)
return if ENV['DOCKER_SYNC_SKIP_UPDATE']
say_status 'ok','Checking if a newer native_osx (unison:hostsync_0.2) image is available' unless silent

if system("docker pull eugenmayer/unison:hostsync_0.2 | grep 'Downloaded newer image for'")
say_status 'ok', 'Downloaded newer image for native_osx', :green unless silent
@newer_image_found = true
else
say_status 'ok', 'No newer image found - current image is up to date.' unless silent
end

end

def check_unison_image
return if ENV['DOCKER_SYNC_SKIP_UPDATE']
say_status 'ok','Checking if a newer unison image is available'

if system("docker pull eugenmayer/unison | grep 'Downloaded newer image for'")
if system("docker pull eugenmayer/unison:2.51.2.0 | grep 'Downloaded newer image for'")
say_status 'ok', 'Downloaded newer image for unison', :green
@newer_image_found = true
else
Expand Down
23 changes: 18 additions & 5 deletions lib/docker-sync/upgrade_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def should_run

def self.get_current_version
path = File.expand_path('../../../', __FILE__)
return File.read("#{path}/VERSION")
version = File.read("#{path}/VERSION")
version.gsub!(/ *\n+/, "\n")
version.strip
end

def docker_sync_update_check
Expand Down Expand Up @@ -98,7 +100,7 @@ def check_and_warn

if Gem::Version.new(last_upgraded_version) < Gem::Version.new('0.4.2')
checker = UpdateChecker.new
checker.check_unison_hostsync_image
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

Expand All @@ -109,17 +111,28 @@ def check_and_warn

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

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

if Gem::Version.new(last_upgraded_version) < Gem::Version.new('0.4.5')
checker = UpdateChecker.new
checker.check_unison_hostsync_image
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

# update the upgrade_status
Expand Down

0 comments on commit 114252a

Please sign in to comment.