Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: dynamic aspects preparation #59

Merged
merged 79 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
2d18fd4
Initial commit
cdchapman Oct 25, 2012
0938b91
Aligned things
cdchapman Oct 25, 2012
2b7ca7e
Update a few things
cdchapman Oct 26, 2012
a23165e
Add redirection to non-www and 403 stuff
cdchapman Oct 26, 2012
e7dfc8a
Use a 307 response instead of a 301
cdchapman Oct 26, 2012
73ad779
Removed extra semicolon
cdchapman Oct 26, 2012
11fa962
Replace redirect with the right location
cdchapman Oct 26, 2012
dd192c6
Added script to update server configs automatically
cdchapman Oct 26, 2012
d963e2b
Add endpoint for status monitoring
cdchapman Dec 15, 2012
c81b469
Redirect people URIs to descriptions about people
cdchapman Oct 27, 2014
8cc4cfc
Reload the server after uploading new config files
cdchapman Oct 27, 2014
7c5ead7
Use specific people; don't just pass through anything
cdchapman Oct 27, 2014
927ac24
Combine vars
cdchapman Oct 27, 2014
50e4d7a
I think I need to use hash URIs
cdchapman Oct 27, 2014
2f446ec
Updated mime types
cdchapman Dec 11, 2014
94651c3
Working on charsets
cdchapman Dec 11, 2014
97ddd4d
Fix duplicate warning
cdchapman Dec 11, 2014
459a7e5
Encode css as utf-8
cdchapman Dec 11, 2014
321393c
Redirect /products → /solutions/
cdchapman Oct 2, 2015
08fd408
Split into conf.d
cdchapman Dec 11, 2015
e23e26b
Protect against logjam
cdchapman Dec 11, 2015
ffe7f0e
Fixed spelling
cdchapman Dec 11, 2015
4af31b7
Add redirect for page that changed names
cdchapman Dec 12, 2015
f5d59cb
Add hints for vim
cdchapman Jun 1, 2016
f5a3f21
Updating h5bp configuration
cdchapman Jun 2, 2016
963970e
Synthesizing pentandra.com
cdchapman Jun 2, 2016
24e19fc
Include HSTS header in the include file
cdchapman Jun 2, 2016
c421bef
Use ssl cert directives in the redirecting server as well
cdchapman Jun 2, 2016
8d0fbe3
Move pentandra to the appropriate filename
cdchapman Jun 2, 2016
38af2a5
Duplicate type removed
cdchapman Jun 2, 2016
2b0554c
Fix capitalization of includeSubDomains
cdchapman Jun 2, 2016
9b78a23
Upgrade spdy to http2
cdchapman Jun 2, 2016
c3f8566
Making this more generic, and less specific to h5bp
cdchapman Jun 3, 2016
5910d6e
Don't use spdy, since it's deprecated. Use http/2
cdchapman Jun 3, 2016
00401fe
Move to etc/nginx to prepare for merge into main lifepreserver repo
cdchapman Jun 6, 2016
efeb737
Come up with better mechanism for deployment
cdchapman Jun 6, 2016
050b3f6
Moved `items` to `content` as part of issue #50
cdchapman Nov 3, 2016
844a878
Simplify robots and humans compile
cdchapman Nov 4, 2016
18c7e94
Use item path to get path for search page, not site config
cdchapman Nov 4, 2016
8164102
Fix the shortener code
cdchapman Nov 4, 2016
1bb02d9
Setup a staging environment that inherits from production but doesn't…
cdchapman Nov 4, 2016
379d875
Fork Nanoc's view command to concatenate the static_root to the websi…
cdchapman Nov 4, 2016
c63d53e
Hardcoded the static directory into all the places
cdchapman Nov 5, 2016
e0e141d
Updating some forgotten configuration for the folder move
cdchapman Nov 5, 2016
01a6494
Added new path API to separate the notion of a Nanoc build path & a p…
cdchapman Nov 5, 2016
8ef502b
Move short_url_for to the LinkTo helper module
cdchapman Nov 5, 2016
e269d31
Remove the absolutify_links filter, as I think it is a code smell
cdchapman Nov 5, 2016
fd42d36
Simplify and remove some redundancies
cdchapman Nov 7, 2016
96c7768
Use specific config for the view command. Fixes #57
cdchapman Nov 7, 2016
d88d833
Introduce the (albeit hackish) ability to use a global flag in the li…
cdchapman Nov 7, 2016
f273ad1
Also check to see whether the rep has a path
cdchapman Nov 7, 2016
e250474
Accidentally committed this during experimentation. Removing.
cdchapman Nov 7, 2016
572c69e
Add item rep for the blog feed. Fixes #56
cdchapman Nov 7, 2016
9902ad5
Removing filter helpers. Related to #56
cdchapman Nov 7, 2016
122e7a1
Forgot to remove this with the previous commit
cdchapman Nov 7, 2016
bd49e19
Move 'content' back to 'items'
cdchapman Nov 7, 2016
5de42f0
Moved static items into an explicit static subfolder
cdchapman Nov 7, 2016
282d5dd
Use the build path for version history
cdchapman Nov 7, 2016
913cb2e
Redesign static_root configuration, as it won't be as important now
cdchapman Nov 7, 2016
505b0a1
Use the longer, more explicit method name
cdchapman Nov 7, 2016
360b98a
Try to be a little smarter about grabbing the current item's path
cdchapman Nov 7, 2016
3d04d34
Trying to show the motivation better here
cdchapman Nov 8, 2016
8b1bf4b
A fix for a nil result
cdchapman Nov 8, 2016
95e4ea3
Reorganizing site configuration
cdchapman Nov 8, 2016
a566028
Forked Nanoc::Helpers::XMLSitemap to fix the public paths for static …
cdchapman Nov 8, 2016
ffb39b5
Convert to UTC time
cdchapman Nov 8, 2016
f853266
Fork Nanoc atom feed builder and fix public paths. Closes #21 for now.
cdchapman Nov 8, 2016
e988b39
Redirect to new feed name
cdchapman Nov 8, 2016
fd27d01
Preparing for merge to main project
cdchapman Nov 8, 2016
b6097ae
Add static_only environment. Resolves #50.
cdchapman Nov 8, 2016
bb8e315
Merge remote-tracking branch 'server-configs/master' into feature/dyn…
cdchapman Nov 8, 2016
b1d9e7b
Moving configuration to a project-specific file
cdchapman Nov 8, 2016
57c35e1
Simplify unneeded stuff. Removed url_for
cdchapman Nov 8, 2016
ac6b793
Broaden reasons to include builder
cdchapman Nov 8, 2016
bde1edc
Initial dynamic setup with nginx. Resolves #14.
cdchapman Nov 8, 2016
92138d0
Remove extra lines
cdchapman Nov 8, 2016
2cce6b6
Patch internal links check to prepend static_root. Fixes #58
cdchapman Nov 9, 2016
1b5e4ed
Add check for private build paths. Fixes #55
cdchapman Nov 9, 2016
6a201d6
Implemented a nanoc server command. Fixes #33
cdchapman Nov 9, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ output.diff
crash.log
*.autosave
*.bak
items/assets/components/
items/static/assets/components/
tmp/
.bundle
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "specifications"]
path = specifications
url = [email protected]:pentandra/specifications.git
[submodule "items/company/benefit-reports"]
path = items/company/benefit-reports
[submodule "benefit-reports"]
path = items/static/company/benefit-reports
url = [email protected]:pentandra/benefit-reports.git
16 changes: 16 additions & 0 deletions Checks
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,26 @@ check :no_unprocessed_markdown do
end
end

