Browse Source

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

Thibaut Courouble 7 years ago
parent
commit
17cddbccaf
3 changed files with 27 additions and 1 deletions
  1. 1 0
      Gemfile
  2. 4 0
      Gemfile.lock
  3. 22 1
      lib/tasks/docs.thor

+ 1 - 0
Gemfile

@@ -39,6 +39,7 @@ group :docs do
   gem 'progress_bar', require: false
   gem 'unix_utils', require: false
   gem 'tty-pager', require: false
+  gem 'net-sftp', '>= 2.1.3.rc2', require: false
 end
 
 group :test do

+ 4 - 0
Gemfile.lock

@@ -49,6 +49,9 @@ GEM
     minitest (5.11.3)
     multi_json (1.13.1)
     mustermann (1.0.3)
+    net-sftp (2.1.3.rc2)
+      net-ssh (>= 2.6.5, < 5.0.0)
+    net-ssh (4.2.0)
     newrelic_rpm (5.5.0.348)
     nokogiri (1.8.5)
       mini_portile2 (~> 2.3.0)
@@ -136,6 +139,7 @@ DEPENDENCIES
   image_optim
   image_optim_pack
   minitest
+  net-sftp (>= 2.1.3.rc2)
   newrelic_rpm
   nokogiri
   progress_bar

+ 22 - 1
lib/tasks/docs.thor

@@ -157,15 +157,36 @@ class DocsCLI < Thor
   option :dryrun, type: :boolean
   option :packaged, type: :boolean
   def upload(*names)
+    require 'net/sftp'
     names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged]
     docs = find_docs(names)
     assert_docs(docs)
+
+    # Sync files with S3 (used by the web app)
+    puts '[S3] Begin syncing.'
     docs.each do |doc|
-      puts "Syncing #{doc.path}..."
+      puts "[S3] Syncing #{doc.path}..."
       cmd = "aws s3 sync #{File.join(Docs.store_path, doc.path)} s3://docs.devdocs.io/#{doc.path} --delete"
       cmd << ' --dryrun' if options[:dryrun]
       system(cmd)
     end
+    puts '[S3] Done syncing.'
+
+    # Upload packages to dl.devdocs.io (used by the "thor docs:download" command)
+    puts '[MaxCDN] Begin uploading.'
+    Net::SFTP.start('ftp.devdocs-dl.devdocs.netdna-cdn.com', ENV['DEVDOCS_DL_USERNAME'], password: ENV['DEVDOCS_DL_PASSWORD']) do |sftp|
+      docs.each do |doc|
+        filename = "#{doc.path}.tar.gz"
+        print "[MaxCDN] Uploading #{filename}..."
+        if options[:dryrun]
+          print "\n"
+        else
+          sftp.upload! File.join(Docs.store_path, filename), File.join('', 'public_html', filename)
+          print " OK\n"
+        end
+      end
+    end
+    puts '[MaxCDN] Done uploading.'
   end
 
   desc 'commit', '[private]'