Add infrastructure for using WAL-E
authorTom Hughes <tom@compton.nu>
Tue, 10 Oct 2017 19:43:46 +0000 (20:43 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 10 Oct 2017 19:49:20 +0000 (20:49 +0100)
cookbooks/db/metadata.rb
cookbooks/db/recipes/base.rb
cookbooks/db/templates/default/wal-e.erb [new file with mode: 0644]
cookbooks/python/recipes/default.rb
cookbooks/python/resources/package.rb

index 2a7f0c6..94c044f 100644 (file)
@@ -9,3 +9,4 @@ supports          "ubuntu"
 depends           "postgresql"
 depends           "web"
 depends           "git"
+depends           "python"
index f24e42e..92d74f8 100644 (file)
 
 include_recipe "postgresql"
 include_recipe "git"
+include_recipe "python"
 
 passwords = data_bag_item("db", "passwords")
+wal_secrets = data_bag_item("db", "wal-secrets")
 
 postgresql_munin "openstreetmap" do
   cluster node[:db][:cluster]
@@ -72,3 +74,21 @@ link "/usr/lib/postgresql/#{db_version}/lib/libpgosm.so" do
   owner "root"
   group "root"
 end
+
+package "lzop"
+
+python_package "wal-e" do
+  python_version "3"
+end
+
+python_package "boto" do
+  python_version "3"
+end
+
+template "/usr/local/bin/openstreetmap-wal-e" do
+  source "wal-e.erb"
+  owner "root"
+  group "postgres"
+  mode 0o750
+  variables :s3_key => wal_secrets["s3_key"]
+end
diff --git a/cookbooks/db/templates/default/wal-e.erb b/cookbooks/db/templates/default/wal-e.erb
new file mode 100644 (file)
index 0000000..93f3144
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# DO NOT EDIT - This file is being maintained by Chef
+
+export WALE_S3_PREFIX="s3://openstreetmap-wal/"
+export AWS_ACCESS_KEY_ID="AKIAIQX2LTDOBIW4CZUQ"
+export AWS_SECRET_ACCESS_KEY="<%= @s3_key %>"
+export AWS_REGION="eu-west-2"
+
+exec /usr/local/bin/wal-e "$@"
index 14b1e5a..a2eaf1c 100644 (file)
@@ -19,3 +19,6 @@
 
 package "python"
 package "python-pip"
+
+package "python3"
+package "python3-pip"
index 76a6af7..d6431c8 100644 (file)
@@ -21,24 +21,29 @@ default_action :install
 
 property :package_name, :kind_of => String, :name_property => true
 property :version, :kind_of => String
+property :python_version, :kind_of => String
 
 action :install do
   if version.nil?
     execute "pip-install-#{name}" do
-      command "pip install #{new_resource.package_name}"
-      not_if "pip show #{new_resource.package_name}"
+      command "#{pip_command} install #{new_resource.package_name}"
+      not_if "#{pip_command} show #{new_resource.package_name}"
     end
   else
     execute "pip-install-#{name}" do
-      command "pip install #{new_resource.package_name}==#{new_resource.version}"
-      not_if "pip show #{new_resource.package_name} | fgrep -q #{new_resource.version}"
+      command "#{pip_command} install #{new_resource.package_name}==#{new_resource.version}"
+      not_if "#{pip_command} show #{new_resource.package_name} | fgrep -q #{new_resource.version}"
     end
   end
 end
 
 action :remove do
   execute "pip-uninstall-#{name}" do
-    command "pip uninstall #{new_resource.package_name}"
-    only_if "pip show #{new_resource.package_name}"
+    command "#{pip_command} uninstall #{new_resource.package_name}"
+    only_if "#{pip_command} show #{new_resource.package_name}"
   end
 end
+
+def pip_command
+  "pip#{python_version}"
+end