check :no_static_build_paths do
filenames = @output_filenames.select { |f| File.extname(f) == '.html' }
hrefs_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :internal).filenames_per_href
resource_uris_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :internal).filenames_per_resource_uri

uris = hrefs_with_filenames.merge(resource_uris_with_filenames)
uris.each_pair do |href, fns|
fns.each do |filename|
if href.start_with?(@config[:static_root])
add_issue("private build path present in #{href}", subject: filename)
end
end
end
end

deploy_check :internal_links
deploy_check :mixed_content
deploy_check :stale
deploy_check :no_unprocessed_erb
deploy_check :no_unprocessed_markdown
deploy_check :no_static_build_paths

# vi: ft=ruby
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gem 'rouge'
gem 'haml'
gem 'pandoc-ruby' # for benefit reports in ConTeXt
gem 'git' # for version history and tagging info
gem 'builder' # for XML stuff, such as sitemap and atom feeds

group :development, optional: true do
gem 'guard'
Expand Down
9 changes: 6 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GIT

GIT
remote: https://github.com/ruby-rdf/rdf.git
revision: e1ff91841066369b8917dd21be9564452a6ea18a
revision: 4740b4a52bf358656d01d93adc5174d5fe07aec8
branch: develop
specs:
rdf (2.1.0)
Expand All @@ -40,7 +40,8 @@ GEM
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.4.0)
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
adsf (1.2.1)
rack (>= 1.0.0)
bcp47 (0.3.3)
Expand Down Expand Up @@ -191,11 +192,12 @@ GEM
pandoc-ruby (2.0.1)
parallel (1.9.0)
pipe-run (0.3.0)
posix-spawn (0.3.11)
posix-spawn (0.3.12)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
public_suffix (2.0.4)
pygments.rb (0.6.3)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.2.0)
Expand Down Expand Up @@ -330,6 +332,7 @@ PLATFORMS
DEPENDENCIES
activesupport
adsf
builder
chunky_png
compass
ghi
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ in scope before compiling:
#### Optional dependencies
* [optipng] for optimizing PNG images
* A Java 8 runtime for running the [Nu HTML] checker.
* [OpenResty] for running the dynamic parts of the site via `nanoc server`.

