ferry 1.3.3 → 2.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.
@@ -0,0 +1,22 @@
1
+ include Ferry::DSL
2
+
3
+ namespace :load do
4
+ task :defaults do
5
+ load 'ferry/defaults.rb'
6
+ end
7
+ end
8
+
9
+ stages.each do |stage|
10
+ Rake::Task.define_task(stage) do
11
+ set(:stage, stage.to_sym)
12
+
13
+ invoke 'load:defaults'
14
+ load deploy_config_path
15
+ load stage_config_path.join("#{stage}.rb")
16
+ load "ferry/#{fetch(:scm)}.rb"
17
+ I18n.locale = fetch(:locale, :en)
18
+ configure_backend
19
+ end
20
+ end
21
+
22
+ require 'ferry/dotfile'
@@ -0,0 +1,226 @@
1
+ namespace :deploy do
2
+
3
+ task :starting do
4
+ invoke 'deploy:check'
5
+ invoke 'deploy:set_previous_revision'
6
+ end
7
+
8
+ task :updating => :new_release_path do
9
+ invoke "#{scm}:create_release"
10
+ invoke "deploy:set_current_revision"
11
+ invoke 'deploy:symlink:shared'
12
+ end
13
+
14
+ task :reverting do
15
+ invoke 'deploy:revert_release'
16
+ end
17
+
18
+ task :publishing do
19
+ invoke 'deploy:symlink:release'
20
+ end
21
+
22
+ task :finishing do
23
+ invoke 'deploy:cleanup'
24
+ end
25
+
26
+ task :finishing_rollback do
27
+ invoke 'deploy:cleanup_rollback'
28
+ end
29
+
30
+ task :finished do
31
+ invoke 'deploy:log_revision'
32
+ end
33
+
34
+ desc 'Check required files and directories exist'
35
+ task :check do
36
+ invoke "#{scm}:check"
37
+ invoke 'deploy:check:directories'
38
+ invoke 'deploy:check:linked_dirs'
39
+ invoke 'deploy:check:make_linked_dirs'
40
+ invoke 'deploy:check:linked_files'
41
+ end
42
+
43
+ namespace :check do
44
+ desc 'Check shared and release directories exist'
45
+ task :directories do
46
+ on release_roles :all do
47
+ execute :mkdir, '-p', shared_path, releases_path
48
+ end
49
+ end
50
+
51
+ desc 'Check directories to be linked exist in shared'
52
+ task :linked_dirs do
53
+ next unless any? :linked_dirs
54
+ on release_roles :all do
55
+ execute :mkdir, '-p', linked_dirs(shared_path)
56
+ end
57
+ end
58
+
59
+ desc 'Check directories of files to be linked exist in shared'
60
+ task :make_linked_dirs do
61
+ next unless any? :linked_files
62
+ on release_roles :all do |host|
63
+ execute :mkdir, '-p', linked_file_dirs(shared_path)
64
+ end
65
+ end
66
+
67
+ desc 'Check files to be linked exist in shared'
68
+ task :linked_files do
69
+ next unless any? :linked_files
70
+ on release_roles :all do |host|
71
+ linked_files(shared_path).each do |file|
72
+ unless test "[ -f #{file} ]"
73
+ error t(:linked_file_does_not_exist, file: file, host: host)
74
+ exit 1
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ namespace :symlink do
82
+ desc 'Symlink release to current'
83
+ task :release do
84
+ on release_roles :all do
85
+ tmp_current_path = release_path.parent.join(current_path.basename)
86
+ execute :ln, '-s', release_path, tmp_current_path
87
+ execute :mv, tmp_current_path, current_path.parent
88
+ end
89
+ end
90
+
91
+ desc 'Symlink files and directories from shared to release'
92
+ task :shared do
93
+ invoke 'deploy:symlink:linked_files'
94
+ invoke 'deploy:symlink:linked_dirs'
95
+ end
96
+
97
+ desc 'Symlink linked directories'
98
+ task :linked_dirs do
99
+ next unless any? :linked_dirs
100
+ on release_roles :all do
101
+ execute :mkdir, '-p', linked_dir_parents(release_path)
102
+
103
+ fetch(:linked_dirs).each do |dir|
104
+ target = release_path.join(dir)
105
+ source = shared_path.join(dir)
106
+ unless test "[ -L #{target} ]"
107
+ if test "[ -d #{target} ]"
108
+ execute :rm, '-rf', target
109
+ end
110
+ execute :ln, '-s', source, target
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ desc 'Symlink linked files'
117
+ task :linked_files do
118
+ next unless any? :linked_files
119
+ on release_roles :all do
120
+ execute :mkdir, '-p', linked_file_dirs(release_path)
121
+
122
+ fetch(:linked_files).each do |file|
123
+ target = release_path.join(file)
124
+ source = shared_path.join(file)
125
+ unless test "[ -L #{target} ]"
126
+ if test "[ -f #{target} ]"
127
+ execute :rm, target
128
+ end
129
+ execute :ln, '-s', source, target
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ desc 'Clean up old releases'
137
+ task :cleanup do
138
+ on release_roles :all do |host|
139
+ releases = capture(:ls, '-xtr', releases_path).split
140
+ if releases.count >= fetch(:keep_releases)
141
+ info t(:keeping_releases, host: host.to_s, keep_releases: fetch(:keep_releases), releases: releases.count)
142
+ directories = (releases - releases.last(fetch(:keep_releases)))
143
+ if directories.any?
144
+ directories_str = directories.map do |release|
145
+ releases_path.join(release)
146
+ end.join(" ")
147
+ execute :rm, '-rf', directories_str
148
+ else
149
+ info t(:no_old_releases, host: host.to_s, keep_releases: fetch(:keep_releases))
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ desc 'Remove and archive rolled-back release.'
156
+ task :cleanup_rollback do
157
+ on release_roles(:all) do
158
+ last_release = capture(:ls, '-xt', releases_path).split.first
159
+ last_release_path = releases_path.join(last_release)
160
+ if test "[ `readlink #{current_path}` != #{last_release_path} ]"
161
+ execute :tar, '-czf',
162
+ deploy_path.join("rolled-back-release-#{last_release}.tar.gz"),
163
+ last_release_path
164
+ execute :rm, '-rf', last_release_path
165
+ else
166
+ debug 'Last release is the current release, skip cleanup_rollback.'
167
+ end
168
+ end
169
+ end
170
+
171
+ desc 'Log details of the deploy'
172
+ task :log_revision do
173
+ on release_roles(:all) do
174
+ within releases_path do
175
+ execute %{echo "#{revision_log_message}" >> #{revision_log}}
176
+ end
177
+ end
178
+ end
179
+
180
+ desc 'Revert to previous release timestamp'
181
+ task :revert_release => :rollback_release_path do
182
+ on release_roles(:all) do
183
+ set(:revision_log_message, rollback_log_message)
184
+ end
185
+ end
186
+
187
+ task :new_release_path do
188
+ set_release_path
189
+ end
190
+
191
+ task :rollback_release_path do
192
+ on release_roles(:all) do
193
+ releases = capture(:ls, '-xt', releases_path).split
194
+ if releases.count < 2
195
+ error t(:cannot_rollback)
196
+ exit 1
197
+ end
198
+ last_release = releases[1]
199
+ set_release_path(last_release)
200
+ set(:rollback_timestamp, last_release)
201
+ end
202
+ end
203
+
204
+ desc "Place a REVISION file with the current revision SHA in the current release path"
205
+ task :set_current_revision do
206
+ invoke "#{scm}:set_current_revision"
207
+ on release_roles(:all) do
208
+ within release_path do
209
+ execute :echo, "\"#{fetch(:current_revision)}\" >> REVISION"
210
+ end
211
+ end
212
+ end
213
+
214
+ task :set_previous_revision do
215
+ on release_roles(:all) do
216
+ target = release_path.join('REVISION')
217
+ if test "[ -f #{target} ]"
218
+ set(:previous_revision, capture(:cat, target, '2>/dev/null'))
219
+ end
220
+ end
221
+ end
222
+
223
+ task :restart
224
+ task :failed
225
+
226
+ end
@@ -0,0 +1,52 @@
1
+ namespace :deploy do
2
+
3
+ desc "Preparing ferry for deployment."
4
+ task :starting do
5
+ end
6
+
7
+ desc 'Started'
8
+ task :started do
9
+ end
10
+
11
+ desc 'Revert database to previous release.'
12
+ task :reverting do
13
+ end
14
+
15
+ desc 'Reverted'
16
+ task :reverted do
17
+ end
18
+
19
+ desc 'Finish the deployment, cleaning up.'
20
+ task :finishing do
21
+ end
22
+
23
+ desc 'Finish the rollback, clean up.'
24
+ task :finishing_rollback do
25
+ end
26
+
27
+ desc 'Finished'
28
+ task :finished do
29
+ end
30
+
31
+ desc 'Rollback to previous release.'
32
+ task :rollback do
33
+ %w{ starting started
34
+ reverting reverted
35
+ publishing published
36
+ finishing_rollback finished }.each do |task|
37
+ invoke "deploy:#{task}"
38
+ end
39
+ end
40
+ end
41
+
42
+ desc 'Deploy a new release.'
43
+ task :deploy do
44
+ set(:deploying, true)
45
+ %w{ starting started
46
+ updating updated
47
+ publishing published
48
+ finishing finished }.each do |task|
49
+ invoke "deploy:#{task}"
50
+ end
51
+ end
52
+ task default: :deploy
@@ -0,0 +1,41 @@
1
+ require 'erb'
2
+ require 'pathname'
3
+ desc 'Install Ferry, ferry install STAGES=test,development,production'
4
+ task :install do
5
+ envs = ENV['STAGES'] || 'test,development,production'
6
+
7
+ tasks_dir = Pathname.new('lib/ferry/tasks')
8
+ config_dir = Pathname.new('config')
9
+ deploy_dir = config_dir.join('deploy_ferry')
10
+
11
+ deploy_rb = File.expand_path("../../templates/deploy_ferry.rb.erb", __FILE__)
12
+ stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
13
+ ferryfile = File.expand_path("../../templates/Ferryfile", __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.exists?(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: :ferry, file: entry[:file])
27
+ end
28
+ end
29
+ end
30
+
31
+ mkdir_p tasks_dir
32
+
33
+ if File.exists?('Ferryfile')
34
+ warn "[skip] Ferryfile already exists"
35
+ else
36
+ FileUtils.cp(ferryfile, 'Ferryfile')
37
+ puts I18n.t(:written_file, scope: :ferry, file: 'Ferryfile')
38
+ end
39
+
40
+ puts I18n.t :set_sail, scope: :deploy
41
+ end
@@ -0,0 +1,8 @@
1
+ # Load DSL and set up stages
2
+ require 'ferry/setup'
3
+
4
+ # Include default deployment tasks
5
+ require 'ferry/deploy'
6
+
7
+ # Load custom tasks from `lib/ferry/tasks` if you have any defined
8
+ Dir.glob('lib/ferry/tasks/*.rake').each { |r| import r }
@@ -0,0 +1,21 @@
1
+ # config valid only for current version of Ferry
2
+ lock '<%= Ferry::VERSION %>'
3
+
4
+ set :database, 'my_db_name'
5
+ set :db_role, 'my_db_role'
6
+ set :server, 'my_ip'
7
+ set :server_role, 'my_server_role'
8
+
9
+ namespace :deploy do
10
+
11
+ after :restart, :clear_cache do
12
+ on roles(:web), in: :groups, limit: 3, wait: 10 do
13
+ # Here we can do anything such as:
14
+ # within release_path do
15
+ # execute :rake, 'cache:clear'
16
+ # # or execute anything that we define in tasks
17
+ # end
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1 @@
1
+ # still deciding what we can use this for
@@ -0,0 +1,9 @@
1
+ require 'rake/file_creation_task'
2
+
3
+ module Ferry
4
+ class UploadTask < Rake::FileCreationTask
5
+ def needed?
6
+ true # always needed because we can't check remote hosts duhhhhhh
7
+ end
8
+ end
9
+ end
@@ -28,18 +28,6 @@ module Ferry
28
28
  `#{command}`
29
29
  end
30
30
 
31
- def make_starter_file
32
- if !File.exist?("lib/tasks/ferry.rake")
33
- install_dir = `bundle show ferry`.chomp
34
- starter_file_contents = File.open("#{install_dir}/doc/ferry_rake_contents.rb", "rb")
35
- contents = starter_file_contents.read
36
- File.open("lib/tasks/ferry.rake", 'w') {|f| f.write(contents)}
37
- puts "/lib/tasks/ferry.rake created!"
38
- else
39
- puts "/lib/tasks/ferry.rake already exists - but you knew that already ... didn't you?"
40
- end
41
- end
42
-
43
31
  def print_version
44
32
  puts "Ferry #{Ferry::VERSION}"
45
33
  end
@@ -1,3 +1,3 @@
1
1
  module Ferry
2
- VERSION = "1.3.3"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ferry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Corletti
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-04-23 00:00:00.000000000 Z
13
+ date: 2016-02-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -213,16 +213,40 @@ files:
213
213
  - README.md
214
214
  - Rakefile
215
215
  - bin/ferry
216
- - doc/ferry_rake_contents.rb
217
- - doc/ferry_readme_icon.png
218
- - doc/ferry_readme_icon_2.png
219
216
  - ferry.gemspec
217
+ - img/ferry_readme_icon.png
218
+ - img/ferry_readme_icon_2.png
219
+ - lib/Ferryfile
220
220
  - lib/ferry.rb
221
- - lib/ferry/dsl/captain.rb
221
+ - lib/ferry/all.rb
222
+ - lib/ferry/configuration.rb
223
+ - lib/ferry/configuration/filter.rb
224
+ - lib/ferry/configuration/question.rb
225
+ - lib/ferry/configuration/server.rb
226
+ - lib/ferry/configuration/servers.rb
227
+ - lib/ferry/defaults.rb
228
+ - lib/ferry/deploy.rb
229
+ - lib/ferry/dotfile.rb
230
+ - lib/ferry/dsl.rb
231
+ - lib/ferry/dsl/env.rb
232
+ - lib/ferry/dsl/paths.rb
233
+ - lib/ferry/dsl/stages.rb
234
+ - lib/ferry/dsl/task_enhancements.rb
222
235
  - lib/ferry/dumper.rb
223
236
  - lib/ferry/exporter.rb
224
237
  - lib/ferry/filler.rb
238
+ - lib/ferry/framework.rb
239
+ - lib/ferry/i18n.rb
225
240
  - lib/ferry/importer.rb
241
+ - lib/ferry/install.rb
242
+ - lib/ferry/setup.rb
243
+ - lib/ferry/tasks/deploy.rake
244
+ - lib/ferry/tasks/framework.rake
245
+ - lib/ferry/tasks/install.rake
246
+ - lib/ferry/templates/Ferryfile
247
+ - lib/ferry/templates/deploy_ferry.rb.erb
248
+ - lib/ferry/templates/stage.rb.erb
249
+ - lib/ferry/upload_task.rb
226
250
  - lib/ferry/utilities.rb
227
251
  - lib/ferry/version.rb
228
252
  - spec/config/database.yml
@@ -273,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
297
  version: '0'
274
298
  requirements: []
275
299
  rubyforge_project:
276
- rubygems_version: 2.4.5
300
+ rubygems_version: 2.4.8
277
301
  signing_key:
278
302
  specification_version: 4
279
303
  summary: Ferry is a data migration and visualization command line tool rubygem