lib/rspec/hive/rake_tasks/docker.rake in rspec-hive-0.6.2 vs lib/rspec/hive/rake_tasks/docker.rake in rspec-hive-0.6.3
- old
+ new
@@ -46,27 +46,27 @@
end
end
end
namespace :docker do
- desc 'Runs docker using hive config file.'\
- ' It assumes your docker-machine is running.'
+ desc 'Runs docker using hive config file.' \
+ ' It assumes your docker-machine is running.'
task :run do
raise 'Command `docker` not found.'.red unless system('which docker')
config_filepath = ENV['CONFIG_FILE'] || File.join('config', 'rspec-hive.yml')
unless File.exist? config_filepath
- raise "There's no config file #{config_filepath} please"\
- 'generate default or provide custom config.'.red
+ raise "There's no config file #{config_filepath} please" \
+ 'generate default or provide custom config.'.red
end
interpolated = ERB.new(File.read(config_filepath)).result
config = YAML.safe_load(interpolated)['hive']
docker_image_name = ENV['DOCKER_IMAGE_NAME'] || 'nielsensocial/hive'
- cmd = "docker run -v #{config['host_shared_directory_path']}:"\
- "#{config['docker_shared_directory_path']}"\
+ cmd = "docker run -v #{config['host_shared_directory_path']}:" \
+ "#{config['docker_shared_directory_path']}" \
" -d -p #{config['port']}:10000 #{docker_image_name}"
puts "Running `#{cmd}`...".green
system(cmd)
end
@@ -82,17 +82,18 @@
system(cmd)
end
def container_id
return ENV['CONTAINER_ID'] if ENV['CONTAINER_ID']
+
docker_conatiners = `docker ps`.lines
- if docker_conatiners.size != 2
- raise 'There is more than 1 instance of docker container running (or no running docker containers). '\
- 'Check `docker ps` and stop containers that are not in use right now or specify CONTAINER_ID '\
- 'and run this command again.'.red
- else
+ if docker_conatiners.size == 2
docker_conatiners[1].split[0]
+ else
+ raise 'There is more than 1 instance of docker container running (or no running docker containers). ' \
+ 'Check `docker ps` and stop containers that are not in use right now or specify CONTAINER_ID ' \
+ 'and run this command again.'.red
end
end
desc 'Load Hive UDFS (user defined functions) onto docker.'
task :load_udfs, [:udfs_path] do |_t, args|
@@ -101,14 +102,16 @@
interpolated = ERB.new(File.read(config_filepath)).result
config = YAML.safe_load(interpolated)['hive']
host_hive_udfs_path = File.join(config['host_shared_directory_path'], 'hive-udfs.jar')
raise 'Please provide UDFS_PATH'.red unless udfs_path
+
if udfs_path.start_with?('s3://')
puts 'Downloading from s3...'.yellow
cmd = "aws s3 ls #{udfs_path}"
raise 'awscli is not configured.'.red unless system(cmd)
+
cmd = "aws s3 cp #{udfs_path} #{host_hive_udfs_path}"
else
puts 'Copying from local directory...'.yellow
cmd = "cp #{udfs_path} #{host_hive_udfs_path}"
end