capistrano-net_storage-s3 0.3.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +30 -0
- data/CHANGELOG.md +11 -0
- data/README.md +30 -28
- data/lib/capistrano/net_storage/s3/config.rb +36 -101
- data/lib/capistrano/net_storage/s3/transport.rb +90 -8
- data/lib/capistrano/net_storage/s3/version.rb +6 -4
- data/lib/capistrano/net_storage/s3.rb +14 -4
- metadata +3 -7
- data/.travis.yml +0 -12
- data/lib/capistrano/net_storage/s3/base.rb +0 -18
- data/lib/capistrano/net_storage/s3/broker/aws_cli.rb +0 -104
- data/lib/capistrano/net_storage/s3/broker/base.rb +0 -38
- data/lib/capistrano/net_storage/s3/error.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70af8342361107fa073b2c1dcb2ab36ef8e95b12d16730efdfd19e1490872b98
|
4
|
+
data.tar.gz: 3689224a25a2bd3a9ef29d5cd7947f5c6c53e1d0f5ac753b3d97117248496e1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35deda7d822adbfe5b8982736399a83a9360022d00366bf12c6441ceb6be9eb8d20ca38f056b94eb70442bf339ffcc6b473550a340b04fd4da28f7118db6e0b2
|
7
|
+
data.tar.gz: 7d0d46015d5a8c848458c0aebea094113ca52a1222a15aee04e23dbc724412c80e2f09d8993e05dc790b6174a3dc467c9cb2d6aa3f54b10d74eb1bd10107d328
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- '2.7'
|
18
|
+
- '3.0'
|
19
|
+
- '3.1'
|
20
|
+
- '3.2'
|
21
|
+
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v3
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
28
|
+
bundler-cache: true
|
29
|
+
- name: Run the default task
|
30
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 1.0.0 (2023/08/07)
|
2
|
+
|
3
|
+
Major Update by @aeroastro
|
4
|
+
|
5
|
+
Improvement:
|
6
|
+
|
7
|
+
* `--no-progress` option is passed to `aws cp` to keep console quiet (#7)
|
8
|
+
* README.md has been changed not to `require 'capistrano-net_storage-s3` by bundler (#8)
|
9
|
+
* Major improvement for `Capistrano::NetStorage` version 1.0.0 (#9, #10, #11)
|
10
|
+
* GitHub Actions has been introduced (#12)
|
11
|
+
|
1
12
|
## 0.2.3 (2017/5/10)
|
2
13
|
|
3
14
|
Enhancement:
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
[](https://badge.fury.io/rb/capistrano-net_storage-s3)
|
2
|
-
[](https://github.com/DeNADev/capistrano-net_storage-s3/actions/workflows/test.yml?query=branch%3Amaster)
|
3
3
|
# Capistrano::NetStorage::S3
|
4
4
|
|
5
5
|
**Capistrano::NetStorage::S3** is a transport plugin of
|
6
6
|
[Capistrano::NetStorage](https://github.com/DeNADev/capistrano-net_storage) to deploy application
|
7
|
-
via [Amazon S3](https://aws.amazon.com/s3/).
|
7
|
+
via [Amazon S3](https://aws.amazon.com/s3/).
|
8
8
|
And Capistrano::NetStorage is a plugin of [Capistrano](http://capistranorb.com/).
|
9
9
|
|
10
10
|
## Installation
|
@@ -12,7 +12,7 @@ And Capistrano::NetStorage is a plugin of [Capistrano](http://capistranorb.com/)
|
|
12
12
|
Add this line to your application's Gemfile:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem 'capistrano-net_storage-s3'
|
15
|
+
gem 'capistrano-net_storage-s3', require: false
|
16
16
|
```
|
17
17
|
|
18
18
|
And then execute:
|
@@ -27,21 +27,32 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
Set Capistrano variables by `set name, value`.
|
29
29
|
|
30
|
+
#### General Settings
|
31
|
+
|
32
|
+
Name | Default | Description
|
33
|
+
------|---------|------------
|
34
|
+
`:net_storage_transport` | NO DEFAULT | Set `Capistrano::NetStorage::S3::Transport`
|
35
|
+
`:net_storage_s3_bucket` | NO DEFAULT | S3 bucket name (e.g. `"your-bucket-name"` )
|
36
|
+
`:net_storage_s3_archives_directory` | `"/"` | Directory for application archives in S3 bucket
|
37
|
+
|
38
|
+
#### Settings for AWS
|
39
|
+
|
30
40
|
Name | Default | Description
|
31
41
|
------|---------|------------
|
32
|
-
`:scm` | `nil` | Set `:net_storage` for capistrano before v3.7
|
33
|
-
`:net_storage_transport` | `nil` | Set `Capistrano::NetStorage::S3::Transport`
|
34
|
-
`:net_storage_s3_broker` | `:aws_cli` | Type of transportation broker
|
35
42
|
`:net_storage_s3_aws_access_key_id` | `ENV['AWS_ACCESS_KEY_ID']` | AWS Access Key ID
|
36
43
|
`:net_storage_s3_aws_secret_access_key` | `ENV['AWS_SECRET_ACCESS_KEY']` | AWS Secret Access Key
|
37
44
|
`:net_storage_s3_aws_session_token` | `ENV['AWS_SESSION_TOKEN']` | AWS Session Token
|
38
45
|
`:net_storage_s3_aws_region` | `ENV['AWS_DEFAULT_REGION']` | AWS Region
|
39
46
|
`:net_storage_s3_aws_profile` | `ENV['AWS_DEFAULT_PROFILE']` | AWS Profile
|
40
47
|
`:net_storage_s3_aws_config_file` | `ENV['AWS_CONFIG_FILE']` | AWS Config File
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
|
49
|
+
#### Other Settings
|
50
|
+
|
51
|
+
**NOTE: We strongly recommend the defaults for integrity and performance. Change at your own risk.**
|
52
|
+
|
53
|
+
Name | Default | Description
|
54
|
+
------|---------|------------
|
55
|
+
`:net_storage_s3_max_retry` | `3` | Max retry to download from S3 to each servers
|
45
56
|
|
46
57
|
See also
|
47
58
|
[the configuration section of Capistrano::NetStorage](https://github.com/DeNADev/capistrano-net_storage#configuration).
|
@@ -58,12 +69,8 @@ require 'capistrano/setup'
|
|
58
69
|
require 'capistrano/deploy'
|
59
70
|
|
60
71
|
# Includes tasks from other gems included in your Gemfile
|
61
|
-
|
62
|
-
|
63
|
-
else
|
64
|
-
require "capistrano/net_storage/plugin"
|
65
|
-
install_plugin Capistrano::NetStorage::Plugin
|
66
|
-
end
|
72
|
+
require "capistrano/net_storage/plugin"
|
73
|
+
install_plugin Capistrano::NetStorage::Plugin
|
67
74
|
|
68
75
|
# Load transport plugin for Capistrano::NetStorage
|
69
76
|
require 'capistrano/net_storage/s3'
|
@@ -72,21 +79,16 @@ require 'capistrano/net_storage/s3'
|
|
72
79
|
Edit your `config/deploy.rb`:
|
73
80
|
|
74
81
|
```ruby
|
75
|
-
if Gem::Version.new(Capistrano::VERSION) < Gem::Version.new('3.7.0')
|
76
|
-
set :scm, :net_storage
|
77
|
-
end
|
78
82
|
set :net_storage_transport, Capistrano::NetStorage::S3::Transport
|
79
|
-
|
80
|
-
# set :net_storage_with_bundle, true
|
81
|
-
# set :net_storage_archiver, Capistrano::NetStorage::Archiver::TarGzip
|
82
|
-
set :net_storage_s3_bucket, 'example-bucket'
|
83
|
-
# set :net_storage_s3_archives_directory, your_favorite_directory_path
|
84
|
-
```
|
83
|
+
set :net_storage_config_files, Pathname('path/to/config').glob('*.yml')
|
85
84
|
|
86
|
-
|
85
|
+
# These settings upload archives to s3://bucket-for-deployment/api/#{sha1_hash}.tar.gz
|
86
|
+
set :net_storage_s3_bucket, 'bucket-for-deployment'
|
87
|
+
set :net_storage_s3_archives_directory 'api'
|
87
88
|
|
88
|
-
|
89
|
-
|
89
|
+
set :net_storage_s3_aws_config_file, '~/.aws/config'
|
90
|
+
# set :net_storage_s3_aws_profile, 'some-name' # If you are using multiple profiles
|
91
|
+
```
|
90
92
|
|
91
93
|
## License
|
92
94
|
|
@@ -1,132 +1,67 @@
|
|
1
1
|
require 'uri'
|
2
2
|
|
3
|
-
require 'capistrano/net_storage/s3/base'
|
4
|
-
require 'capistrano/net_storage/s3/error'
|
5
|
-
require 'capistrano/net_storage/s3/broker/aws_cli'
|
6
|
-
|
7
3
|
class Capistrano::NetStorage::S3
|
8
4
|
class Config
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
5
|
+
def aws_environments
|
6
|
+
{
|
7
|
+
aws_config_file: aws_config_file,
|
8
|
+
aws_default_profile: aws_profile,
|
9
|
+
aws_default_region: aws_region,
|
10
|
+
aws_access_key_id: aws_access_key_id,
|
11
|
+
aws_secret_access_key: aws_secret_access_key,
|
12
|
+
aws_session_token: aws_session_token,
|
13
|
+
}.compact
|
20
14
|
end
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
# @return [String] AWS Access Key ID
|
25
|
-
def aws_access_key_id
|
26
|
-
@aws_access_key_id ||= fetch(:net_storage_s3_aws_access_key_id, ENV['AWS_ACCESS_KEY_ID'])
|
16
|
+
def bucket
|
17
|
+
fetch(:net_storage_s3_bucket, -> { raise ArgumentError, ':net_storage_s3_bucket is not configured!' })
|
27
18
|
end
|
28
19
|
|
29
|
-
|
30
|
-
|
31
|
-
@aws_secret_access_key ||= fetch(:net_storage_s3_aws_secret_access_key)
|
32
|
-
@aws_secret_access_key ||= ENV['AWS_SECRET_ACCESS_KEY']
|
20
|
+
def archives_url
|
21
|
+
URI.parse("s3://#{bucket}") + archives_directory
|
33
22
|
end
|
34
23
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
24
|
+
def archive_url
|
25
|
+
revision = fetch(:current_revision)
|
26
|
+
raise ArgumentError, ':current_revision is not set! Your deployment flow might be buggy.' unless revision
|
39
27
|
|
40
|
-
|
41
|
-
def aws_region
|
42
|
-
@aws_region ||= fetch(:net_storage_s3_aws_region, ENV['AWS_DEFAULT_REGION'])
|
28
|
+
archives_url + "#{revision}.#{Capistrano::NetStorage.config.archive_file_extension}"
|
43
29
|
end
|
44
30
|
|
45
|
-
|
46
|
-
def aws_profile
|
47
|
-
@aws_profile ||= fetch(:net_storage_s3_aws_profile, ENV['AWS_DEFAULT_PROFILE'])
|
48
|
-
end
|
31
|
+
private
|
49
32
|
|
50
|
-
|
51
|
-
|
52
|
-
@aws_config_file ||= fetch(:net_storage_s3_aws_config_file, ENV['AWS_CONFIG_FILE'])
|
53
|
-
end
|
33
|
+
def archives_directory
|
34
|
+
directory = fetch(:net_storage_s3_archives_directory, '/')
|
54
35
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
environments = {}
|
59
|
-
environments[:aws_config_file] = aws_config_file if aws_config_file
|
60
|
-
environments[:aws_default_profile] = aws_profile if aws_profile
|
61
|
-
environments[:aws_default_region] = aws_region if aws_region
|
62
|
-
environments[:aws_access_key_id] = aws_access_key_id if aws_access_key_id
|
63
|
-
environments[:aws_secret_access_key] = aws_secret_access_key if aws_secret_access_key
|
64
|
-
environments[:aws_session_token] = aws_session_token if aws_session_token
|
65
|
-
environments
|
66
|
-
end
|
67
|
-
end
|
36
|
+
# Make it absolute directory path from root
|
37
|
+
directory = "#{directory}/" unless directory.end_with?('/')
|
38
|
+
directory = "/#{directory}" unless directory.start_with?('/')
|
68
39
|
|
69
|
-
|
70
|
-
# @return [String]
|
71
|
-
def bucket
|
72
|
-
@bucket ||= begin
|
73
|
-
unless bucket = fetch(:net_storage_s3_bucket)
|
74
|
-
raise Capistrano::NetStorage::S3::Error, ':net_storage_s3_bucket is not configured!'
|
75
|
-
end
|
76
|
-
bucket
|
77
|
-
end
|
40
|
+
directory
|
78
41
|
end
|
79
42
|
|
80
|
-
|
81
|
-
|
82
|
-
def bucket_url
|
83
|
-
@bucket_url ||= URI.parse("s3://#{bucket}")
|
43
|
+
def aws_access_key_id
|
44
|
+
fetch(:net_storage_s3_aws_access_key_id, ENV['AWS_ACCESS_KEY_ID'])
|
84
45
|
end
|
85
46
|
|
86
|
-
|
87
|
-
|
88
|
-
def archives_directory
|
89
|
-
# append '/' in case missing
|
90
|
-
@archives_directory ||= begin
|
91
|
-
dir = fetch(:net_storage_s3_archives_directory)
|
92
|
-
dir.sub(%r{[^/]\Z}, '\&/') if dir
|
93
|
-
end
|
47
|
+
def aws_secret_access_key
|
48
|
+
fetch(:net_storage_s3_aws_secret_access_key, ENV['AWS_SECRET_ACCESS_KEY'])
|
94
49
|
end
|
95
50
|
|
96
|
-
|
97
|
-
|
98
|
-
def archives_url
|
99
|
-
@archives_url ||= begin
|
100
|
-
if archives_directory
|
101
|
-
bucket_url + archives_directory
|
102
|
-
else
|
103
|
-
bucket_url
|
104
|
-
end
|
105
|
-
end
|
51
|
+
def aws_session_token
|
52
|
+
fetch(:net_storage_s3_aws_session_token, ENV['AWS_SESSION_TOKEN'])
|
106
53
|
end
|
107
54
|
|
108
|
-
|
109
|
-
|
110
|
-
def archive_url
|
111
|
-
@archive_url ||= begin
|
112
|
-
unless revision = fetch(:current_revision)
|
113
|
-
raise Capistrano::NetStorage::Error, ':current_revision is not set!'
|
114
|
-
end
|
115
|
-
archive_file = "#{revision}.#{Capistrano::NetStorage.config.archive_suffix}"
|
116
|
-
archives_url + archive_file
|
117
|
-
end
|
55
|
+
def aws_region
|
56
|
+
fetch(:net_storage_s3_aws_region, ENV['AWS_DEFAULT_REGION'])
|
118
57
|
end
|
119
58
|
|
120
|
-
|
121
|
-
|
122
|
-
def max_retry
|
123
|
-
@max_retry ||= fetch(:net_storage_s3_max_retry, 3)
|
59
|
+
def aws_profile
|
60
|
+
fetch(:net_storage_s3_aws_profile, ENV['AWS_DEFAULT_PROFILE'])
|
124
61
|
end
|
125
62
|
|
126
|
-
|
127
|
-
|
128
|
-
def s3_keep_releases
|
129
|
-
@s3_keep_releases ||= fetch(:net_storage_s3_keep_releases, fetch(:keep_releases, 5))
|
63
|
+
def aws_config_file
|
64
|
+
fetch(:net_storage_s3_aws_config_file, ENV['AWS_CONFIG_FILE'])
|
130
65
|
end
|
131
66
|
end
|
132
67
|
end
|
@@ -2,16 +2,98 @@ require 'forwardable'
|
|
2
2
|
|
3
3
|
require 'capistrano/net_storage/transport/base'
|
4
4
|
|
5
|
-
require 'capistrano/net_storage/s3
|
6
|
-
require 'capistrano/net_storage/s3/config'
|
5
|
+
require 'capistrano/net_storage/s3'
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
module Capistrano
|
8
|
+
module NetStorage
|
9
|
+
class S3
|
10
|
+
class Transport < Capistrano::NetStorage::Transport::Base
|
11
|
+
# These values are intentionally separated from config and fixed.
|
12
|
+
# If you have trouble with these defaults for 10^2 ~ 10^3 servers, please contact us on GitHub.
|
13
|
+
JITTER_DURATION_TO_DOWNLOAD = 4.0
|
14
|
+
MAX_RETRY = 3 # TODO: We need to rewrite this for large-scale AWS S3 stability
|
15
|
+
KEEP_FILE = '.keep'
|
11
16
|
|
12
|
-
|
17
|
+
def check
|
18
|
+
config = Capistrano::NetStorage::S3.config
|
13
19
|
|
14
|
-
|
15
|
-
|
20
|
+
# We check both read and write permissions with aws s3 command
|
21
|
+
run_locally_with_aws_env do
|
22
|
+
unless test :aws, 's3', 'ls', config.archives_url
|
23
|
+
keep = Tempfile.create.path
|
24
|
+
execute :aws, 's3', 'cp', keep, config.archives_url + KEEP_FILE
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def archive_exists?
|
30
|
+
config = Capistrano::NetStorage::S3.config
|
31
|
+
|
32
|
+
run_locally_with_aws_env do
|
33
|
+
test :aws, 's3', 'ls', config.archive_url
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def upload
|
38
|
+
config = Capistrano::NetStorage::S3.config
|
39
|
+
ns_config = Capistrano::NetStorage.config
|
40
|
+
|
41
|
+
run_locally_with_aws_env do
|
42
|
+
execute :aws, 's3', 'cp', '--no-progress', ns_config.local_archive_path, config.archive_url
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def download
|
47
|
+
config = Capistrano::NetStorage::S3.config
|
48
|
+
ns_config = Capistrano::NetStorage.config
|
49
|
+
|
50
|
+
on release_roles(:all), in: :groups, limit: ns_config.max_parallels do
|
51
|
+
Retryable.retryable(tries: MAX_RETRY, sleep: 0.1) do
|
52
|
+
within releases_path do
|
53
|
+
with(config.aws_environments) do
|
54
|
+
sleep Random.rand(JITTER_DURATION_TO_DOWNLOAD)
|
55
|
+
execute :aws, 's3', 'cp', '--no-progress', config.archive_url, ns_config.archive_path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def cleanup
|
63
|
+
config = Capistrano::NetStorage::S3.config
|
64
|
+
ns_config = Capistrano::NetStorage.config
|
65
|
+
|
66
|
+
files = run_locally_with_aws_env do
|
67
|
+
capture :aws, 's3', 'ls', config.archives_url
|
68
|
+
end.lines.sort.map { |line| line.chomp.split(' ').last }
|
69
|
+
releases = files - [KEEP_FILE]
|
70
|
+
|
71
|
+
if releases.count > ns_config.keep_remote_archives
|
72
|
+
run_locally_with_aws_env do
|
73
|
+
info "Keeping #{ns_config.keep_remote_archives} of #{releases.count} in #{config.archives_url}"
|
74
|
+
(releases - releases.last(ns_config.keep_remote_archives)).each do |release|
|
75
|
+
execute :aws, 's3', 'rm', config.archives_url + release
|
76
|
+
end
|
77
|
+
end
|
78
|
+
else
|
79
|
+
run_locally do
|
80
|
+
info "No old archives (keeping newest #{ns_config.keep_remote_archives}) in #{config.archives_url}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def run_locally_with_aws_env(&block)
|
88
|
+
config = Capistrano::NetStorage::S3.config
|
89
|
+
|
90
|
+
run_locally do
|
91
|
+
with(config.aws_environments) do
|
92
|
+
instance_eval(&block)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
16
98
|
end
|
17
99
|
end
|
@@ -1,8 +1,18 @@
|
|
1
|
-
require 'capistrano/net_storage/s3/base'
|
2
|
-
require 'capistrano/net_storage/s3/error'
|
3
1
|
require 'capistrano/net_storage/s3/config'
|
4
|
-
require 'capistrano/net_storage/s3/broker/aws_cli'
|
5
2
|
require 'capistrano/net_storage/s3/transport'
|
6
|
-
|
3
|
+
|
4
|
+
module Capistrano
|
5
|
+
module NetStorage
|
6
|
+
class S3
|
7
|
+
class << self
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
def setup!(config:)
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
7
17
|
|
8
18
|
Capistrano::NetStorage::S3.setup!(config: Capistrano::NetStorage::S3::Config.new)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-net_storage-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- progrhyme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano-net_storage
|
@@ -88,9 +88,9 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
91
|
+
- ".github/workflows/test.yml"
|
91
92
|
- ".gitignore"
|
92
93
|
- ".rspec"
|
93
|
-
- ".travis.yml"
|
94
94
|
- CHANGELOG.md
|
95
95
|
- Gemfile
|
96
96
|
- LICENSE.txt
|
@@ -99,11 +99,7 @@ files:
|
|
99
99
|
- capistrano-net_storage-s3.gemspec
|
100
100
|
- lib/capistrano-net_storage-s3.rb
|
101
101
|
- lib/capistrano/net_storage/s3.rb
|
102
|
-
- lib/capistrano/net_storage/s3/base.rb
|
103
|
-
- lib/capistrano/net_storage/s3/broker/aws_cli.rb
|
104
|
-
- lib/capistrano/net_storage/s3/broker/base.rb
|
105
102
|
- lib/capistrano/net_storage/s3/config.rb
|
106
|
-
- lib/capistrano/net_storage/s3/error.rb
|
107
103
|
- lib/capistrano/net_storage/s3/transport.rb
|
108
104
|
- lib/capistrano/net_storage/s3/version.rb
|
109
105
|
homepage: https://github.com/DeNADev/capistrano-net_storage-s3
|
data/.travis.yml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.6.3
|
5
|
-
- 2.5.5
|
6
|
-
- 2.4.6
|
7
|
-
before_install: gem install bundler
|
8
|
-
install: bundle install
|
9
|
-
script: bundle exec rake spec
|
10
|
-
notifications:
|
11
|
-
slack:
|
12
|
-
secure: WFEsKPeewkV6n/LmpsvLbu17nT5AWxVr1yglUjhCEe8OGIukTOpTbdsnhv9ticj0vXNdKZZRQEe4B0BhC8Fn+iPbFLyi1Z4is7dmABVU+b1qSOKIQlCCoPqa8RzYuVPYzMcVs9E1ldVdrQfLXKYoVeFAFeFSzcrf4mmTDrJbHhOXFIp1GYfYnhCIf01R72pcc2sHfWrzL3croIAqVYFiYJlimjQgduqQGVnyQjCeFmERCnnJU4t4VUlDU1gxTi3VYLfUtyUFyo5Kp+msRMbjr7LVuXyv/JplnNX3skG7VYN2nyhL6VuuOMAfCDpDCeCpH5mJcB1xLagide+GgDVYPJMJG419Ao7vCNI+1cl4VojT8aZKOs6vR7AMBSCP6gittrDIWOCuD61fc5HLFBSzL5dD5u2b2AxAUuODohNKigKwY59tE5CePuMycS/wVaFBtZjAKwDJDKU95m8JCtqJGzHQ0mEMKrXKICal9O7GWwEuEV+EnU+yzk+ZqWM6AHpGJ48DSm3pMnlnoPy3SBs4W8tFH+IS18cKBJ795Nj2vdwZFEYUEo0UwZrch/STY0/rPHayts9/7vgzZOIur168kxIw5bDNisPqzMTeNiYECnNLYWBSa0Xqn8mKPu52GVJYW6L0Wa8LRxln6BcNv2DkS+JFjyUC04T5wAdD4ADnQd4=
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module Capistrano
|
4
|
-
module NetStorage
|
5
|
-
class S3
|
6
|
-
class << self
|
7
|
-
attr_reader :config
|
8
|
-
|
9
|
-
extend Forwardable
|
10
|
-
def_delegator :config, :broker
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.setup!(params)
|
14
|
-
@config = params[:config]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'time'
|
3
|
-
require 'retryable'
|
4
|
-
|
5
|
-
require 'capistrano/net_storage/s3/base'
|
6
|
-
require 'capistrano/net_storage/s3/broker/base'
|
7
|
-
|
8
|
-
class Capistrano::NetStorage::S3::Broker::AwsCLI < Capistrano::NetStorage::S3::Broker::Base
|
9
|
-
def check
|
10
|
-
execute_aws_s3('ls', config.bucket_url)
|
11
|
-
end
|
12
|
-
|
13
|
-
def find_uploaded
|
14
|
-
if capture_aws_s3('ls', config.archive_url)
|
15
|
-
set :net_storage_uploaded_archive, true
|
16
|
-
end
|
17
|
-
rescue SSHKit::StandardError
|
18
|
-
c = config
|
19
|
-
run_locally do
|
20
|
-
info "Archive is not found as #{c.archive_url}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def upload
|
25
|
-
c = config
|
26
|
-
ns = net_storage
|
27
|
-
Retryable.retryable(tries: c.max_retry, sleep: 0.1) do
|
28
|
-
execute_aws_s3('cp', '--no-progress', ns.local_archive_path, c.archive_url)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def download
|
33
|
-
c = config
|
34
|
-
ns = net_storage
|
35
|
-
on ns.servers, in: :groups, limit: ns.max_parallels do
|
36
|
-
Retryable.retryable(tries: c.max_retry, sleep: 0.1) do
|
37
|
-
within releases_path do
|
38
|
-
with(c.aws_environments) do
|
39
|
-
execute :aws, 's3', 'cp', '--no-progress', c.archive_url, ns.archive_path
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def cleanup
|
47
|
-
c = config
|
48
|
-
list_args = %W(--bucket #{c.bucket} --output json)
|
49
|
-
if c.archives_directory
|
50
|
-
list_args += %W(--prefix #{c.archives_directory})
|
51
|
-
end
|
52
|
-
output = capture_aws_s3api('list-objects', list_args)
|
53
|
-
return if output.empty?
|
54
|
-
|
55
|
-
objects = JSON.parse(output)['Contents']
|
56
|
-
sorted = objects.sort_by { |obj| Time.parse(obj['LastModified']) }
|
57
|
-
c.s3_keep_releases.times do
|
58
|
-
break if sorted.empty?
|
59
|
-
sorted.pop
|
60
|
-
end
|
61
|
-
sorted.each do |obj|
|
62
|
-
delete_args = %W(--bucket #{c.bucket} --key #{obj['Key']})
|
63
|
-
execute_aws_s3api('delete-object', *delete_args)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def execute_aws_s3(cmd, *args)
|
70
|
-
c = config
|
71
|
-
run_locally do
|
72
|
-
with(c.aws_environments) do
|
73
|
-
execute :aws, 's3', cmd, *args
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def capture_aws_s3(cmd, *args)
|
79
|
-
c = config
|
80
|
-
run_locally do
|
81
|
-
with(c.aws_environments) do
|
82
|
-
capture :aws, 's3', cmd, *args
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def execute_aws_s3api(cmd, *args)
|
88
|
-
c = config
|
89
|
-
run_locally do
|
90
|
-
with(c.aws_environments) do
|
91
|
-
execute :aws, 's3api', cmd, *args
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def capture_aws_s3api(cmd, *args)
|
97
|
-
c = config
|
98
|
-
run_locally do
|
99
|
-
with(c.aws_environments) do
|
100
|
-
capture :aws, 's3api', cmd, *args
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'capistrano/net_storage/s3/base'
|
2
|
-
|
3
|
-
class Capistrano::NetStorage::S3
|
4
|
-
module Broker
|
5
|
-
# @abstract
|
6
|
-
class Base
|
7
|
-
# @abstract
|
8
|
-
def check
|
9
|
-
raise NotImplementedError
|
10
|
-
end
|
11
|
-
|
12
|
-
# @abstract
|
13
|
-
def find_uploaded
|
14
|
-
raise NotImplementedError
|
15
|
-
end
|
16
|
-
|
17
|
-
# @abstract
|
18
|
-
def upload
|
19
|
-
raise NotImplementedError
|
20
|
-
end
|
21
|
-
|
22
|
-
# @abstract
|
23
|
-
def download
|
24
|
-
raise NotImplementedError
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def config
|
30
|
-
Capistrano::NetStorage::S3.config
|
31
|
-
end
|
32
|
-
|
33
|
-
def net_storage
|
34
|
-
Capistrano::NetStorage.config
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|