### Then clone this repo (including submodules), install bower components and Ruby gems…

Expand Down Expand Up @@ -58,7 +59,8 @@ $ nanoc view # if you are only dealing with statically generated pages
$ nanoc server # if you are dealing with both the static and dynamic aspects of the site
```

And view the page in your browser.
And view the page in your browser at [port 3000](http://localhost:3000/) for
`nanoc view` or [port 4125](https://localhost:4125/) for `nanoc server`.

## Contributing

Expand Down Expand Up @@ -95,3 +97,4 @@ Also, please see [the colophon][colophon] for more raving attributions!
[pygments]: <http://pygments.org/>
[bundler]: <http://bundler.io/>
[colophon]: <https://pentandra.com/colophon/>
[OpenResty]: <http://openresty.org/>
2 changes: 2 additions & 0 deletions Rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
include_rules 'rules/company'
include_rules 'rules/blog'

include_rules 'rules/dynamic'

# This should always be last
include_rules 'rules/catch_all'
98 changes: 98 additions & 0 deletions commands/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
usage 'server [options]'
summary 'start the dynamic web server (nginx/OpenResty)'
description <<-EOS
Start the dynamic web server. Running this web server requires OpenResty
to be installed and in scope.
EOS

required :c, :conf, 'specify the configuration file to use (default: nginx.conf)'
required :g, :global, 'specify any global directives (default: daemon off;)'

module LifePreserver
class Server < ::Nanoc::CLI::CommandRunner
NGINX_BIN = 'nginx'
NGINX_SEARCH_PATHS = [
'/usr/local/openresty/nginx/sbin/',
'/usr/local/opt/openresty/bin/',
'/usr/local/bin/',
'/usr/sbin/',
'/opt/openresty/nginx/sbin/'
]

class Error < ::Nanoc::Int::Errors::Generic
def initialize(command, exit_code)
@command = command
@exit_code = exit_code
end

def message
"command exited with a nonzero status code #{@exit_code} (command: #{@command.join(' ')})"
end
end

def run
require 'open3'

load_site

conf = options[:conf] || 'nginx.conf'
directives = options[:global] || 'daemon off;'


nginx = find_nginx
output_dir = site.config[:output_dir]
cmd = [ nginx, '-p', output_dir, '-c', conf, '-g', directives ]

Open3.popen3(*cmd) do |_stdin, stdout, stderr, wait_thr|
puts "Starting OpenResty (#{nginx}) in path (#{output_dir}) with config (#{conf}) and global directives (#{directives})"

stdout_thread = Thread.new do
while (line = stdout.gets)
puts line
end
end

stderr_thread = Thread.new do
while (line = stderr.gets)
puts line
end
end

stdout_thread.join
stderr_thread.join

exit_status = wait_thr.value
unless exit_status.success?
raise Error.new(cmd, exit_status.to_i)
end
end
end

protected

def find_nginx
NGINX_SEARCH_PATHS.each do |path|
to_check = path + NGINX_BIN
if File.file?(to_check) && openresty?(to_check)
return to_check
end
end

# As a last resort, check the PATH
require 'mkmf'
to_check = find_executable0(NGINX_BIN)
if to_check && openresty?(to_check)
return to_check
end

raise "Cannot find the OpenResty executable in any of the following places: #{NGINX_SEARCH_PATHS.join(':')} or in the current path: #{ENV['PATH']}"
end

def openresty?(path_to_check)
output, _status = Open3.capture2e(path_to_check, '-v')
output && output['openresty']
end
end
end

runner LifePreserver::Server
91 changes: 91 additions & 0 deletions commands/view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
usage 'view [options]'
summary 'start the web server that serves static files'
description <<-EOS
Start the static web server. Unless specified, the web server will run on port
3000 and listen on all IP addresses. Running this static web server requires
`adsf` (not `asdf`!).
EOS

required :H, :handler, 'specify the handler to use (webrick/mongrel/...)'
required :o, :host, 'specify the host to listen on (default: 0.0.0.0)'
required :p, :port, 'specify the port to listen on (default: 3000)'

module Nanoc::CLI::Commands
class View < ::Nanoc::CLI::CommandRunner
DEFAULT_HANDLER_NAME ||= :thin

def run
load_adsf
require 'rack'

load_site

# Set options
options_for_rack = {
Port: (options[:port] || 3000).to_i,
Host: (options[:host] || '0.0.0.0'),
}

# Get handler
if options.key?(:handler)
handler = Rack::Handler.get(options[:handler])
else
begin
handler = Rack::Handler.get(DEFAULT_HANDLER_NAME)
rescue LoadError
handler = Rack::Handler::WEBrick
end
end

# Build app
site = self.site
site_root = site.config[:output_dir] + view_config_root

app = Rack::Builder.new do
use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::Lint
use Rack::Head
use Adsf::Rack::IndexFileFinder, root: site_root
run Rack::File.new(site_root)
end.to_app

# Run autocompiler
handler.run(app, options_for_rack)
end

protected

def view_config
site.config[:view] || {}
end

def view_config_root
view_config[:static_root]
end

def load_adsf
# Load adsf
begin
require 'adsf'
return
rescue LoadError
$stderr.puts "Could not find the required 'adsf' gem, " \
'which is necessary for the view command.'
end

# Check asdf
begin
require 'asdf'
$stderr.puts "You appear to have 'asdf' installed, " \
"but not 'adsf'. Please install 'adsf' (check the spelling)!"
rescue LoadError
end

# Done
exit 1
end
end
end

runner Nanoc::CLI::Commands::View
12 changes: 6 additions & 6 deletions etc/compass/config.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'compass/import-once/activate'
# Require any additional compass plugins here.

add_import_path "items/assets/components/retina.js/src"
add_import_path "items/static/assets/components/retina.js/src"

http_path = "/"
project_path = File.expand_path(File.join(File.dirname(__FILE__), '../../'))
css_dir = "items/assets/stylesheets"
sass_dir = "items/assets/stylesheets"
images_dir = "items/assets/images"
javascripts_dir = "items/assets/scripts"
fonts_dir = "items/assets/fonts"
css_dir = "items/static/assets/stylesheets"
sass_dir = "items/static/assets/stylesheets"
images_dir = "items/static/assets/images"
javascripts_dir = "items/static/assets/scripts"
fonts_dir = "items/static/assets/fonts"
http_javascripts_path = "js"
http_stylesheets_path = "css"
http_images_path = "images"
Expand Down
1 change: 0 additions & 1 deletion items/assets/scripts/jsonld.js.erb

This file was deleted.

21 changes: 21 additions & 0 deletions items/directives/cache-file-descriptors.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This tells Nginx to cache open file handles, "not found" errors, metadata about files and their permissions, etc.
#
# The upside of this is that Nginx can immediately begin sending data when a popular file is requested,
# and will also know to immediately send a 404 if a file is missing on disk, and so on.
#
# However, it also means that the server won't react immediately to changes on disk, which may be undesirable.
#
# In the below configuration, inactive files are released from the cache after 20 seconds, whereas
# active (recently requested) files are re-validated every 30 seconds.
#
# Descriptors will not be cached unless they are used at least 2 times within 20 seconds (the inactive time).
#
# A maximum of the 1000 most recently used file descriptors can be cached at any time.
#
# Production servers with stable file collections will definitely want to enable the cache.
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;

# vi: ft=nginx
16 changes: 16 additions & 0 deletions items/directives/cross-domain-insecure.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Cross domain AJAX requests

# http://www.w3.org/TR/cors/#access-control-allow-origin-response-header

# **Security Warning**
# Do not use this without understanding the consequences.
# This will permit access from any other website.
#
add_header "Access-Control-Allow-Origin" "*";

# Instead of using this file, consider using a specific rule such as:
#
# Allow access based on [sub]domain:
# add_header "Access-Control-Allow-Origin" "subdomain.example.com";

# vi: ft=nginx
19 changes: 19 additions & 0 deletions items/directives/extra-security.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# The X-Frame-Options header indicates whether a browser should be allowed
# to render a page within a frame or iframe.
add_header X-Frame-Options SAMEORIGIN;

# MIME type sniffing security protection
# There are very few edge cases where you wouldn't want this enabled.
add_header X-Content-Type-Options nosniff;

# The X-XSS-Protection header is used by Internet Explorer version 8+
# The header instructs IE to enable its inbuilt anti-cross-site scripting filter.
add_header X-XSS-Protection "1; mode=block";

# with Content Security Policy (CSP) enabled (and a browser that supports it (http://caniuse.com/#feat=contentsecuritypolicy),
# you can tell the browser that it can only download content from the domains you explicitly allow
# CSP can be quite difficult to configure, and cause real issues if you get it wrong
# There is website that helps you generate a policy here http://cspisawesome.com/
# add_header Content-Security-Policy "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' https://www.google-analytics.com;";

# vi: ft=nginx
Loading