From f9ee98a3a20e5864c8cda5c060ef38301bbb6c76 Mon Sep 17 00:00:00 2001 From: Kevin Attfield Date: Wed, 14 Dec 2016 16:27:54 -0800 Subject: [PATCH 1/2] Namespace helper methods The rake namespace DSL does nothing to excanpsulate defined methods. So we can either refactor oops tasks into modules or simply rename the private helpers to lower the chance of collisions on the global scope. --- lib/oops/tasks.rb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/oops/tasks.rb b/lib/oops/tasks.rb index 4e52893..b7a8753 100644 --- a/lib/oops/tasks.rb +++ b/lib/oops/tasks.rb @@ -48,7 +48,7 @@ def create_task! namespace :oops do task :build, [:filename] => prerequisites do |t, args| - args.with_defaults filename: default_filename + args.with_defaults filename: oops_default_filename file_path = args.filename @@ -76,10 +76,10 @@ def create_task! namespace :oops do task :upload, :filename do |t, args| - args.with_defaults filename: default_filename + args.with_defaults filename: oops_default_filename file_path = args.filename - s3 = s3_object(file_path) + s3 = oops_s3_object(file_path) puts "Starting upload..." s3.upload_file("build/#{file_path}") @@ -89,13 +89,13 @@ def create_task! task :deploy, :app_name, :stack_name, :filename do |t, args| raise "app_name variable is required" unless (app_name = args.app_name) raise "stack_name variable is required" unless (stack_name = args.stack_name) - args.with_defaults filename: default_filename + args.with_defaults filename: oops_default_filename file_path = args.filename - file_url = s3_url file_path + file_url = oops_s3_url file_path ENV['AWS_REGION'] ||= 'us-east-1' - if !s3_object(file_path).exists? + if !oops_s3_object(file_path).exists? raise "Artifact \"#{file_url}\" doesn't seem to exist\nMake sure you've run `RAILS_ENV=deploy rake opsworks:build opsworks:upload` before deploying" end @@ -115,29 +115,29 @@ def create_task! end private - def s3_object file_path + def oops_s3_object file_path s3 = Aws::S3::Resource.new - s3.bucket(bucket_name).object("#{package_folder}/#{file_path}") + s3.bucket(oops_bucket_name).object("#{oops_package_folder}/#{file_path}") end - def s3_url file_path - s3_object(file_path).public_url.to_s + def oops_s3_url file_path + oops_s3_object(file_path).public_url.to_s end - def build_hash - @build_hash ||= `git rev-parse HEAD`.strip + def oops_build_hash + @oops_build_hash ||= `git rev-parse HEAD`.strip end - def default_filename - ENV['PACKAGE_FILENAME'] || "git-#{build_hash}.zip" + def oops_default_filename + ENV['PACKAGE_FILENAME'] || "git-#{oops_build_hash}.zip" end - def package_folder + def oops_package_folder raise "PACKAGE_FOLDER environment variable required" unless ENV['PACKAGE_FOLDER'] ENV['PACKAGE_FOLDER'] end - def bucket_name + def oops_bucket_name raise "DEPLOY_BUCKET environment variable required" unless ENV['DEPLOY_BUCKET'] ENV['DEPLOY_BUCKET'] end From a31f5b842c28d320896d2cd89007958fea2160e9 Mon Sep 17 00:00:00 2001 From: Kevin Attfield Date: Sun, 8 Oct 2017 14:38:24 -0700 Subject: [PATCH 2/2] Add rake task descriptions I'm not as concerned with the accuracy of these descriptions as I am with their existance, so that oops tasks will be listed by rake -T --- lib/oops/tasks.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/oops/tasks.rb b/lib/oops/tasks.rb index b7a8753..ed9e6a2 100644 --- a/lib/oops/tasks.rb +++ b/lib/oops/tasks.rb @@ -47,6 +47,7 @@ def create_task! Rake::Task["oops:build"].clear if Rake::Task.task_defined?("oops:build") namespace :oops do + desc 'Build project as filename' task :build, [:filename] => prerequisites do |t, args| args.with_defaults filename: oops_default_filename @@ -75,6 +76,7 @@ def create_task! end namespace :oops do + desc 'Upload file by path from build to S3' task :upload, :filename do |t, args| args.with_defaults filename: oops_default_filename @@ -86,6 +88,7 @@ def create_task! puts "Uploaded Application: #{s3.public_url}" end + desc 'Deploy application by opsworks name and stack' task :deploy, :app_name, :stack_name, :filename do |t, args| raise "app_name variable is required" unless (app_name = args.app_name) raise "stack_name variable is required" unless (stack_name = args.stack_name)