Commit 63b930b
config/deploy.rb
@@ -11,8 +11,10 @@ set :branch, "master"
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, "/var/www/my_app_name"
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
# Default value for :scm is :git
-set :scm, :git
+#set :scm, :git
+set :scm, :s3
# Default value for :format is :pretty
# set :format, :pretty
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
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