Skip to content

Commit

Permalink
Merge pull request #301 from EugenMayer/precondition_strategy
Browse files Browse the repository at this point in the history
implemented precondition os based strategy, implemented brew being ma…
  • Loading branch information
EugenMayer authored Apr 24, 2017
2 parents 4cf3e1c + fe0126b commit 3d43a59
Show file tree
Hide file tree
Showing 21 changed files with 418 additions and 162 deletions.
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
PATH
remote: .
specs:
docker-sync (0.2.3)
docker-sync (0.3.0)
daemons (~> 1.2, >= 1.2.3)
docker-compose (~> 1.0, >= 1.0.2)
dotenv (~> 2.1, >= 2.1.1)
gem_update_checker (~> 0.2.0, >= 0.2.0)
os
terminal-notifier (= 1.6.3)
thor (~> 0.19, >= 0.19.0)

Expand All @@ -15,10 +16,11 @@ GEM
backticks (1.0.0)
daemons (1.2.4)
diff-lcs (1.3)
docker-compose (1.1.4)
docker-compose (1.1.5)
backticks (~> 1.0)
dotenv (2.2.0)
gem_update_checker (0.2.0)
os (1.0.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
Expand All @@ -43,4 +45,4 @@ DEPENDENCIES
rspec

BUNDLED WITH
1.13.7
1.14.6
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.3
0.3.0
1 change: 1 addition & 0 deletions docker-sync.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'terminal-notifier', '1.6.3'
s.add_runtime_dependency 'dotenv', '~> 2.1', '>= 2.1.1'
s.add_runtime_dependency 'daemons', '~> 1.2', '>= 1.2.3'
s.add_runtime_dependency 'os'
end
3 changes: 2 additions & 1 deletion docker_sync.iml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.14.6, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="daemons (v1.2.4, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="docker-compose (v1.1.4, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="docker-compose (v1.1.5, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="dotenv (v2.2.0, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="gem_update_checker (v0.2.0, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="os (v1.0.0, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.5.0, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.5.4, rbenv: 2.2.4) [gem]" level="application" />
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.5.0, rbenv: 2.2.4) [gem]" level="application" />
Expand Down
2 changes: 1 addition & 1 deletion lib/docker-sync.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'docker-sync/config/config_locator'
require 'docker-sync/config/global_config'
require 'docker-sync/config/project_config'
require 'docker-sync/preconditions'
require 'docker-sync/preconditions/strategy'
7 changes: 7 additions & 0 deletions lib/docker-sync/config/project_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def unison_required?
}
end

def rsync_required?
config['syncs'].any? { |name, sync_config|
sync_config['sync_strategy'] == 'rsync'
}
end


private

def validate_config!
Expand Down
112 changes: 0 additions & 112 deletions lib/docker-sync/preconditions.rb

This file was deleted.

24 changes: 24 additions & 0 deletions lib/docker-sync/preconditions/preconditions_linux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module DockerSync
module Preconditions
class Linux
def check_all_preconditions(config)
end

def docker_available
end

def docker_running
end

def fswatch_available
end

def rsync_available
end

def unison_available
end
end

end
end
148 changes: 148 additions & 0 deletions lib/docker-sync/preconditions/preconditions_osx.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
require 'mkmf'
module DockerSync
module Preconditions
class Osx
def check_all_preconditions(config)
return unless should_run_precondition?

docker_available
docker_running

if config.unison_required?
unison_available
end

if config.rsync_required?
rsync_available
fswatch_available
end
end

def docker_available
if (find_executable0 'docker').nil?
raise('Could not find docker binary in path. Please install it, e.g. using "brew install docker" or install docker-for-mac')
end
end

def docker_running
`docker ps`
if $?.exitstatus > 0
raise('No docker daemon seems to be running. Did you start your docker-for-mac / docker-machine?')
end
end

def rsync_available
if should_run_precondition?
if (find_executable0 'rsync').nil?
raise('Could not find rsync binary in path. Please install it, e.g. using "brew install rsync"')
end
end
end

def unison_available
if should_run_precondition?
if (find_executable0 'unison').nil?
cmd1 = 'brew install unison"'

Thor::Shell::Basic.new.say_status 'warning', 'Could not find unison binary in $PATH. Trying to install now', :red
if Thor::Shell::Basic.new.yes?('I will install unison using brew for you? (y/N)')
system cmd1
else
raise('Please install it yourself using: brew install unison')
end
end

unox_available
end
end

def fswatch_available
if should_run_precondition?
if (find_executable0 'fswatch').nil?
cmd1 = 'brew install fswatch"'

Thor::Shell::Basic.new.say_status 'warning', 'No fswatch available. Install it by "brew install fswatch Trying to install now', :red
if Thor::Shell::Basic.new.yes?('I will install fswatch using brew for you? (y/N)')
system cmd1
else
raise('Please install it yourself using: brew install fswatch')
end
end
end

end

private

def should_run_precondition?(silent = false)
unless has_brew?
Thor::Shell::Basic.new.say_status 'inf', 'Not running any precondition checks since you have no brew and that is unsupported. Is all up to you know.', :white unless silent
return false
end
return true
end

def has_brew?
return find_executable0 'brew'
end


def unox_available
if should_run_precondition?
`brew list unox`
if $?.exitstatus > 0
unless (find_executable0 'unison-fsmonitor').nil?
# unox installed, but not using brew, we do not allow that anymore
Thor::Shell::Basic.new.say_status 'error', 'You install unison-fsmonitor (unox) not using brew. Please uninstall it and run docker-sync again, so we can install it for you', :red
exit 1
end
cmd1 = 'brew tap eugenmayer/dockersync && brew install eugenmayer/dockersync/unox'

Thor::Shell::Basic.new.say_status 'warning', 'Could not find unison-fsmonitor (unox) binary in $PATH. Trying to install now', :red
if Thor::Shell::Basic.new.yes?('I will install unox through brew for you? (y/N)')
system cmd1
else
raise('Please install it yourself using: brew tap eugenmayer/dockersync && brew install unox')
end
end
end
end

def install_pip(package, test = nil)
test ? `python -c 'import #{test}'` : `python -c 'import #{package}'`

unless $?.success?
Thor::Shell::Basic.new.say_status 'warning', "Could not find #{package}. Will try to install it using pip", :red
if find_executable0('python') == '/usr/bin/python'
Thor::Shell::Basic.new.say_status 'ok', 'You seem to use the system python, we will need sudo below'
sudo = true
cmd2 = "sudo easy_install pip && sudo pip install #{package}"
else
Thor::Shell::Basic.new.say_status 'ok', 'You seem to have a custom python, using non-sudo commands'
sudo = false
cmd2 = "easy_install pip && pip install #{package}"
end
if sudo
question = "I will ask you for you root password to install #{package} by running (This will ask for sudo, since we use the system python)"
else
question = "I will now install #{package} for you by running"
end

Thor::Shell::Basic.new.say_status 'info', "#{question}: `#{cmd2}\n\n"
if Thor::Shell::Basic.new.yes?('Shall I continue? (y/N)')
system cmd2
if $?.exitstatus > 0
raise("Failed to install #{package}, please file an issue with the output of the error")
end
test ? `python -c 'import #{test}'` : `python -c 'import #{package}'`
unless $?.success?
raise("Somehow I could not successfully install #{package} even though I tried. Please report this issue.")
end
else
raise("Please install #{package} manually, see https://github.com/EugenMayer/docker-sync/wiki/1.-Installation")
end
end
end
end
end
end
Loading

0 comments on commit 3d43a59

Please sign in to comment.