capistrano-s3copy-awscli 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +158 -0
- data/Rakefile +22 -0
- data/capistrano-s3copy-awscli.gemspec +27 -0
- data/lib/capistrano-s3copy-awscli.rb +2 -0
- data/lib/capistrano-s3copy-awscli/recipes/s3_copy.rb +15 -0
- data/lib/capistrano-s3copy-awscli/version.rb +7 -0
- data/lib/capistrano/recipes/deploy/strategy/aws_install.sh.erb +93 -0
- data/lib/capistrano/recipes/deploy/strategy/s3_copy.rb +87 -0
- metadata +80 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Takayuki Okawa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
# Capistrano::S3copy::Awscli
|
2
|
+
|
3
|
+
This is a revised implementation of the ideas in Bill Richie McMahon [capistrano-s3-copy](http://github.com/richie/capistrano-s3-copy) gem.
|
4
|
+
|
5
|
+
Part of my revising've simply to use the aws-cli.
|
6
|
+
|
7
|
+
aws-cli supports
|
8
|
+
|
9
|
+
* Environment variables
|
10
|
+
* Config file
|
11
|
+
* IAM Role
|
12
|
+
|
13
|
+
*But this gem don't support Config file.*
|
14
|
+
|
15
|
+
This gem use Capistrano's own code to package the tarball, but instead of deploying it to each
|
16
|
+
machine, we deploy it to a configured S3 bucket (using aws-cli provided by the https://github.com/aws/aws-cli),
|
17
|
+
then deploy it from there to the known nodes from the capistrano script.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
gem build capistrano-s3copy-awscli.gemspec
|
22
|
+
gem install --local capistrano-s3copy-awscli-[version].gem
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
In your deploy.rb file, we need to tell Capistrano to adopt our new strategy:
|
27
|
+
|
28
|
+
set :deploy_via, :s3_copy
|
29
|
+
|
30
|
+
If you want to use Environment variables then we need to provide AWS account details to authorize the upload/download of our
|
31
|
+
package to S3
|
32
|
+
|
33
|
+
set :aws_access_key_id, ENV['AWS_ACCESS_KEY_ID']
|
34
|
+
set :aws_secret_access_key, ENV['AWS_SECRET_ACCESS_KEY']
|
35
|
+
|
36
|
+
Finally, we need to indicate which region and bucket to store the packages in:
|
37
|
+
|
38
|
+
set :aws_region, 'mybucket-region'
|
39
|
+
set :aws_releases_bucket, 'mybucket-deployments'
|
40
|
+
|
41
|
+
The package will be stored in S3 prefixed with a rails_env that was set in capistrano:
|
42
|
+
|
43
|
+
e.g.
|
44
|
+
|
45
|
+
S3://mybucket-deployment/production/201307212007.tar.gz
|
46
|
+
|
47
|
+
If the deployment succeeds, another file is written to S3:
|
48
|
+
|
49
|
+
S3://mybucket-deployment/production/aws_install.sh
|
50
|
+
|
51
|
+
The intention is that auto-scaled instances started after the deploy could download this well-known script
|
52
|
+
to an AMI, and executing it would bring down the latest tarball, and extract it in a manner similar to
|
53
|
+
someone running:
|
54
|
+
|
55
|
+
cap deploy:setup
|
56
|
+
cap deploy
|
57
|
+
|
58
|
+
Of course, everyone has tweaks that they make to the standard capistrano recipe. For this reason, the script
|
59
|
+
thats executed is generated from an ERB template.
|
60
|
+
|
61
|
+
|
62
|
+
#!/bin/sh
|
63
|
+
|
64
|
+
# Auto-scaling capistrano like deployment script Rails3 specific.
|
65
|
+
|
66
|
+
set -x
|
67
|
+
set -e
|
68
|
+
|
69
|
+
echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"
|
70
|
+
echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
|
71
|
+
|
72
|
+
if [ "${AWS_ACCESS_KEY_ID}" == "" ]; then
|
73
|
+
echo "Expecting the environment variable AWS_ACCESS_KEY_ID to be set"
|
74
|
+
exit 1
|
75
|
+
fi
|
76
|
+
|
77
|
+
if [ "${AWS_SECRET_ACCESS_KEY}" == "" ]; then
|
78
|
+
echo "Expecting the environment variable AWS_SECRET_ACCESS_KEY to be set"
|
79
|
+
exit 2
|
80
|
+
fi
|
81
|
+
|
82
|
+
AWS_RELEASES_BUCKET=<%= configuration[:aws_releases_bucket] %>
|
83
|
+
AWS_REGION=<%= configuration[:aws_region] %>
|
84
|
+
RAILS_ENV=<%= configuration[:rails_env] %> # e.g. production
|
85
|
+
DEPLOY_TO=<%= configuration[:deploy_to] %> # e.g. /u/apps/myapp
|
86
|
+
RELEASES_PATH=<%= configuration[:releases_path] %> # e.g. /u/apps/myapp/releases
|
87
|
+
RELEASE_PATH=<%= configuration[:release_path] %> # e.g. /u/apps/myapp/releases/20130720210958
|
88
|
+
SHARED_PATH=<%= configuration[:shared_path] %> # e.g. /u/apps/myapp/shared
|
89
|
+
CURRENT_PATH=<%= configuration[:current_path] %> # e.g. /u/apps/myapp/current
|
90
|
+
|
91
|
+
PACKAGE_NAME=<%= File.basename(filename) %> # e.g. 20130720210958.tar.gz
|
92
|
+
S3_PACKAGE_PATH=${RAILS_ENV}/${PACKAGE_NAME} # e.g. production/20130720210958.tar.gz
|
93
|
+
DOWNLOADED_PACKAGE_PATH=<%= remote_filename %> # e.g. /tmp/20130720210958.tar.gz
|
94
|
+
DECOMPRESS_CMD="<%= decompress(remote_filename).join(" ") %>" # e.g. tar xfz /tmp/20130720210958.tar.gz
|
95
|
+
|
96
|
+
mkdir -p $DEPLOY_TO
|
97
|
+
mkdir -p $RELEASES_PATH
|
98
|
+
mkdir -p ${SHARED_PATH}
|
99
|
+
mkdir -p ${SHARED_PATH}/system
|
100
|
+
mkdir -p ${SHARED_PATH}/log
|
101
|
+
mkdir -p ${SHARED_PATH}/pids
|
102
|
+
|
103
|
+
touch ${SHARED_PATH}/log/${RAILS_ENV}.log
|
104
|
+
chmod 0666 ${SHARED_PATH}/log/${RAILS_ENV}.log
|
105
|
+
chmod -R g+w ${DEPLOY_TO}
|
106
|
+
|
107
|
+
# AFTER: cap deploy:setup
|
108
|
+
# Project specific shared directories
|
109
|
+
# mkdir -p ${SHARED_PATH}/content
|
110
|
+
# mkdir -p ${SHARED_PATH}/uploads
|
111
|
+
|
112
|
+
# cap deploy:update_code
|
113
|
+
s3cmd get ${AWS_RELEASES_BUCKET}:${S3_PACKAGE_PATH} ${DOWNLOADED_PACKAGE_PATH} 2>&1
|
114
|
+
cd ${RELEASES_PATH} && ${DECOMPRESS_CMD} && rm ${DOWNLOADED_PACKAGE_PATH}
|
115
|
+
|
116
|
+
# cap deploy:assets_symlink (Rails 3.x specific)
|
117
|
+
rm -rf ${RELEASE_PATH}/public/assets
|
118
|
+
mkdir -p ${RELEASE_PATH}/public
|
119
|
+
mkdir -p ${DEPLOY_TO}/shared/assets
|
120
|
+
ln -s ${SHARED_PATH}/assets ${RELEASE_PATH}/public/assets
|
121
|
+
|
122
|
+
# cap deploy:finalize_update
|
123
|
+
chmod -R g+w ${RELEASE_PATH}
|
124
|
+
rm -rf ${RELEASE_PATH}/log
|
125
|
+
rm -rf ${RELEASE_PATH}/public/system
|
126
|
+
rm -rf ${RELEASE_PATH}/tmp/pids
|
127
|
+
mkdir -p ${RELEASE_PATH}/public
|
128
|
+
mkdir -p ${RELEASE_PATH}/tmp
|
129
|
+
ln -s ${SHARED_PATH}/system ${RELEASE_PATH}/public/system
|
130
|
+
ln -s ${SHARED_PATH}/log ${RELEASE_PATH}/log
|
131
|
+
ln -s ${SHARED_PATH}/pids ${RELEASE_PATH}/tmp/pids
|
132
|
+
|
133
|
+
# AFTER: cap deploy:finalize_update
|
134
|
+
cd ${RELEASE_PATH}
|
135
|
+
bundle install --gemfile ${RELEASE_PATH}/Gemfile --path ${SHARED_PATH}/bundle --deployment --quiet --without development test
|
136
|
+
|
137
|
+
# AFTER: cap deploy:update_code
|
138
|
+
# cap deploy:assets:precompile
|
139
|
+
cd ${RELEASE_PATH}
|
140
|
+
bundle exec rake RAILS_ENV=${RAILS_ENV} RAILS_GROUPS=assets assets:precompile
|
141
|
+
|
142
|
+
# Project specific shared symlinking
|
143
|
+
#ln -nfs ${SHARED_PATH}/content ${RELEASE_PATH}/public/content
|
144
|
+
#ln -nfs ${SHARED_PATH}/uploads ${RELEASE_PATH}/public/uploads
|
145
|
+
|
146
|
+
# cap deploy:create_symlink
|
147
|
+
rm -f ${CURRENT_PATH}
|
148
|
+
ln -s ${RELEASE_PATH} ${CURRENT_PATH}
|
149
|
+
|
150
|
+
# cap deploy:restart
|
151
|
+
# touch ${CURRENT_PATH}/tmp/restart.txt
|
152
|
+
|
153
|
+
# AFTER: cap deploy:restart
|
154
|
+
# cd ${CURRENT_PATH};RAILS_ENV=${RAILS_ENV} script/delayed_job restart
|
155
|
+
|
156
|
+
An alternative ERB script can be configured via something like this:
|
157
|
+
|
158
|
+
set :aws_install_script, File.read(File.join(File.dirname(__FILE__), "custom_aws_install.sh.erb")
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#rake #!/usr/bin/env rake
|
2
|
+
require 'rdoc/task'
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
desc "Build the RDoc API documentation"
|
6
|
+
RDoc::Task.new do |rdoc|
|
7
|
+
rdoc.rdoc_dir = "doc"
|
8
|
+
rdoc.title = "Capistrano S3Copy aws-cli"
|
9
|
+
rdoc.options += %w(--main README)
|
10
|
+
rdoc.rdoc_files.include('README.md', 'LICENSE', 'lib/**/*.rb')
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Build documentation"
|
14
|
+
task :doc => [ :rdoc ]
|
15
|
+
|
16
|
+
desc "Clean up generated directories and files"
|
17
|
+
task :clean do
|
18
|
+
rm_rf "pkg"
|
19
|
+
rm_rf "doc"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :default => [ :clean, :build, :doc ]
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#lib = File.expand_path('../lib', __FILE__)
|
3
|
+
#$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require File.expand_path('../lib/capistrano-s3copy-awscli/version', __FILE__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-s3copy-awscli"
|
8
|
+
gem.version = Capistrano::S3copy::Awscli::VERSION
|
9
|
+
gem.authors = ["Takayuki Okawa"]
|
10
|
+
gem.email = ["takayuki.ohkawa@gmail.com"]
|
11
|
+
gem.description = %q{Capistrano deployment strategy that creates and pushes a tarball
|
12
|
+
into S3, for both pushed deployments and pulled auto-scaling.
|
13
|
+
Modified to use aws-cli(https://github.com/aws/aws-cli) from s3cmd.
|
14
|
+
The original source is Capistrano-S3-Copy(http://github.com/richie/capistrano-s3-copy)}
|
15
|
+
gem.summary = %q{Capistrano deployment strategy that transfers the release on S3}
|
16
|
+
gem.homepage = "https://github.com/bacter1a/capistrano-s3copy-awscli"
|
17
|
+
gem.license = "MIT"
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($\)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
|
24
|
+
#gem.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
#gem.add_development_dependency "rake"
|
26
|
+
gem.add_dependency 'capistrano', ">= 2.12.0"
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Capistrano::Configuration.instance(false).load do
|
2
|
+
|
3
|
+
namespace :s3_copy do
|
4
|
+
|
5
|
+
desc "Internal hook that updates the aws_install.sh script to latest if the deploy completed"
|
6
|
+
task :store_aws_install_script_on_success do
|
7
|
+
cmd = fetch(:s3_copy_aws_install_cmd)
|
8
|
+
if cmd
|
9
|
+
run_locally(cmd)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after 'deploy', 's3_copy:store_aws_install_script_on_success'
|
15
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# Auto-scaling capistrano like deployment script Rails3 specific.
|
4
|
+
|
5
|
+
set -x
|
6
|
+
set -e
|
7
|
+
|
8
|
+
echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}"
|
9
|
+
echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
|
10
|
+
|
11
|
+
if [ "${AWS_ACCESS_KEY_ID}" == "" ]; then
|
12
|
+
echo "Expecting the environment variable AWS_ACCESS_KEY_ID to be set"
|
13
|
+
exit 1
|
14
|
+
fi
|
15
|
+
|
16
|
+
if [ "${AWS_SECRET_ACCESS_KEY}" == "" ]; then
|
17
|
+
echo "Expecting the environment variable AWS_SECRET_ACCESS_KEY to be set"
|
18
|
+
exit 2
|
19
|
+
fi
|
20
|
+
|
21
|
+
AWS_RELEASES_BUCKET=<%= configuration[:aws_releases_bucket] %>
|
22
|
+
|
23
|
+
RAILS_ENV=<%= configuration[:rails_env] %> # e.g. production
|
24
|
+
DEPLOY_TO=<%= configuration[:deploy_to] %> # e.g. /u/apps/myapp
|
25
|
+
RELEASES_PATH=<%= configuration[:releases_path] %> # e.g. /u/apps/myapp/releases
|
26
|
+
RELEASE_PATH=<%= configuration[:release_path] %> # e.g. /u/apps/myapp/releases/20120428210958
|
27
|
+
SHARED_PATH=<%= configuration[:shared_path] %> # e.g. /u/apps/myapp/shared
|
28
|
+
CURRENT_PATH=<%= configuration[:current_path] %> # e.g. /u/apps/myapp/current
|
29
|
+
|
30
|
+
PACKAGE_NAME=<%= File.basename(filename) %> # e.g. 20120428210958.tar.gz
|
31
|
+
S3_PACKAGE_PATH=${RAILS_ENV}/${PACKAGE_NAME} # e.g. production/20120428210958.tar.gz
|
32
|
+
DOWNLOADED_PACKAGE_PATH=<%= remote_filename %> # e.g. /tmp/20120428210958.tar.gz
|
33
|
+
DECOMPRESS_CMD="<%= decompress(remote_filename).join(" ") %>" # e.g. tar xfz /tmp/20120428210958.tar.gz
|
34
|
+
|
35
|
+
mkdir -p $DEPLOY_TO
|
36
|
+
mkdir -p $RELEASES_PATH
|
37
|
+
mkdir -p ${SHARED_PATH}
|
38
|
+
mkdir -p ${SHARED_PATH}/system
|
39
|
+
mkdir -p ${SHARED_PATH}/log
|
40
|
+
mkdir -p ${SHARED_PATH}/pids
|
41
|
+
|
42
|
+
touch ${SHARED_PATH}/log/${RAILS_ENV}.log
|
43
|
+
chmod 0666 ${SHARED_PATH}/log/${RAILS_ENV}.log
|
44
|
+
chmod -R g+w ${DEPLOY_TO}
|
45
|
+
|
46
|
+
# AFTER: cap deploy:setup
|
47
|
+
# Project specific shared directories
|
48
|
+
# mkdir -p ${SHARED_PATH}/content
|
49
|
+
# mkdir -p ${SHARED_PATH}/uploads
|
50
|
+
|
51
|
+
# cap deploy:update_code
|
52
|
+
s3cmd get ${AWS_RELEASES_BUCKET}:${S3_PACKAGE_PATH} ${DOWNLOADED_PACKAGE_PATH} 2>&1
|
53
|
+
cd ${RELEASES_PATH} && ${DECOMPRESS_CMD} && rm ${DOWNLOADED_PACKAGE_PATH}
|
54
|
+
|
55
|
+
# cap deploy:assets_symlink (Rails 3.x specific)
|
56
|
+
rm -rf ${RELEASE_PATH}/public/assets
|
57
|
+
mkdir -p ${RELEASE_PATH}/public
|
58
|
+
mkdir -p ${DEPLOY_TO}/shared/assets
|
59
|
+
ln -s ${SHARED_PATH}/assets ${RELEASE_PATH}/public/assets
|
60
|
+
|
61
|
+
# cap deploy:finalize_update
|
62
|
+
chmod -R g+w ${RELEASE_PATH}
|
63
|
+
rm -rf ${RELEASE_PATH}/log
|
64
|
+
rm -rf ${RELEASE_PATH}/public/system
|
65
|
+
rm -rf ${RELEASE_PATH}/tmp/pids
|
66
|
+
mkdir -p ${RELEASE_PATH}/public
|
67
|
+
mkdir -p ${RELEASE_PATH}/tmp
|
68
|
+
ln -s ${SHARED_PATH}/system ${RELEASE_PATH}/public/system
|
69
|
+
ln -s ${SHARED_PATH}/log ${RELEASE_PATH}/log
|
70
|
+
ln -s ${SHARED_PATH}/pids ${RELEASE_PATH}/tmp/pids
|
71
|
+
|
72
|
+
# AFTER: cap deploy:finalize_update
|
73
|
+
cd ${RELEASE_PATH}
|
74
|
+
bundle install --gemfile ${RELEASE_PATH}/Gemfile --path ${SHARED_PATH}/bundle --deployment --quiet --without development test
|
75
|
+
|
76
|
+
# AFTER: cap deploy:update_code
|
77
|
+
# cap deploy:assets:precompile
|
78
|
+
cd ${RELEASE_PATH}
|
79
|
+
bundle exec rake RAILS_ENV=${RAILS_ENV} RAILS_GROUPS=assets assets:precompile
|
80
|
+
|
81
|
+
# Project specific shared symlinking
|
82
|
+
#ln -nfs ${SHARED_PATH}/content ${RELEASE_PATH}/public/content
|
83
|
+
#ln -nfs ${SHARED_PATH}/uploads ${RELEASE_PATH}/public/uploads
|
84
|
+
|
85
|
+
# cap deploy:create_symlink
|
86
|
+
rm -f ${CURRENT_PATH}
|
87
|
+
ln -s ${RELEASE_PATH} ${CURRENT_PATH}
|
88
|
+
|
89
|
+
# cap deploy:restart
|
90
|
+
# touch ${CURRENT_PATH}/tmp/restart.txt
|
91
|
+
|
92
|
+
# AFTER: cap deploy:restart
|
93
|
+
# cd ${CURRENT_PATH};RAILS_ENV=${RAILS_ENV} script/delayed_job restart
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/copy'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
module Deploy
|
7
|
+
module Strategy
|
8
|
+
class S3Copy < Copy
|
9
|
+
|
10
|
+
def initialize(config={})
|
11
|
+
super(config)
|
12
|
+
|
13
|
+
s3cmd_vars = []
|
14
|
+
["aws_access_key_id", "aws_secret_access_key"].each do |var|
|
15
|
+
value = configuration[var.to_sym]
|
16
|
+
# This error handling was commented for IAM role
|
17
|
+
# raise Capistrano::Error, "Missing configuration[:#{var}] setting" if value.nil?
|
18
|
+
s3cmd_vars << "#{var.upcase}=#{value}"
|
19
|
+
end
|
20
|
+
@aws_environment = s3cmd_vars.join(" ")
|
21
|
+
|
22
|
+
@bucket_name = configuration[:aws_releases_bucket]
|
23
|
+
raise Capistrano::Error, "Missing configuration[:aws_releases_bucket]" if @bucket_name.nil?
|
24
|
+
|
25
|
+
@region_name = configuration[:aws_region]
|
26
|
+
raise Capistrano::Error, "Missing configuration[:aws_region]" if @region_name.nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
def check!
|
30
|
+
super.check do |d|
|
31
|
+
d.local.command("aws s3")
|
32
|
+
d.remote.command("aws s3")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Distributes the file to the remote servers
|
37
|
+
def distribute!
|
38
|
+
package_path = filename
|
39
|
+
package_name = File.basename(package_path)
|
40
|
+
s3_push_cmd = "#{aws_environment} aws s3 put-object --bucket #{bucket_name} --region #{region_name} --key #{rails_env}/#{package_name} --body #{package_path} 2>&1"
|
41
|
+
|
42
|
+
if configuration.dry_run
|
43
|
+
logger.debug s3_push_cmd
|
44
|
+
else
|
45
|
+
system(s3_push_cmd)
|
46
|
+
raise Capistrano::Error, "shell command failed with return code #{$?}" if $? != 0
|
47
|
+
end
|
48
|
+
|
49
|
+
run "#{aws_environment} aws s3 get-object --bucket #{bucket_name} --region #{region_name} --key #{rails_env}/#{package_name} #{remote_filename} 2>&1"
|
50
|
+
run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
|
51
|
+
logger.debug "done!"
|
52
|
+
|
53
|
+
build_aws_install_script
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_aws_install_script
|
57
|
+
template_text = configuration[:aws_install_script]
|
58
|
+
template_text = File.read(File.join(File.dirname(__FILE__), "aws_install.sh.erb")) if template_text.nil?
|
59
|
+
template_text = template_text.gsub("\r\n?", "\n")
|
60
|
+
template = ERB.new(template_text, nil, '<>-')
|
61
|
+
output = template.result(self.binding)
|
62
|
+
local_output_file = File.join(copy_dir, "aws_install.sh")
|
63
|
+
File.open(local_output_file, "w") do |f|
|
64
|
+
f.write(output)
|
65
|
+
end
|
66
|
+
configuration[:s3_copy_aws_install_cmd] = "#{aws_environment} aws s3 put-object --bucket #{bucket_name} --region #{region_name} --key #{rails_env}/aws_install.sh --body #{local_output_file} 2>&1"
|
67
|
+
end
|
68
|
+
|
69
|
+
def binding
|
70
|
+
super
|
71
|
+
end
|
72
|
+
|
73
|
+
def aws_environment
|
74
|
+
@aws_environment
|
75
|
+
end
|
76
|
+
|
77
|
+
def bucket_name
|
78
|
+
@bucket_name
|
79
|
+
end
|
80
|
+
|
81
|
+
def region_name
|
82
|
+
@region_name
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-s3copy-awscli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Takayuki Okawa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.12.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.12.0
|
30
|
+
description: ! 'Capistrano deployment strategy that creates and pushes a tarball
|
31
|
+
|
32
|
+
into S3, for both pushed deployments and pulled auto-scaling.
|
33
|
+
|
34
|
+
Modified to use aws-cli(https://github.com/aws/aws-cli) from s3cmd.
|
35
|
+
|
36
|
+
The original source is Capistrano-S3-Copy(http://github.com/richie/capistrano-s3-copy)'
|
37
|
+
email:
|
38
|
+
- takayuki.ohkawa@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- LICENSE.txt
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- capistrano-s3copy-awscli.gemspec
|
50
|
+
- lib/capistrano-s3copy-awscli.rb
|
51
|
+
- lib/capistrano-s3copy-awscli/recipes/s3_copy.rb
|
52
|
+
- lib/capistrano-s3copy-awscli/version.rb
|
53
|
+
- lib/capistrano/recipes/deploy/strategy/aws_install.sh.erb
|
54
|
+
- lib/capistrano/recipes/deploy/strategy/s3_copy.rb
|
55
|
+
homepage: https://github.com/bacter1a/capistrano-s3copy-awscli
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.25
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Capistrano deployment strategy that transfers the release on S3
|
80
|
+
test_files: []
|