From 343f2f0c08c4e9e414b49e6085da9a494209978f Mon Sep 17 00:00:00 2001 From: Siddharth Date: Wed, 12 Oct 2022 18:01:03 +0530 Subject: [PATCH] elasticache redis and memcache recipes Signed-off-by: Siddharth --- .../elasticache-memcache/README.md | 25 ++++++++++++++ .../attributes/default.rb | 7 ++++ .../elasticache-memcache/metadata.rb | 8 +++++ .../elasticache-memcache/recipes/configure.rb | 34 +++++++++++++++++++ .../elasticache-memcache/recipes/default.rb | 5 +++ .../templates/default/memcached.yml.erb | 7 ++++ custom-cookbooks/elasticache-redis/README.md | 25 ++++++++++++++ .../elasticache-redis/attributes/default.rb | 7 ++++ .../elasticache-redis/metadata.rb | 8 +++++ .../elasticache-redis/recipes/configure.rb | 34 +++++++++++++++++++ .../elasticache-redis/recipes/default.rb | 5 +++ .../templates/default/redis.yml.erb | 3 ++ 12 files changed, 168 insertions(+) create mode 100644 custom-cookbooks/elasticache-memcache/README.md create mode 100644 custom-cookbooks/elasticache-memcache/attributes/default.rb create mode 100644 custom-cookbooks/elasticache-memcache/metadata.rb create mode 100644 custom-cookbooks/elasticache-memcache/recipes/configure.rb create mode 100644 custom-cookbooks/elasticache-memcache/recipes/default.rb create mode 100644 custom-cookbooks/elasticache-memcache/templates/default/memcached.yml.erb create mode 100644 custom-cookbooks/elasticache-redis/README.md create mode 100644 custom-cookbooks/elasticache-redis/attributes/default.rb create mode 100644 custom-cookbooks/elasticache-redis/metadata.rb create mode 100644 custom-cookbooks/elasticache-redis/recipes/configure.rb create mode 100644 custom-cookbooks/elasticache-redis/recipes/default.rb create mode 100644 custom-cookbooks/elasticache-redis/templates/default/redis.yml.erb diff --git a/custom-cookbooks/elasticache-memcache/README.md b/custom-cookbooks/elasticache-memcache/README.md new file mode 100644 index 0000000..34a4bbc --- /dev/null +++ b/custom-cookbooks/elasticache-memcache/README.md @@ -0,0 +1,25 @@ +## Optional Cookbook for Engine Yard Cloud + +# Elasticache Memcache + +AWS Elasticache is managed service for Memcache. + +## Overview + +This cookbook generates configuration file from provided environment variables. + +## Installation + +### Environment Variables + +When the environment variable `EY_ELASTICACHE_MEMCACHE_ENABLED` is set to "true", this recipe will be enabled and setup up Memcache configuration file. +`EY_ELASTICACHE_MEMCACHE_URL` vairable will be used for the URL + + +### Custom Chef + +Since this is an optional recipe, it can be installed by simply including it via a `depends` in your `ey-custom/metadata.rb` file and an `include_recipe` in the appropriate hook file. + +## Notes + +1. This recipe will put in place a `memcached.yml` on `/data/{app_name}/shared/config/`. diff --git a/custom-cookbooks/elasticache-memcache/attributes/default.rb b/custom-cookbooks/elasticache-memcache/attributes/default.rb new file mode 100644 index 0000000..c8f054b --- /dev/null +++ b/custom-cookbooks/elasticache-memcache/attributes/default.rb @@ -0,0 +1,7 @@ +default["elasticache-memcache"].tap do |elasticache| + + elasticache['ey_elastic_memcache_enabled'] = fetch_env_var(node, "EY_ELASTICACHE_MEMCACHE_ENABLED") + elasticache['ey_elastic_memcache_url'] = fetch_env_var(node, "EY_ELASTICACHE_MEMCACHE_URL") + elasticache['ey_memcache'] = fetch_env_var(node, "EY_MEMCACHE") + +end diff --git a/custom-cookbooks/elasticache-memcache/metadata.rb b/custom-cookbooks/elasticache-memcache/metadata.rb new file mode 100644 index 0000000..35f4e8f --- /dev/null +++ b/custom-cookbooks/elasticache-memcache/metadata.rb @@ -0,0 +1,8 @@ +name 'elasticache-memcache' +description 'Configuration of Elasticache Memcache on AWS' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +maintainer 'Engine Yard' +maintainer_email 'support@engineyard.com' +version '1.0.1' +issues_url 'https://github.com/engineyard/ey-cookbooks-stable-v6/issues' +source_url 'https://github.com/engineyard/ey-cookbooks-stable-v6' diff --git a/custom-cookbooks/elasticache-memcache/recipes/configure.rb b/custom-cookbooks/elasticache-memcache/recipes/configure.rb new file mode 100644 index 0000000..548c404 --- /dev/null +++ b/custom-cookbooks/elasticache-memcache/recipes/configure.rb @@ -0,0 +1,34 @@ +# +# Cookbook Name:: memcache +# Recipe:: configure +# + +if node['elasticache-memcache']['ey_elastic_memcache_enabled'] + + if node['elasticache-memcache']['ey_memcache'] + # ERROR both EY_MEMCACHE and ELASTICACHE Enabled + end + + if node['elasticache-memcache']['ey_elastic_memcache_url'].nil? || node['elasticache-memcache']['ey_elastic_memcache_url'].empty? + # ERROR URL missing + end + + if ['solo', 'app', 'app_master', 'util'].include?(node['dna']['instance_role']) + + node['dna']['applications'].each do |app, data| + template "/data/#{app}/shared/config/memcached.yml"do + source 'memcached.yml.erb' + owner node['owner_name'] + group node['owner_name'] + mode 0655 + backup 0 + variables({ + 'hostname' => node['elasticache-memcache']['ey_elastic_memcache_url'], + 'environment' => node["dna"]["engineyard"]["environment"]["framework_env"] + }) + end + end + + end + +end diff --git a/custom-cookbooks/elasticache-memcache/recipes/default.rb b/custom-cookbooks/elasticache-memcache/recipes/default.rb new file mode 100644 index 0000000..62817d9 --- /dev/null +++ b/custom-cookbooks/elasticache-memcache/recipes/default.rb @@ -0,0 +1,5 @@ +# +# Cookbook Name:: elasticache-memcache +# + +include_recipe 'elasticache-memcache::configure' diff --git a/custom-cookbooks/elasticache-memcache/templates/default/memcached.yml.erb b/custom-cookbooks/elasticache-memcache/templates/default/memcached.yml.erb new file mode 100644 index 0000000..541404f --- /dev/null +++ b/custom-cookbooks/elasticache-memcache/templates/default/memcached.yml.erb @@ -0,0 +1,7 @@ +defaults: + servers: + - <%= @hostname %>:11211 + +<%= @environment %>: + servers: + - <%= @hostname %>:11211 diff --git a/custom-cookbooks/elasticache-redis/README.md b/custom-cookbooks/elasticache-redis/README.md new file mode 100644 index 0000000..a592a9b --- /dev/null +++ b/custom-cookbooks/elasticache-redis/README.md @@ -0,0 +1,25 @@ +## Optional Cookbook for Engine Yard Cloud + +# Elasticache Redis + +AWS Elasticache is managed service for Redis. + +## Overview + +This cookbook generates configuration file from provided environment variables. + +## Installation + +### Environment Variables + +When the environment variable `EY_ELASTICACHE_REDIS_ENABLED` is set to "true", this recipe will be enabled and setup up Redis configuration file. +`EY_ELASTICACHE_REDIS_URL` vairable will be used for the URL + + +### Custom Chef + +Since this is an optional recipe, it can be installed by simply including it via a `depends` in your `ey-custom/metadata.rb` file and an `include_recipe` in the appropriate hook file. + +## Notes + +1. This recipe will put in place a `redis.yml` on `/data/{app_name}/shared/config/`. diff --git a/custom-cookbooks/elasticache-redis/attributes/default.rb b/custom-cookbooks/elasticache-redis/attributes/default.rb new file mode 100644 index 0000000..eb77eb7 --- /dev/null +++ b/custom-cookbooks/elasticache-redis/attributes/default.rb @@ -0,0 +1,7 @@ +default["elasticache-redis"].tap do |elasticache| + + elasticache['ey_elastic_redis_enabled'] = fetch_env_var(node, "EY_ELASTICACHE_REDIS_ENABLED") + elasticache['ey_elastic_redis_url'] = fetch_env_var(node, "EY_ELASTICACHE_REDIS_URL") + elasticache['ey_redis'] = fetch_env_var(node, "EY_REDIS") + +end diff --git a/custom-cookbooks/elasticache-redis/metadata.rb b/custom-cookbooks/elasticache-redis/metadata.rb new file mode 100644 index 0000000..34bb3b2 --- /dev/null +++ b/custom-cookbooks/elasticache-redis/metadata.rb @@ -0,0 +1,8 @@ +name 'elasticache-redis' +description 'Configuration of Elasticache Redis on AWS' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +maintainer 'Engine Yard' +maintainer_email 'support@engineyard.com' +version '1.0.1' +issues_url 'https://github.com/engineyard/ey-cookbooks-stable-v6/issues' +source_url 'https://github.com/engineyard/ey-cookbooks-stable-v6' diff --git a/custom-cookbooks/elasticache-redis/recipes/configure.rb b/custom-cookbooks/elasticache-redis/recipes/configure.rb new file mode 100644 index 0000000..b9ccf1d --- /dev/null +++ b/custom-cookbooks/elasticache-redis/recipes/configure.rb @@ -0,0 +1,34 @@ +# +# Cookbook Name:: redis +# Recipe:: configure +# + +if node['elasticache-redis']['ey_elastic_redis_enabled'] + + if node["elasticache-redis"]['ey_redis'] + # ERROR both EY_REDIS and ELASTICACHE Enabled + end + + if node['elasticache-redis']['ey_elastic_redis_url'].nil? || node['elasticache-redis']['ey_elastic_redis_url'].empty? + # ERROR URL missing + end + + if ['solo', 'app', 'app_master', 'util'].include?(node['dna']['instance_role']) + + node['dna']['applications'].each do |app, data| + template "/data/#{app}/shared/config/redis.yml"do + source 'redis.yml.erb' + owner node['owner_name'] + group node['owner_name'] + mode 0655 + backup 0 + variables({ + 'hostname' => node['elasticache-redis']['ey_elastic_redis_url'], + 'environment' => node["dna"]["engineyard"]["environment"]["framework_env"] + }) + end + end + + end + +end diff --git a/custom-cookbooks/elasticache-redis/recipes/default.rb b/custom-cookbooks/elasticache-redis/recipes/default.rb new file mode 100644 index 0000000..8fd520a --- /dev/null +++ b/custom-cookbooks/elasticache-redis/recipes/default.rb @@ -0,0 +1,5 @@ +# +# Cookbook Name:: elasticache-redis +# + +include_recipe 'elasticache-redis::configure' diff --git a/custom-cookbooks/elasticache-redis/templates/default/redis.yml.erb b/custom-cookbooks/elasticache-redis/templates/default/redis.yml.erb new file mode 100644 index 0000000..d0efb82 --- /dev/null +++ b/custom-cookbooks/elasticache-redis/templates/default/redis.yml.erb @@ -0,0 +1,3 @@ +<%= @environment %>: + host: <%= @hostname %> + port: 6379