/
Rakefile
78 lines (65 loc) · 1.91 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require "rubygems"
require "bundler"
Bundler.setup
require 's3_uploader'
def s3_upload(bucket_name, directory)
Fog.credentials = { path_style: true }
S3Uploader.upload_directory(directory, bucket_name, {
:s3_key => ENV['MZS_AWS_ACCESS_KEY'],
:s3_secret => ENV['MZS_AWS_SECRET'],
:public => true,
:path_style => true
})
end
namespace :build do
desc "Create static site for blog/ directory"
task :blog do
Dir.chdir("blog") do
sh "jekyll build"
end
end
task :scholarship do
# Nothing to do here
end
end
namespace :serve do
desc 'Run a local server for the blog site'
task :blog do
Dir.chdir("blog") do
sh "jekyll serve -w"
end
end
end
namespace :deploy do
SITES = %w{ scholarship blog }
desc "Deploy main site"
task :root => [ 'build:blog' ] do
puts "Deploying mzsanford.com ..."
s3_upload('mzsanford.com', 'blog/_site')
end
SITES.each do |site|
desc "Deploy #{site} site"
task site.to_sym => [ "build:#{site}" ] do
puts "Deploying #{site}.mzsanford.com ..."
s3_upload("#{site}.mzsanford.com", "#{site}/_site")
# There is a root page with the same names as the sub-domain. Make it the index.
if File.exist?("#{site}/_site/#{site}.html")
puts "Setting #{site}.html as root document ..."
connection = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => ENV['MZS_AWS_ACCESS_KEY'],
:aws_secret_access_key => ENV['MZS_AWS_SECRET'],
:region => 'us-east-1'
})
directory = connection.directories.new(:key => "#{site}.mzsanford.com")
directory.files.create(
:key => 'index.html',
:body => File.open("#{site}/_site/#{site}.html"),
:public => true
)
end
end
end
desc "Deploy all sites"
task :all => [ 'deploy:root' ] + SITES.map{|s| "deploy:#{s}" }
end