Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "bundler/setup"
require 'yaml'
load 'lib/tasks/s3.rake'

def git_initialize(repository)
unless File.exist?(".git")
Expand Down
2 changes: 1 addition & 1 deletion config.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'redcarpet'
require 'active_support/core_ext'

Dir['./lib/*'].each { |f| require f }
Dir['./lib/*'].reject{|path| path.split("/").include?("tasks") }.each { |f| require f }

# Debugging
set(:logging, ENV['RACK_ENV'] != 'production')
Expand Down
60 changes: 60 additions & 0 deletions lib/tasks/s3.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'shellwords'
require 'tempfile'

def run_s3cmd(subcmd, *args)
cmd = ["s3cmd"]
cmd << subcmd

cmd.concat(args)

cmd = Shellwords.join(cmd)

puts "Running command: #{cmd.inspect}"
result = system cmd

puts "Error running command" unless result
end

namespace :s3 do

task :setup => [:create_bucket, :create_website, :create_policy, :deploy]

task :create_bucket do
run_s3cmd "mb", ENV['BUCKET_URL']
end

task :create_website do
run_s3cmd "ws-create", ENV['BUCKET_URL']
end

task :create_policy do
Tempfile.open('emberjs-policy.json') do |f|
f.write BUCKET_POLICY
f.rewind
run_s3cmd "setpolicy", f.path, ENV['BUCKET_URL']
end
end

task :deploy do
run_s3cmd "sync", "--delete-removed", "build/", ENV['BUCKET_URL']
end
end

BUCKET_POLICY = <<-EOS
{
"Version": "2008-10-17",
"Id": "Policy1337995845252",
"Statement": [
{
"Sid": "Stmt1337995842373",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::#{ENV['BUCKET_URL'].sub(%r{^s3:\/\/}, '')}/*"
}
]
}
EOS