Last active
April 6, 2016 16:12
-
-
Save mlr/fd8a13b57a7158d3219b2d1afb3ba84d to your computer and use it in GitHub Desktop.
Simple S3 deploy task for middleman site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler' | |
begin | |
Bundler.setup(:default, :development) | |
rescue Bundler::BundlerError => e | |
$stderr.puts e.message | |
$stderr.puts "Run `bundle install` to install missing gems" | |
exit e.status_code | |
end | |
require 'dotenv' | |
Dotenv.load | |
desc "Deploy website to s3" | |
task :deploy do | |
puts "Building website" | |
`middleman build` | |
puts "Deploying website" | |
require 'aws-sdk' | |
s3 = AWS::S3.new(region: 'us-west-2', | |
access_key_id: ENV['ACCESS_KEY_ID'], | |
secret_access_key: ENV['SECRET_ACCESS_KEY']) | |
bucket = s3.buckets['myinvoicer.com'] | |
build = Pathname.new("build") | |
Dir.glob("build/**/*.*").each do |file| | |
source = Pathname.new(file) | |
destination = source.relative_path_from(build) | |
bucket.objects[destination].write(source) | |
end | |
puts "Website deployed" | |
end | |
# Gemfile shown here for reference | |
# source 'https://rubygems.org' | |
# | |
# gem 'middleman', '>= 4.0.0' | |
# | |
# Deployment | |
# gem 'aws-sdk' | |
# gem 'dotenv' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment