Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace oops helper methods #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions lib/oops/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ 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: default_filename
args.with_defaults filename: oops_default_filename

file_path = args.filename

Expand All @@ -75,27 +76,29 @@ 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: 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}")
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)
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

Expand All @@ -115,29 +118,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
Expand Down