From b0d9abfbd0d3b78db57f09a8976b10a446542a99 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 10 Oct 2017 20:43:46 +0100 Subject: [PATCH] Add infrastructure for using WAL-E --- cookbooks/db/metadata.rb | 1 + cookbooks/db/recipes/base.rb | 20 ++++++++++++++++++++ cookbooks/db/templates/default/wal-e.erb | 10 ++++++++++ cookbooks/python/recipes/default.rb | 3 +++ cookbooks/python/resources/package.rb | 17 +++++++++++------ 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 cookbooks/db/templates/default/wal-e.erb diff --git a/cookbooks/db/metadata.rb b/cookbooks/db/metadata.rb index 2a7f0c694..94c044fad 100644 --- a/cookbooks/db/metadata.rb +++ b/cookbooks/db/metadata.rb @@ -9,3 +9,4 @@ supports "ubuntu" depends "postgresql" depends "web" depends "git" +depends "python" diff --git a/cookbooks/db/recipes/base.rb b/cookbooks/db/recipes/base.rb index f24e42e93..92d74f86d 100644 --- a/cookbooks/db/recipes/base.rb +++ b/cookbooks/db/recipes/base.rb @@ -19,8 +19,10 @@ 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 index 000000000..93f314498 --- /dev/null +++ b/cookbooks/db/templates/default/wal-e.erb @@ -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 "$@" diff --git a/cookbooks/python/recipes/default.rb b/cookbooks/python/recipes/default.rb index 14b1e5a87..a2eaf1cdb 100644 --- a/cookbooks/python/recipes/default.rb +++ b/cookbooks/python/recipes/default.rb @@ -19,3 +19,6 @@ package "python" package "python-pip" + +package "python3" +package "python3-pip" diff --git a/cookbooks/python/resources/package.rb b/cookbooks/python/resources/package.rb index 76a6af7ec..d6431c87d 100644 --- a/cookbooks/python/resources/package.rb +++ b/cookbooks/python/resources/package.rb @@ -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 -- 2.39.5