Skip to content

Commit 17cddbc

Browse files
committed
Make "thor docs:upload" upload packages to MaxCDN (dl.devdocs.io)
1 parent a8a1020 commit 17cddbc

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ group :docs do
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ GEM
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
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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,36 @@ class DocsCLI < Thor
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]'

0 commit comments

Comments
 (0)