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
3939 gem 'progress_bar', require: false
4040 gem 'unix_utils', require: false
4141 gem 'tty-pager', require: false
42+ gem 'net-sftp', '>= 2.1.3.rc2', require: false
4243 end
4344
4445 group :test do
Gemfile.lock+4−0
@@ -49,6 +49,9 @@ GEM · 48 unmodified lines
4949 minitest (5.11.3)
5050 multi_json (1.13.1)
5151 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)
5255 newrelic_rpm (5.5.0.348)
5356 nokogiri (1.8.5)
5457 mini_portile2 (~> 2.3.0)
@@ -136,6 +139,7 @@ DEPENDENCIES · 81 unmodified lines
136139 image_optim
137140 image_optim_pack
138141 minitest
142+ net-sftp (>= 2.1.3.rc2)
139143 newrelic_rpm
140144 nokogiri
141145 progress_bar
lib/tasks/docs.thor+22−1
@@ -157,15 +157,36 @@ class DocsCLI < Thor · 156 unmodified lines
157157 option :dryrun, type: :boolean
158158 option :packaged, type: :boolean
159159 def upload(*names)
160+ require 'net/sftp'
160161 names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged]
161162 docs = find_docs(names)
162163 assert_docs(docs)
164+
165+ # Sync files with S3 (used by the web app)
166+ puts '[S3] Begin syncing.'
163167 docs.each do |doc|
164− puts "Syncing #{doc.path}..."
168+ puts "[S3] Syncing #{doc.path}..."
165169 cmd = "aws s3 sync #{File.join(Docs.store_path, doc.path)} s3://docs.devdocs.io/#{doc.path} --delete"
166170 cmd << ' --dryrun' if options[:dryrun]
167171 system(cmd)
168172 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.'
169190 end
170191
171192 desc 'commit', '[private]'