diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c04ea59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vagrant +.bundle +tmp/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/attributes/default.rb b/attributes/default.rb new file mode 100644 index 0000000..be0098f --- /dev/null +++ b/attributes/default.rb @@ -0,0 +1,8 @@ +default[:valhalla][:user] = 'valhalla' +default[:valhalla][:base_dir] = '/data' +default[:valhalla][:s3bucket] = 'mapzen.valhalla' +default[:valhalla][:s3bucket_dir] = 'prod' +default[:valhalla][:log_dir] = "#{node[:valhalla][:base_dir]}/logs" +default[:valhalla][:tile_dir] = "#{node[:valhalla][:base_dir]}/valhalla" +default[:valhalla][:transit_dir] = "#{node[:valhalla][:base_dir]}/valhalla/transit" +default[:valhalla][:elevation_dir] = "#{node[:valhalla][:base_dir]}/valhalla/elevation" diff --git a/metadata.rb b/metadata.rb new file mode 100644 index 0000000..669768e --- /dev/null +++ b/metadata.rb @@ -0,0 +1,7 @@ +name 'mapzen_valhalla-docker' +maintainer 'Mapzen' +maintainer_email 'grant@mapzen.com' +license 'All rights reserved' +description 'Installs/Configures valhalla host systems' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version '0.0.1' diff --git a/recipes/default.rb b/recipes/default.rb new file mode 100644 index 0000000..563b455 --- /dev/null +++ b/recipes/default.rb @@ -0,0 +1,31 @@ +# +# Cookbook Name:: mapzen_valhalla-docker +# Recipe:: default +# +# Copyright 2016, Mapzen +# +# All rights reserved - Do Not Redistribute +# + +# make the valhalla user +user node[:valhalla][:user][:name] do + manage_home false + home node[:valhalla][:base_dir] + not_if { node[:valhalla][:user][:name] == 'root' } +end + +# set up directory structure +dirs = [ + node[:valhalla][:base_dir], + node[:valhalla][:log_dir], + node[:valhalla][:tile_dir], + node[:valhalla][:transit_dir], + node[:valhalla][:elevation_dir] +] + +dirs.each do |d| + directory d do + owner node[:valhalla][:user] + recursive true + end +end diff --git a/recipes/get_routing_tiles.rb b/recipes/get_routing_tiles.rb new file mode 100644 index 0000000..bc8cd4c --- /dev/null +++ b/recipes/get_routing_tiles.rb @@ -0,0 +1,34 @@ +# +# Cookbook Name:: mapzen_valhalla-docker +# Recipe:: default +# +# Copyright 2016, Mapzen +# +# All rights reserved - Do Not Redistribute +# + +# go get the tiles +execute 'pull tiles' do + cwd node[:valhalla][:base_dir] + command <<-EOH + echo -n https://s3.amazonaws.com/#{node[:valhalla][:s3bucket]}/#{node[:valhalla][:s3bucket_dir]}/ > latest_tiles.txt && + aws --region us-east-1 s3 ls s3://#{node[:valhalla][:s3bucket]}/#{node[:valhalla][:s3bucket_dir]}/ | grep -F tiles_ | awk '{print $4}' | sort | tail -n 1 >> latest_tiles.txt + EOH +end + +# open them up +execute 'extract tiles' do + cwd node[:valhalla][:base_dir] + command <<-EOH + rm -rf tmp_tiles old_tiles && + mkdir tmp_tiles && + curl $(cat latest_tiles.txt) 2>#{node[:valhalla][:log_dir]}/curl_tiles.log | tar xzp -C tmp_tiles 2>#{node[:valhalla][:log_dir]}/untar_tiles.log + EOH + retries 3 +end + +# move them into place +execute 'move tiles' do + cwd node[:valhalla][:base_dir] + command "mv #{node[:valhalla][:tile_dir]} old_tiles; mv tmp_tiles #{node[:valhalla][:tile_dir]}" +end