capistrano 2.8.0 → 3.19.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 +7 -0
- data/.docker/Dockerfile +7 -0
- data/.docker/ssh_key_rsa +49 -0
- data/.docker/ssh_key_rsa.pub +1 -0
- data/.docker/ubuntu_setup.sh +23 -0
- data/.github/issue_template.md +19 -0
- data/.github/pull_request_template.md +22 -0
- data/.github/release-drafter.yml +25 -0
- data/.github/workflows/ci.yml +80 -0
- data/.github/workflows/release-drafter.yml +18 -0
- data/.gitignore +23 -8
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +1 -0
- data/CONTRIBUTING.md +63 -0
- data/DEVELOPMENT.md +112 -0
- data/Gemfile +42 -9
- data/LICENSE.txt +21 -0
- data/README.md +221 -0
- data/RELEASING.md +17 -0
- data/Rakefile +17 -8
- data/UPGRADING-3.7.md +86 -0
- data/bin/cap +2 -3
- data/bin/capify +7 -89
- data/capistrano.gemspec +29 -43
- data/docker-compose.yml +8 -0
- data/features/configuration.feature +28 -0
- data/features/deploy.feature +92 -0
- data/features/deploy_failure.feature +17 -0
- data/features/doctor.feature +11 -0
- data/features/installation.feature +21 -0
- data/features/sshconnect.feature +11 -0
- data/features/stage_failure.feature +9 -0
- data/features/step_definitions/assertions.rb +162 -0
- data/features/step_definitions/cap_commands.rb +21 -0
- data/features/step_definitions/setup.rb +91 -0
- data/features/subdirectory.feature +9 -0
- data/features/support/docker_gateway.rb +53 -0
- data/features/support/env.rb +1 -0
- data/features/support/remote_command_helpers.rb +29 -0
- data/features/support/remote_ssh_helpers.rb +33 -0
- data/lib/Capfile +3 -0
- data/lib/capistrano/all.rb +17 -0
- data/lib/capistrano/application.rb +153 -0
- data/lib/capistrano/configuration/empty_filter.rb +9 -0
- data/lib/capistrano/configuration/filter.rb +26 -0
- data/lib/capistrano/configuration/host_filter.rb +29 -0
- data/lib/capistrano/configuration/null_filter.rb +9 -0
- data/lib/capistrano/configuration/plugin_installer.rb +51 -0
- data/lib/capistrano/configuration/question.rb +76 -0
- data/lib/capistrano/configuration/role_filter.rb +29 -0
- data/lib/capistrano/configuration/scm_resolver.rb +149 -0
- data/lib/capistrano/configuration/server.rb +137 -0
- data/lib/capistrano/configuration/servers.rb +56 -96
- data/lib/capistrano/configuration/validated_variables.rb +110 -0
- data/lib/capistrano/configuration/variables.rb +79 -94
- data/lib/capistrano/configuration.rb +178 -33
- data/lib/capistrano/console.rb +1 -0
- data/lib/capistrano/defaults.rb +36 -0
- data/lib/capistrano/deploy.rb +3 -0
- data/lib/capistrano/doctor/environment_doctor.rb +19 -0
- data/lib/capistrano/doctor/gems_doctor.rb +45 -0
- data/lib/capistrano/doctor/output_helpers.rb +79 -0
- data/lib/capistrano/doctor/servers_doctor.rb +105 -0
- data/lib/capistrano/doctor/variables_doctor.rb +74 -0
- data/lib/capistrano/doctor.rb +6 -0
- data/lib/capistrano/dotfile.rb +2 -0
- data/lib/capistrano/dsl/env.rb +43 -0
- data/lib/capistrano/dsl/paths.rb +89 -0
- data/lib/capistrano/dsl/stages.rb +31 -0
- data/lib/capistrano/dsl/task_enhancements.rb +61 -0
- data/lib/capistrano/dsl.rb +95 -0
- data/lib/capistrano/framework.rb +2 -0
- data/lib/capistrano/i18n.rb +46 -0
- data/lib/capistrano/immutable_task.rb +30 -0
- data/lib/capistrano/install.rb +1 -0
- data/lib/capistrano/plugin.rb +95 -0
- data/lib/capistrano/proc_helpers.rb +13 -0
- data/lib/capistrano/scm/git.rb +105 -0
- data/lib/capistrano/scm/hg.rb +55 -0
- data/lib/capistrano/scm/plugin.rb +13 -0
- data/lib/capistrano/scm/svn.rb +56 -0
- data/lib/capistrano/scm/tasks/git.rake +84 -0
- data/lib/capistrano/scm/tasks/hg.rake +53 -0
- data/lib/capistrano/scm/tasks/svn.rake +53 -0
- data/lib/capistrano/scm.rb +115 -0
- data/lib/capistrano/setup.rb +36 -0
- data/lib/capistrano/tasks/console.rake +25 -0
- data/lib/capistrano/tasks/deploy.rake +280 -0
- data/lib/capistrano/tasks/doctor.rake +24 -0
- data/lib/capistrano/tasks/framework.rake +67 -0
- data/lib/capistrano/tasks/install.rake +41 -0
- data/lib/capistrano/templates/Capfile +38 -0
- data/lib/capistrano/templates/deploy.rb.erb +39 -0
- data/lib/capistrano/templates/stage.rb.erb +61 -0
- data/lib/capistrano/upload_task.rb +9 -0
- data/lib/capistrano/version.rb +1 -14
- data/lib/capistrano/version_validator.rb +32 -0
- data/lib/capistrano.rb +0 -3
- data/spec/integration/dsl_spec.rb +632 -0
- data/spec/integration_spec_helper.rb +5 -0
- data/spec/lib/capistrano/application_spec.rb +60 -0
- data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/filter_spec.rb +109 -0
- data/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
- data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
- data/spec/lib/capistrano/configuration/question_spec.rb +92 -0
- data/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
- data/spec/lib/capistrano/configuration/scm_resolver_spec.rb +56 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +309 -0
- data/spec/lib/capistrano/configuration/servers_spec.rb +331 -0
- data/spec/lib/capistrano/configuration_spec.rb +357 -0
- data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
- data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
- data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
- data/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
- data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +228 -0
- data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +108 -0
- data/spec/lib/capistrano/dsl_spec.rb +125 -0
- data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
- data/spec/lib/capistrano/plugin_spec.rb +84 -0
- data/spec/lib/capistrano/scm/git_spec.rb +194 -0
- data/spec/lib/capistrano/scm/hg_spec.rb +109 -0
- data/spec/lib/capistrano/scm/svn_spec.rb +137 -0
- data/spec/lib/capistrano/scm_spec.rb +103 -0
- data/spec/lib/capistrano/upload_task_spec.rb +19 -0
- data/spec/lib/capistrano/version_validator_spec.rb +118 -0
- data/spec/lib/capistrano_spec.rb +7 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/matchers.rb +5 -0
- data/spec/support/tasks/database.rake +11 -0
- data/spec/support/tasks/fail.rake +8 -0
- data/spec/support/tasks/failed.rake +5 -0
- data/spec/support/tasks/plugin.rake +6 -0
- data/spec/support/tasks/root.rake +11 -0
- data/spec/support/test_app.rb +205 -0
- metadata +234 -208
- data/.rvmrc +0 -1
- data/CHANGELOG +0 -954
- data/README.mdown +0 -76
- data/lib/capistrano/callback.rb +0 -45
- data/lib/capistrano/cli/execute.rb +0 -85
- data/lib/capistrano/cli/help.rb +0 -125
- data/lib/capistrano/cli/help.txt +0 -81
- data/lib/capistrano/cli/options.rb +0 -243
- data/lib/capistrano/cli/ui.rb +0 -40
- data/lib/capistrano/cli.rb +0 -47
- data/lib/capistrano/command.rb +0 -286
- data/lib/capistrano/configuration/actions/file_transfer.rb +0 -51
- data/lib/capistrano/configuration/actions/inspect.rb +0 -46
- data/lib/capistrano/configuration/actions/invocation.rb +0 -298
- data/lib/capistrano/configuration/callbacks.rb +0 -148
- data/lib/capistrano/configuration/connections.rb +0 -230
- data/lib/capistrano/configuration/execution.rb +0 -143
- data/lib/capistrano/configuration/loading.rb +0 -197
- data/lib/capistrano/configuration/namespaces.rb +0 -197
- data/lib/capistrano/configuration/roles.rb +0 -73
- data/lib/capistrano/errors.rb +0 -19
- data/lib/capistrano/ext/string.rb +0 -5
- data/lib/capistrano/extensions.rb +0 -57
- data/lib/capistrano/logger.rb +0 -59
- data/lib/capistrano/processable.rb +0 -53
- data/lib/capistrano/recipes/compat.rb +0 -32
- data/lib/capistrano/recipes/deploy/assets.rb +0 -57
- data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
- data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -111
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
- data/lib/capistrano/recipes/deploy/scm/base.rb +0 -196
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
- data/lib/capistrano/recipes/deploy/scm/git.rb +0 -282
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
- data/lib/capistrano/recipes/deploy/scm/none.rb +0 -44
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -138
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
- data/lib/capistrano/recipes/deploy/scm.rb +0 -19
- data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -88
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -224
- data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
- data/lib/capistrano/recipes/deploy/strategy.rb +0 -19
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/recipes/deploy.rb +0 -568
- data/lib/capistrano/recipes/standard.rb +0 -37
- data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/role.rb +0 -102
- data/lib/capistrano/server_definition.rb +0 -56
- data/lib/capistrano/shell.rb +0 -260
- data/lib/capistrano/ssh.rb +0 -101
- data/lib/capistrano/task_definition.rb +0 -75
- data/lib/capistrano/transfer.rb +0 -216
- data/rvmrc.sample +0 -1
- data/test/cli/execute_test.rb +0 -132
- data/test/cli/help_test.rb +0 -165
- data/test/cli/options_test.rb +0 -329
- data/test/cli/ui_test.rb +0 -28
- data/test/cli_test.rb +0 -17
- data/test/command_test.rb +0 -289
- data/test/configuration/actions/file_transfer_test.rb +0 -61
- data/test/configuration/actions/inspect_test.rb +0 -65
- data/test/configuration/actions/invocation_test.rb +0 -247
- data/test/configuration/callbacks_test.rb +0 -220
- data/test/configuration/connections_test.rb +0 -420
- data/test/configuration/execution_test.rb +0 -175
- data/test/configuration/loading_test.rb +0 -132
- data/test/configuration/namespace_dsl_test.rb +0 -311
- data/test/configuration/roles_test.rb +0 -144
- data/test/configuration/servers_test.rb +0 -183
- data/test/configuration/variables_test.rb +0 -190
- data/test/configuration_test.rb +0 -88
- data/test/deploy/local_dependency_test.rb +0 -76
- data/test/deploy/remote_dependency_test.rb +0 -135
- data/test/deploy/scm/accurev_test.rb +0 -23
- data/test/deploy/scm/base_test.rb +0 -55
- data/test/deploy/scm/bzr_test.rb +0 -51
- data/test/deploy/scm/darcs_test.rb +0 -37
- data/test/deploy/scm/git_test.rb +0 -184
- data/test/deploy/scm/mercurial_test.rb +0 -134
- data/test/deploy/scm/none_test.rb +0 -35
- data/test/deploy/scm/subversion_test.rb +0 -32
- data/test/deploy/strategy/copy_test.rb +0 -321
- data/test/extensions_test.rb +0 -69
- data/test/fixtures/cli_integration.rb +0 -5
- data/test/fixtures/config.rb +0 -5
- data/test/fixtures/custom.rb +0 -3
- data/test/logger_test.rb +0 -123
- data/test/recipes_test.rb +0 -25
- data/test/role_test.rb +0 -11
- data/test/server_definition_test.rb +0 -121
- data/test/shell_test.rb +0 -90
- data/test/ssh_test.rb +0 -113
- data/test/task_definition_test.rb +0 -116
- data/test/transfer_test.rb +0 -160
- data/test/utils.rb +0 -37
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
desc "Execute remote commands"
|
|
2
|
+
task :console do
|
|
3
|
+
stage = fetch(:stage)
|
|
4
|
+
puts I18n.t("console.welcome", scope: :capistrano, stage: stage)
|
|
5
|
+
loop do
|
|
6
|
+
print "#{stage}> "
|
|
7
|
+
|
|
8
|
+
command = (input = $stdin.gets) ? input.chomp : "exit"
|
|
9
|
+
|
|
10
|
+
next if command.empty?
|
|
11
|
+
|
|
12
|
+
if %w{quit exit q}.include? command
|
|
13
|
+
puts t("console.bye")
|
|
14
|
+
break
|
|
15
|
+
else
|
|
16
|
+
begin
|
|
17
|
+
on roles :all do
|
|
18
|
+
execute command
|
|
19
|
+
end
|
|
20
|
+
rescue => e
|
|
21
|
+
puts e
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
namespace :deploy do
|
|
2
|
+
task :starting do
|
|
3
|
+
invoke "deploy:print_config_variables" if fetch(:print_config_variables, false)
|
|
4
|
+
invoke "deploy:check"
|
|
5
|
+
invoke "deploy:set_previous_revision"
|
|
6
|
+
invoke "deploy:set_previous_revision_time"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
task :print_config_variables do
|
|
10
|
+
puts
|
|
11
|
+
puts "------- Printing current config variables -------"
|
|
12
|
+
env.keys.each do |config_variable_key|
|
|
13
|
+
if is_question?(config_variable_key)
|
|
14
|
+
puts "#{config_variable_key.inspect} => Question (awaits user input on next fetch(#{config_variable_key.inspect}))"
|
|
15
|
+
else
|
|
16
|
+
puts "#{config_variable_key.inspect} => #{fetch(config_variable_key).inspect}"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
puts
|
|
21
|
+
puts "------- Printing current config variables of SSHKit mechanism -------"
|
|
22
|
+
puts env.backend.config.inspect
|
|
23
|
+
# puts env.backend.config.backend.config.ssh_options.inspect
|
|
24
|
+
# puts env.backend.config.command_map.defaults.inspect
|
|
25
|
+
|
|
26
|
+
puts
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
task updating: :new_release_path do
|
|
30
|
+
invoke "deploy:set_current_revision"
|
|
31
|
+
invoke "deploy:set_current_revision_time"
|
|
32
|
+
invoke "deploy:symlink:shared"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
task :reverting do
|
|
36
|
+
invoke "deploy:revert_release"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
task :publishing do
|
|
40
|
+
invoke "deploy:symlink:release"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
task :finishing do
|
|
44
|
+
invoke "deploy:cleanup"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
task :finishing_rollback do
|
|
48
|
+
invoke "deploy:cleanup_rollback"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
task :finished do
|
|
52
|
+
invoke "deploy:log_revision"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
desc "Check required files and directories exist"
|
|
56
|
+
task :check do
|
|
57
|
+
invoke "deploy:check:directories"
|
|
58
|
+
invoke "deploy:check:linked_dirs"
|
|
59
|
+
invoke "deploy:check:make_linked_dirs"
|
|
60
|
+
invoke "deploy:check:linked_files"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
namespace :check do
|
|
64
|
+
desc "Check shared and release directories exist"
|
|
65
|
+
task :directories do
|
|
66
|
+
on release_roles :all do
|
|
67
|
+
execute :mkdir, "-p", shared_path, releases_path
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
desc "Check directories to be linked exist in shared"
|
|
72
|
+
task :linked_dirs do
|
|
73
|
+
next unless any? :linked_dirs
|
|
74
|
+
on release_roles :all do
|
|
75
|
+
execute :mkdir, "-p", linked_dirs(shared_path)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
desc "Check directories of files to be linked exist in shared"
|
|
80
|
+
task :make_linked_dirs do
|
|
81
|
+
next unless any? :linked_files
|
|
82
|
+
on release_roles :all do |_host|
|
|
83
|
+
execute :mkdir, "-p", linked_file_dirs(shared_path)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
desc "Check files to be linked exist in shared"
|
|
88
|
+
task :linked_files do
|
|
89
|
+
next unless any? :linked_files
|
|
90
|
+
on release_roles :all do |host|
|
|
91
|
+
linked_files(shared_path).each do |file|
|
|
92
|
+
unless test "[ -f #{file} ]"
|
|
93
|
+
error t(:linked_file_does_not_exist, file: file, host: host)
|
|
94
|
+
exit 1
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
namespace :symlink do
|
|
102
|
+
desc "Symlink release to current"
|
|
103
|
+
task :release do
|
|
104
|
+
on release_roles :all do
|
|
105
|
+
tmp_current_path = release_path.parent.join(current_path.basename)
|
|
106
|
+
execute :ln, "-s", release_path, tmp_current_path
|
|
107
|
+
execute :mv, tmp_current_path, current_path.parent
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
desc "Symlink files and directories from shared to release"
|
|
112
|
+
task :shared do
|
|
113
|
+
invoke "deploy:symlink:linked_files"
|
|
114
|
+
invoke "deploy:symlink:linked_dirs"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
desc "Symlink linked directories"
|
|
118
|
+
task :linked_dirs do
|
|
119
|
+
next unless any? :linked_dirs
|
|
120
|
+
on release_roles :all do
|
|
121
|
+
execute :mkdir, "-p", linked_dir_parents(release_path)
|
|
122
|
+
|
|
123
|
+
fetch(:linked_dirs).each do |dir|
|
|
124
|
+
target = release_path.join(dir)
|
|
125
|
+
source = shared_path.join(dir)
|
|
126
|
+
next if test "[ -L #{target} ]"
|
|
127
|
+
execute :rm, "-rf", target if test "[ -d #{target} ]"
|
|
128
|
+
execute :ln, "-s", source, target
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
desc "Symlink linked files"
|
|
134
|
+
task :linked_files do
|
|
135
|
+
next unless any? :linked_files
|
|
136
|
+
on release_roles :all do
|
|
137
|
+
execute :mkdir, "-p", linked_file_dirs(release_path)
|
|
138
|
+
|
|
139
|
+
fetch(:linked_files).each do |file|
|
|
140
|
+
target = release_path.join(file)
|
|
141
|
+
source = shared_path.join(file)
|
|
142
|
+
next if test "[ -L #{target} ]"
|
|
143
|
+
execute :rm, target if test "[ -f #{target} ]"
|
|
144
|
+
execute :ln, "-s", source, target
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
desc "Clean up old releases"
|
|
151
|
+
task :cleanup do
|
|
152
|
+
on release_roles :all do |host|
|
|
153
|
+
releases = capture(:ls, "-x", releases_path).split
|
|
154
|
+
valid, invalid = releases.partition { |e| /^\d{14}$/ =~ e }
|
|
155
|
+
|
|
156
|
+
warn t(:skip_cleanup, host: host.to_s) if invalid.any?
|
|
157
|
+
|
|
158
|
+
if valid.count >= fetch(:keep_releases)
|
|
159
|
+
info t(:keeping_releases, host: host.to_s, keep_releases: fetch(:keep_releases), releases: valid.count)
|
|
160
|
+
directories = (valid - valid.last(fetch(:keep_releases))).map do |release|
|
|
161
|
+
releases_path.join(release).to_s
|
|
162
|
+
end
|
|
163
|
+
if test("[ -d #{current_path} ]")
|
|
164
|
+
current_release = capture(:readlink, current_path).to_s
|
|
165
|
+
if directories.include?(current_release)
|
|
166
|
+
warn t(:wont_delete_current_release, host: host.to_s)
|
|
167
|
+
directories.delete(current_release)
|
|
168
|
+
end
|
|
169
|
+
else
|
|
170
|
+
debug t(:no_current_release, host: host.to_s)
|
|
171
|
+
end
|
|
172
|
+
if directories.any?
|
|
173
|
+
directories.each_slice(100) do |directories_batch|
|
|
174
|
+
execute :rm, "-rf", *directories_batch
|
|
175
|
+
end
|
|
176
|
+
else
|
|
177
|
+
info t(:no_old_releases, host: host.to_s, keep_releases: fetch(:keep_releases))
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
desc "Remove and archive rolled-back release."
|
|
184
|
+
task :cleanup_rollback do
|
|
185
|
+
on release_roles(:all) do
|
|
186
|
+
last_release = capture(:ls, "-xt", releases_path).split.first
|
|
187
|
+
last_release_path = releases_path.join(last_release)
|
|
188
|
+
if test "[ `readlink #{current_path}` != #{last_release_path} ]"
|
|
189
|
+
execute :tar, "-czf",
|
|
190
|
+
deploy_path.join("rolled-back-release-#{last_release}.tar.gz"),
|
|
191
|
+
last_release_path
|
|
192
|
+
execute :rm, "-rf", last_release_path
|
|
193
|
+
else
|
|
194
|
+
debug "Last release is the current release, skip cleanup_rollback."
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
desc "Log details of the deploy"
|
|
200
|
+
task :log_revision do
|
|
201
|
+
on release_roles(:all) do
|
|
202
|
+
within releases_path do
|
|
203
|
+
execute :echo, %Q{"#{revision_log_message}" >> #{revision_log}}
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
desc "Revert to previous release timestamp"
|
|
209
|
+
task revert_release: :rollback_release_path do
|
|
210
|
+
on release_roles(:all) do
|
|
211
|
+
set(:revision_log_message, rollback_log_message)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
task :new_release_path do
|
|
216
|
+
set_release_path
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
task :rollback_release_path do
|
|
220
|
+
on release_roles(:all) do
|
|
221
|
+
releases = capture(:ls, "-xt", releases_path).split
|
|
222
|
+
if releases.count < 2
|
|
223
|
+
error t(:cannot_rollback)
|
|
224
|
+
exit 1
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
rollback_release = ENV["ROLLBACK_RELEASE"]
|
|
228
|
+
index = rollback_release.nil? ? 1 : releases.index(rollback_release)
|
|
229
|
+
if index.nil?
|
|
230
|
+
error t(:cannot_found_rollback_release, release: rollback_release)
|
|
231
|
+
exit 1
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
last_release = releases[index]
|
|
235
|
+
set_release_path(last_release)
|
|
236
|
+
set(:rollback_timestamp, last_release)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
desc "Place a REVISION file with the current revision SHA in the current release path"
|
|
241
|
+
task :set_current_revision do
|
|
242
|
+
on release_roles(:all) do
|
|
243
|
+
within release_path do
|
|
244
|
+
execute :echo, "\"#{fetch(:current_revision)}\" > REVISION"
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
task :set_previous_revision do
|
|
250
|
+
on release_roles(:all) do
|
|
251
|
+
target = release_path.join("REVISION")
|
|
252
|
+
if test "[ -f #{target} ]"
|
|
253
|
+
set(:previous_revision, capture(:cat, target, "2>/dev/null"))
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
desc "Place a REVISION_TIME file with the current revision commit time in the current release path"
|
|
259
|
+
task :set_current_revision_time do
|
|
260
|
+
on release_roles(:all) do
|
|
261
|
+
within release_path do
|
|
262
|
+
if fetch(:current_revision_time)
|
|
263
|
+
execute :echo, "\"#{fetch(:current_revision_time)}\" > REVISION_TIME"
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
task :set_previous_revision_time do
|
|
270
|
+
on release_roles(:all) do
|
|
271
|
+
target = release_path.join("REVISION_TIME")
|
|
272
|
+
if test "[ -f #{target} ]"
|
|
273
|
+
set(:previous_revision_time, capture(:cat, target, "2>/dev/null"))
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
task :restart
|
|
279
|
+
task :failed
|
|
280
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
desc "Display a Capistrano troubleshooting report (all doctor: tasks)"
|
|
2
|
+
task doctor: ["doctor:environment", "doctor:gems", "doctor:variables", "doctor:servers"]
|
|
3
|
+
|
|
4
|
+
namespace :doctor do
|
|
5
|
+
desc "Display Ruby environment details"
|
|
6
|
+
task :environment do
|
|
7
|
+
Capistrano::Doctor::EnvironmentDoctor.new.call
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
desc "Display Capistrano gem versions"
|
|
11
|
+
task :gems do
|
|
12
|
+
Capistrano::Doctor::GemsDoctor.new.call
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc "Display the values of all Capistrano variables"
|
|
16
|
+
task :variables do
|
|
17
|
+
Capistrano::Doctor::VariablesDoctor.new.call
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
desc "Display the effective servers configuration"
|
|
21
|
+
task :servers do
|
|
22
|
+
Capistrano::Doctor::ServersDoctor.new.call
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
namespace :deploy do
|
|
2
|
+
desc "Start a deployment, make sure server(s) ready."
|
|
3
|
+
task :starting do
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
desc "Started"
|
|
7
|
+
task :started do
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
desc "Update server(s) by setting up a new release."
|
|
11
|
+
task :updating do
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
desc "Updated"
|
|
15
|
+
task :updated do
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
desc "Revert server(s) to previous release."
|
|
19
|
+
task :reverting do
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc "Reverted"
|
|
23
|
+
task :reverted do
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
desc "Publish the release."
|
|
27
|
+
task :publishing do
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
desc "Published"
|
|
31
|
+
task :published do
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
desc "Finish the deployment, clean up server(s)."
|
|
35
|
+
task :finishing do
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
desc "Finish the rollback, clean up server(s)."
|
|
39
|
+
task :finishing_rollback do
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
desc "Finished"
|
|
43
|
+
task :finished do
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc "Rollback to previous release."
|
|
47
|
+
task :rollback do
|
|
48
|
+
%w{ starting started
|
|
49
|
+
reverting reverted
|
|
50
|
+
publishing published
|
|
51
|
+
finishing_rollback finished }.each do |task|
|
|
52
|
+
invoke "deploy:#{task}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
desc "Deploy a new release."
|
|
58
|
+
task :deploy do
|
|
59
|
+
set(:deploying, true)
|
|
60
|
+
%w{ starting started
|
|
61
|
+
updating updated
|
|
62
|
+
publishing published
|
|
63
|
+
finishing finished }.each do |task|
|
|
64
|
+
invoke "deploy:#{task}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
task default: :deploy
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
require "pathname"
|
|
3
|
+
desc "Install Capistrano, cap install STAGES=staging,production"
|
|
4
|
+
task :install do
|
|
5
|
+
envs = ENV["STAGES"] || "staging,production"
|
|
6
|
+
|
|
7
|
+
tasks_dir = Pathname.new("lib/capistrano/tasks")
|
|
8
|
+
config_dir = Pathname.new("config")
|
|
9
|
+
deploy_dir = config_dir.join("deploy")
|
|
10
|
+
|
|
11
|
+
deploy_rb = File.expand_path("../../templates/deploy.rb.erb", __FILE__)
|
|
12
|
+
stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
|
|
13
|
+
capfile = File.expand_path("../../templates/Capfile", __FILE__)
|
|
14
|
+
|
|
15
|
+
mkdir_p deploy_dir
|
|
16
|
+
|
|
17
|
+
entries = [{ template: deploy_rb, file: config_dir.join("deploy.rb") }]
|
|
18
|
+
entries += envs.split(",").map { |stage| { template: stage_rb, file: deploy_dir.join("#{stage}.rb") } }
|
|
19
|
+
|
|
20
|
+
entries.each do |entry|
|
|
21
|
+
if File.exist?(entry[:file])
|
|
22
|
+
warn "[skip] #{entry[:file]} already exists"
|
|
23
|
+
else
|
|
24
|
+
File.open(entry[:file], "w+") do |f|
|
|
25
|
+
f.write(ERB.new(File.read(entry[:template])).result(binding))
|
|
26
|
+
puts I18n.t(:written_file, scope: :capistrano, file: entry[:file])
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
mkdir_p tasks_dir
|
|
32
|
+
|
|
33
|
+
if File.exist?("Capfile")
|
|
34
|
+
warn "[skip] Capfile already exists"
|
|
35
|
+
else
|
|
36
|
+
FileUtils.cp(capfile, "Capfile")
|
|
37
|
+
puts I18n.t(:written_file, scope: :capistrano, file: "Capfile")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
puts I18n.t :capified, scope: :capistrano
|
|
41
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Load DSL and set up stages
|
|
2
|
+
require "capistrano/setup"
|
|
3
|
+
|
|
4
|
+
# Include default deployment tasks
|
|
5
|
+
require "capistrano/deploy"
|
|
6
|
+
|
|
7
|
+
# Load the SCM plugin appropriate to your project:
|
|
8
|
+
#
|
|
9
|
+
# require "capistrano/scm/hg"
|
|
10
|
+
# install_plugin Capistrano::SCM::Hg
|
|
11
|
+
# or
|
|
12
|
+
# require "capistrano/scm/svn"
|
|
13
|
+
# install_plugin Capistrano::SCM::Svn
|
|
14
|
+
# or
|
|
15
|
+
require "capistrano/scm/git"
|
|
16
|
+
install_plugin Capistrano::SCM::Git
|
|
17
|
+
|
|
18
|
+
# Include tasks from other gems included in your Gemfile
|
|
19
|
+
#
|
|
20
|
+
# For documentation on these, see for example:
|
|
21
|
+
#
|
|
22
|
+
# https://github.com/capistrano/rvm
|
|
23
|
+
# https://github.com/capistrano/rbenv
|
|
24
|
+
# https://github.com/capistrano/chruby
|
|
25
|
+
# https://github.com/capistrano/bundler
|
|
26
|
+
# https://github.com/capistrano/rails
|
|
27
|
+
# https://github.com/capistrano/passenger
|
|
28
|
+
#
|
|
29
|
+
# require "capistrano/rvm"
|
|
30
|
+
# require "capistrano/rbenv"
|
|
31
|
+
# require "capistrano/chruby"
|
|
32
|
+
# require "capistrano/bundler"
|
|
33
|
+
# require "capistrano/rails/assets"
|
|
34
|
+
# require "capistrano/rails/migrations"
|
|
35
|
+
# require "capistrano/passenger"
|
|
36
|
+
|
|
37
|
+
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
|
38
|
+
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# config valid for current version and patch releases of Capistrano
|
|
2
|
+
lock "~> <%= Capistrano::VERSION %>"
|
|
3
|
+
|
|
4
|
+
set :application, "my_app_name"
|
|
5
|
+
set :repo_url, "git@example.com:me/my_repo.git"
|
|
6
|
+
|
|
7
|
+
# Default branch is :master
|
|
8
|
+
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
|
|
9
|
+
|
|
10
|
+
# Default deploy_to directory is /var/www/my_app_name
|
|
11
|
+
# set :deploy_to, "/var/www/my_app_name"
|
|
12
|
+
|
|
13
|
+
# Default value for :format is :airbrussh.
|
|
14
|
+
# set :format, :airbrussh
|
|
15
|
+
|
|
16
|
+
# You can configure the Airbrussh format using :format_options.
|
|
17
|
+
# These are the defaults.
|
|
18
|
+
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
|
|
19
|
+
|
|
20
|
+
# Default value for :pty is false
|
|
21
|
+
# set :pty, true
|
|
22
|
+
|
|
23
|
+
# Default value for :linked_files is []
|
|
24
|
+
# append :linked_files, "config/database.yml", 'config/master.key'
|
|
25
|
+
|
|
26
|
+
# Default value for linked_dirs is []
|
|
27
|
+
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system", "vendor", "storage"
|
|
28
|
+
|
|
29
|
+
# Default value for default_env is {}
|
|
30
|
+
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
|
|
31
|
+
|
|
32
|
+
# Default value for local_user is ENV['USER']
|
|
33
|
+
# set :local_user, -> { `git config user.name`.chomp }
|
|
34
|
+
|
|
35
|
+
# Default value for keep_releases is 5
|
|
36
|
+
# set :keep_releases, 5
|
|
37
|
+
|
|
38
|
+
# Uncomment the following to require manually verifying the host key before first deploy.
|
|
39
|
+
# set :ssh_options, verify_host_key: :secure
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# server-based syntax
|
|
2
|
+
# ======================
|
|
3
|
+
# Defines a single server with a list of roles and multiple properties.
|
|
4
|
+
# You can define all roles on a single server, or split them:
|
|
5
|
+
|
|
6
|
+
# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value
|
|
7
|
+
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
|
|
8
|
+
# server "db.example.com", user: "deploy", roles: %w{db}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# role-based syntax
|
|
13
|
+
# ==================
|
|
14
|
+
|
|
15
|
+
# Defines a role with one or multiple servers. The primary server in each
|
|
16
|
+
# group is considered to be the first unless any hosts have the primary
|
|
17
|
+
# property set. Specify the username and a domain or IP for the server.
|
|
18
|
+
# Don't use `:all`, it's a meta role.
|
|
19
|
+
|
|
20
|
+
# role :app, %w{deploy@example.com}, my_property: :my_value
|
|
21
|
+
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
|
|
22
|
+
# role :db, %w{deploy@example.com}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Configuration
|
|
27
|
+
# =============
|
|
28
|
+
# You can set any configuration variable like in config/deploy.rb
|
|
29
|
+
# These variables are then only loaded and set in this stage.
|
|
30
|
+
# For available Capistrano configuration variables see the documentation page.
|
|
31
|
+
# http://capistranorb.com/documentation/getting-started/configuration/
|
|
32
|
+
# Feel free to add new variables to customise your setup.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Custom SSH Options
|
|
37
|
+
# ==================
|
|
38
|
+
# You may pass any option but keep in mind that net/ssh understands a
|
|
39
|
+
# limited set of options, consult the Net::SSH documentation.
|
|
40
|
+
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
|
|
41
|
+
#
|
|
42
|
+
# Global options
|
|
43
|
+
# --------------
|
|
44
|
+
# set :ssh_options, {
|
|
45
|
+
# keys: %w(/home/user_name/.ssh/id_rsa),
|
|
46
|
+
# forward_agent: false,
|
|
47
|
+
# auth_methods: %w(password)
|
|
48
|
+
# }
|
|
49
|
+
#
|
|
50
|
+
# The server-based syntax can be used to override options:
|
|
51
|
+
# ------------------------------------
|
|
52
|
+
# server "example.com",
|
|
53
|
+
# user: "user_name",
|
|
54
|
+
# roles: %w{web app},
|
|
55
|
+
# ssh_options: {
|
|
56
|
+
# user: "user_name", # overrides user setting above
|
|
57
|
+
# keys: %w(/home/user_name/.ssh/id_rsa),
|
|
58
|
+
# forward_agent: false,
|
|
59
|
+
# auth_methods: %w(publickey password)
|
|
60
|
+
# # password: "please use keys"
|
|
61
|
+
# }
|
data/lib/capistrano/version.rb
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
class VersionValidator
|
|
3
|
+
def initialize(version)
|
|
4
|
+
@version = version
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def verify
|
|
8
|
+
return self if match?
|
|
9
|
+
raise "Capfile locked at #{version}, but #{current_version} is loaded"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
attr_reader :version
|
|
15
|
+
|
|
16
|
+
def match?
|
|
17
|
+
available =~ requested
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def current_version
|
|
21
|
+
VERSION
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def available
|
|
25
|
+
Gem::Dependency.new("cap", version)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def requested
|
|
29
|
+
Gem::Dependency.new("cap", current_version)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/capistrano.rb
CHANGED