diff options
| author | mo khan <mo@mokhan.ca> | 2015-05-28 22:37:13 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-05-28 22:37:13 -0600 |
| commit | 63b930b414061a81ec31fbe4b8a183a7b56e6033 (patch) | |
| tree | 0acd4f8ba7b0ca1449fe8b8292165ff18d3470af /lib | |
| parent | 49ea45c199d08558b500adb54f39dc4521eb9ee4 (diff) | |
use s3 based deployment strategy.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/capistrano/s3.rb | 38 | ||||
| -rw-r--r-- | lib/tasks/s3.rake | 78 |
2 files changed, 116 insertions, 0 deletions
diff --git a/lib/capistrano/s3.rb b/lib/capistrano/s3.rb new file mode 100644 index 0000000..aa456ca --- /dev/null +++ b/lib/capistrano/s3.rb @@ -0,0 +1,38 @@ +load File.expand_path("../../tasks/s3.rake", __FILE__) + +require 'capistrano/scm' + +class Capistrano::S3 < Capistrano::SCM + def s3(*args) + puts args.inspect + args.unshift '--profile default' + args.unshift :s3 + args.unshift :aws + context.execute *args + end + + module DefaultStrategy + def test + test! " [ -f #{repo_path}/HEAD ] " + end + + def check + s3 'ls stronglifters' + end + + def clone + context.execute("mkdir -p #{repo_path}") + end + + def update + build = "stronglifters-2015-05-29-03-07-33.tar.gz" + s3 "cp s3://stronglifters/production/#{build} #{repo_path}/#{build}" + end + + def release + build = "stronglifters-2015-05-29-03-07-33.tar.gz" + context.execute("mkdir -p #{release_path}") + context.execute("tar -xvzf #{repo_path}/#{build} --strip-components=1 -C #{release_path}") + end + end +end diff --git a/lib/tasks/s3.rake b/lib/tasks/s3.rake new file mode 100644 index 0000000..461cade --- /dev/null +++ b/lib/tasks/s3.rake @@ -0,0 +1,78 @@ +namespace :s3 do + def strategy + @strategy ||= Capistrano::S3.new(self, Capistrano::S3::DefaultStrategy) + end + + set :s3_environmental_variables, ->() { + { + aws_access_key_id: fetch(:aws_access_key_id), + aws_secret_access_key: fetch(:aws_secret_access_key), + bucket_name: fetch(:s3_bucket), + build_revision: fetch(:build_revision), + } + } + + task :wrapper do + on release_roles :all do + end + end + + desc 'Check that the repository is reachable' + task check: :'s3:wrapper' do + fetch(:branch) + on release_roles :all do + with fetch(:s3_environmental_variables) do + strategy.check + end + end + end + + desc 'Clone the repo to the cache' + task clone: :'s3:wrapper' do + on release_roles :all do + if strategy.test + info t(:mirror_exists, at: repo_path) + else + within deploy_path do + with fetch(:s3_environmental_variables) do + strategy.clone + end + end + end + end + end + + desc 'Update the repo mirror to reflect the origin state' + task update: :'s3:clone' do + on release_roles :all do + within repo_path do + with fetch(:s3_environmental_variables) do + strategy.update + end + end + end + end + + desc 'Copy repo to releases' + task create_release: :'s3:update' do + on release_roles :all do + with fetch(:s3_environmental_variables) do + within repo_path do + execute :mkdir, '-p', release_path + strategy.release + end + end + end + end + + desc 'Determine the revision that will be deployed' + task :set_current_revision do + on release_roles :all do + within repo_path do + with fetch(:s3_environmental_variables) do + set :current_revision, fetch(:build_revision) + end + end + end + end +end |
