lib/commands/checkup.rb in nutella_framework-0.6.21 vs lib/commands/checkup.rb in nutella_framework-0.7.0
- old
+ new
@@ -10,11 +10,11 @@
# First check that we have all the tools we need to run nutella
return unless all_dependencies_installed?
# Check if we have a local broker installed
# and install one if we don't
- if File.directory? Nutella.config['broker_dir']
+ if broker_exists
console.info 'You have a local broker installed. Yay!'
else
console.warn 'You don\'t seem to have a local broker installed so we are going to go ahead and install one for you. This might take some time...'
unless install_local_broker
console.error 'Whoops...something went wrong while installing the broker'
@@ -31,33 +31,37 @@
private
+ def broker_exists
+ # Check if Docker image for the broker was already pulled
+ if `docker images matteocollina/mosca:v2.3.0 --format "{{.ID}}"` != ""
+ # If so, check that a broker configuration exists and create one if it doesn't
+ Nutella.config['broker'] = '127.0.0.1' if Nutella.config['broker'].nil?
+ true
+ else
+ false
+ end
+ end
+
+
def install_local_broker
- # Clone, cd and npm install
- broker_version = 'v0.28.1'
- out1 = system "git clone -b #{broker_version} --depth 1 git://github.com/mcollina/mosca.git #{Nutella.config['broker_dir']} > /dev/null 2>&1"
- Dir.chdir(Nutella.config['broker_dir'])
- out2 = system 'npm install > /dev/null 2>&1'
-
- # Add startup script and make it executable
- File.open('startup', 'w') { |file| file.write("#!/bin/sh\n\nBASEDIR=$(dirname $0)\n$BASEDIR/bin/mosca --disable-stats --http-port 1884 > /dev/null 2>&1 &\necho $! > $BASEDIR/bin/.pid\n") }
- File.chmod( 0755, 'startup' )
-
- # Write configuration into config.json
+ # Docker pull to install
+ system "docker pull matteocollina/mosca:v2.3.0 > /dev/null 2>&1"
+ # Write broker setting inside config.json
Nutella.config['broker'] = '127.0.0.1'
- out1 && out2
end
def all_dependencies_installed?
- # Node version lambda
- node_semver = lambda do
- out = `node --version`
- out[0] = ''
- Semantic::Version.new out
+ # Docker version lambda
+ docker_semver = lambda do
+ out = `docker --version`
+ token = out.split(' ')
+ token[2].slice(0..1)
+ Semantic::Version.new token[2].slice(0..1).concat('.0.0')
end
# Git version lambda
git_semver = lambda do
out = `git --version`
out.slice!(0,12)
@@ -79,10 +83,10 @@
out = `mongod --version`
out.slice!(0,12)
Semantic::Version.new out[0..4]
end
# Check versions
- return true if check_version?('node', '0.10.0', node_semver) && check_version?('git', '1.8.0', git_semver) && check_version?('tmux', '1.8.0', tmux_semver) && check_version?('mongodb', '2.6.9', mongo_semver)
+ return true if check_version?('docker', '17.0.0', docker_semver) && check_version?('git', '1.8.0', git_semver) && check_version?('tmux', '1.8.0', tmux_semver) && check_version?('mongodb', '2.6.9', mongo_semver)
# If even one of the checks fails, return false
false
end