Merge pull request #1480 from ojeytonwilliams/feat/cloudflare

feat: migrate to Cloudflare
This commit is contained in:
Oliver Eyton-Williams 2021-02-18 15:01:51 +01:00 committed by GitHub
commit 324ad131cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 42 deletions

View file

@ -12,7 +12,7 @@ app.config =
sentry_dsn: '<%= App.sentry_dsn %>'
version: <%= Time.now.to_i %>
release: <%= Time.now.utc.httpdate.to_json %>
mathml_stylesheet: '<%= App.cdn_origin %>/mathml.css'
mathml_stylesheet: '/mathml.css'
favicon_spritesheet: '<%= image_path('sprites/docs.png') %>'
service_worker_path: '/service-worker.js'
service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %>

View file

@ -20,8 +20,6 @@ class App < Sinatra::Application
set :root, Pathname.new(File.expand_path('../..', __FILE__))
set :sprockets, Sprockets::Environment.new(root)
set :cdn_origin, ''
set :assets_prefix, 'assets'
set :assets_path, File.join(public_folder, assets_prefix)
set :assets_manifest_path, File.join(assets_path, 'manifest.json')
@ -75,9 +73,8 @@ class App < Sinatra::Application
configure :production do
set :static, false
set :cdn_origin, 'https://cdn.devdocs.io'
set :docs_origin, '//docs.devdocs.io'
set :csp, "default-src 'self' *; script-src 'self' 'nonce-devdocs' https://cdn.devdocs.io https://www.google-analytics.com https://secure.gaug.es https://*.jquery.com; font-src 'none'; style-src 'self' 'unsafe-inline' *; img-src 'self' * data:;"
set :docs_origin, '//documents.devdocs.io'
set :csp, "default-src 'self' *; script-src 'self' 'nonce-devdocs' https://www.google-analytics.com https://secure.gaug.es https://*.jquery.com; font-src 'none'; style-src 'self' 'unsafe-inline' *; img-src 'self' * data:;"
use Rack::ConditionalGet
use Rack::ETag
@ -102,7 +99,6 @@ class App < Sinatra::Application
Sprockets::Helpers.configure do |config|
config.digest = true
config.asset_host = 'cdn.devdocs.io'
config.manifest = Sprockets::Manifest.new(sprockets, assets_manifest_path)
end
end
@ -202,7 +198,7 @@ class App < Sinatra::Application
def service_worker_asset_urls
@@service_worker_asset_urls ||= [
javascript_path('application', asset_host: false),
javascript_path('application'),
stylesheet_path('application'),
image_path('sprites/docs.png'),
image_path('sprites/docs@2x.png'),

View file

@ -191,27 +191,23 @@ class DocsCLI < Thor
puts '[S3] Begin syncing.'
docs.each do |doc|
puts "[S3] Syncing #{doc.path}..."
cmd = "aws s3 sync #{File.join(Docs.store_path, doc.path)} s3://devdocs-assets/#{doc.path} --delete --profile devdocs"
cmd = "aws s3 sync #{File.join(Docs.store_path, doc.path)} s3://devdocs-documents/#{doc.path} --delete --profile devdocs"
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|
# Upload packages to downloads.devdocs.io (used by the "thor docs:download" command)
puts '[S3 bundle] Begin uploading.'
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"
puts "[S3 bundle] Uploading #{filename}..."
cmd = "aws s3 cp #{File.join(Docs.store_path, filename)} s3://devdocs-downloads/#{filename} --profile devdocs"
cmd << ' --dryrun' if options[:dryrun]
system(cmd)
end
end
end
puts '[MaxCDN] Done uploading.'
puts '[S3 bundle] Done uploading.'
end
desc 'commit', '[private]'
@ -244,7 +240,7 @@ class DocsCLI < Thor
FileUtils.mkpath(dir)
['index.json', 'meta.json'].each do |filename|
json = "https://docs.devdocs.io/#{doc.path}/#{filename}?#{time}"
json = "https://documents.devdocs.io/#{doc.path}/#{filename}?#{time}"
begin
open(json) do |file|
mutex.synchronize do
@ -341,7 +337,7 @@ class DocsCLI < Thor
def download_doc(doc)
target_path = File.join(Docs.store_path, doc.path)
open "http://dl.devdocs.io/#{doc.path}.tar.gz" do |file|
open "https://downloads.devdocs.io/#{doc.path}.tar.gz" do |file|
FileUtils.mkpath(target_path)
file.close
tar = UnixUtils.gunzip(file.path)

View file

@ -4,8 +4,8 @@
<Description>Search API documentation</Description>
<Tags>devdocs</Tags>
<Url type="text/html" method="get" template="https://devdocs.io/#q={searchTerms}"/>
<Image height="16" width="16" type="image/vnd.microsoft.icon">https://cdn.devdocs.io/favicon.ico</Image>
<Image height="64" width="64" type="image/x-icon">https://cdn.devdocs.io/images/icon-64.png</Image>
<Image height="16" width="16" type="image/vnd.microsoft.icon">https://devdocs.io/favicon.ico</Image>
<Image height="64" width="64" type="image/x-icon">https://devdocs.io/images/icon-64.png</Image>
<InputEncoding>UTF-8</InputEncoding>
<moz:SearchForm>https://devdocs.io</moz:SearchForm>
<Url type="application/opensearchdescription+xml" rel="self" template="https://devdocs.io/opensearch.xml"/>

View file

@ -9,7 +9,7 @@
<meta property="og:description" content="Fast, offline, and free documentation browser for developers. Search 100+ docs in one web app including HTML, CSS, JavaScript, PHP, Ruby, Python, Go, C, C++, and many more.">
<meta property="og:type" content="website">
<meta property="og:url" content="<%= canonical_origin %>">
<meta property="og:image" content="<%= App.cdn_origin %>/images/icon-320.png">
<meta property="og:image" content="/images/icon-320.png">
<meta name="apple-mobile-web-app-title" content="DevDocs">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
@ -21,22 +21,22 @@
<link rel="manifest" href="/manifest.json">
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="DevDocs Search">
<link rel="alternate" href="<%= canonical_origin %>/feed" title="DevDocs" type="application/atom+xml">
<link rel="icon" type="image/x-icon" href="<%= App.cdn_origin %>/favicon.ico">
<link rel="fluid-icon" href="<%= App.cdn_origin %>/images/fluid-icon.png" title="DevDocs">
<link rel="apple-touch-icon" sizes="72x72" href="<%= App.cdn_origin %>/images/apple-icon-72.png">
<link rel="apple-touch-icon" sizes="76x76" href="<%= App.cdn_origin %>/images/apple-icon-76.png">
<link rel="apple-touch-icon" sizes="114x114" href="<%= App.cdn_origin %>/images/apple-icon-114.png">
<link rel="apple-touch-icon" sizes="120x120" href="<%= App.cdn_origin %>/images/apple-icon-120.png">
<link rel="apple-touch-icon" sizes="144x144" href="<%= App.cdn_origin %>/images/apple-icon-144.png">
<link rel="apple-touch-icon" sizes="152x152" href="<%= App.cdn_origin %>/images/apple-icon-152.png">
<link rel="apple-touch-icon" sizes="160x160" href="<%= App.cdn_origin %>/images/apple-icon-160.png">
<link rel="mask-icon" href="<%= App.cdn_origin %>/images/webkit-mask-icon.svg" color="#398df0">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<link rel="fluid-icon" href="/images/fluid-icon.png" title="DevDocs">
<link rel="apple-touch-icon" sizes="72x72" href="/images/apple-icon-72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/images/apple-icon-76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/images/apple-icon-114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/images/apple-icon-120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/images/apple-icon-144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/images/apple-icon-152.png">
<link rel="apple-touch-icon" sizes="160x160" href="/images/apple-icon-160.png">
<link rel="mask-icon" href="/images/webkit-mask-icon.svg" color="#398df0">
<%= stylesheet_tag 'application' %>
</head>
<body>
<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
<%= erb :app -%>
<%= javascript_tag 'application', asset_host: false %>
<%= javascript_tag 'application' %>
<%= javascript_tag 'docs' %><% unless App.production? %>
<%= javascript_tag 'debug' %><% end %>
</body>

View file

@ -6,18 +6,18 @@
<% if doc_index_page? %><meta name="description" content="<%= @doc['name'] %> <%= @doc['release'] %> API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more."><% else %><meta name="robots" content="noindex"><% end %>
<meta name="format-detection" content="telephone=no">
<meta name="theme-color" content="#eee">
<meta property="og:image" content="<%= App.cdn_origin %>/images/icon-320.png">
<meta property="og:image" content="/images/icon-320.png">
<title>DevDocs<%= " &mdash; #{@doc['full_name']} documentation" if doc_index_page? %></title>
<link rel="canonical" href="<%= canonical_origin %><%= request.path %>">
<link rel="manifest" href="/manifest.json">
<link rel="icon" type="image/x-icon" href="<%= App.cdn_origin %>/favicon.ico">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Search DevDocs">
<%= stylesheet_tag 'application' %>
</head>
<body data-doc="<%= CGI::escape_html @doc.to_json %>">
<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
<%= erb :app -%>
<%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
<%= javascript_tag 'application' %><% unless App.production? %>
<%= javascript_tag 'debug' %><% end %>
</body>
</html>