History

Make "thor docs:upload" upload packages to MaxCDN (dl.devdocs.io)

Thibaut Courouble committed 7 years ago

Commit 17cddbc1 parent a8a10203 files · +27 −1Browse files

Unified · Split

3 files
  1. Gemfile +1 −0
  2. Gemfile.lock +4 −0
  3. lib/tasks/docs.thor +22 −1
Gemfile+1−0
@@ -39,6 +39,7 @@ group :docs do · 38 unmodified lines
39 gem 'progress_bar', require: false39 gem 'progress_bar', require: false
40 gem 'unix_utils', require: false40 gem 'unix_utils', require: false
41 gem 'tty-pager', require: false41 gem 'tty-pager', require: false
42 gem 'net-sftp', '>= 2.1.3.rc2', require: false
42end43end
43 44
44group :test do45group :test do
Gemfile.lock+4−0
@@ -49,6 +49,9 @@ GEM · 48 unmodified lines
49 minitest (5.11.3)49 minitest (5.11.3)
50 multi_json (1.13.1)50 multi_json (1.13.1)
51 mustermann (1.0.3)51 mustermann (1.0.3)
52 net-sftp (2.1.3.rc2)
53 net-ssh (>= 2.6.5, < 5.0.0)
54 net-ssh (4.2.0)
52 newrelic_rpm (5.5.0.348)55 newrelic_rpm (5.5.0.348)
53 nokogiri (1.8.5)56 nokogiri (1.8.5)
54 mini_portile2 (~> 2.3.0)57 mini_portile2 (~> 2.3.0)
@@ -136,6 +139,7 @@ DEPENDENCIES · 81 unmodified lines
136 image_optim139 image_optim
137 image_optim_pack140 image_optim_pack
138 minitest141 minitest
142 net-sftp (>= 2.1.3.rc2)
139 newrelic_rpm143 newrelic_rpm
140 nokogiri144 nokogiri
141 progress_bar145 progress_bar
lib/tasks/docs.thor+22−1
@@ -157,15 +157,36 @@ class DocsCLI < Thor · 156 unmodified lines
157 option :dryrun, type: :boolean157 option :dryrun, type: :boolean
158 option :packaged, type: :boolean158 option :packaged, type: :boolean
159 def upload(*names)159 def upload(*names)
160 require 'net/sftp'
160 names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged]161 names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged]
161 docs = find_docs(names)162 docs = find_docs(names)
162 assert_docs(docs)163 assert_docs(docs)
164
165 # Sync files with S3 (used by the web app)
166 puts '[S3] Begin syncing.'
163 docs.each do |doc|167 docs.each do |doc|
164 puts "Syncing #{doc.path}..."168 puts "[S3] Syncing #{doc.path}..."
165 cmd = "aws s3 sync #{File.join(Docs.store_path, doc.path)} s3://docs.devdocs.io/#{doc.path} --delete"169 cmd = "aws s3 sync #{File.join(Docs.store_path, doc.path)} s3://docs.devdocs.io/#{doc.path} --delete"
166 cmd << ' --dryrun' if options[:dryrun]170 cmd << ' --dryrun' if options[:dryrun]
167 system(cmd)171 system(cmd)
168 end172 end
173 puts '[S3] Done syncing.'
174
175 # Upload packages to dl.devdocs.io (used by the "thor docs:download" command)
176 puts '[MaxCDN] Begin uploading.'
177 Net::SFTP.start('ftp.devdocs-dl.devdocs.netdna-cdn.com', ENV['DEVDOCS_DL_USERNAME'], password: ENV['DEVDOCS_DL_PASSWORD']) do |sftp|
178 docs.each do |doc|
179 filename = "#{doc.path}.tar.gz"
180 print "[MaxCDN] Uploading #{filename}..."
181 if options[:dryrun]
182 print "\n"
183 else
184 sftp.upload! File.join(Docs.store_path, filename), File.join('', 'public_html', filename)
185 print " OK\n"
186 end
187 end
188 end
189 puts '[MaxCDN] Done uploading.'
169 end190 end
170 191
171 desc 'commit', '[private]'192 desc 'commit', '[private]'