Last active
April 26, 2017 22:38
-
-
Save anthonymoralez/6f8621ab14061dc9487016939bdcfe99 to your computer and use it in GitHub Desktop.
Heroku Nanoc Buildpack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# bin/compile <build-dir> <cache-dir> | |
# parse and derive params | |
BUILD_DIR=$1 | |
CACHE_DIR=$2 | |
BUILDPACK_DIR=`cd $(dirname $0); cd ..; pwd` | |
# =========> Nanoc | |
echo "-----> Compiling Nanoc Site" | |
export LANG=en_US.UTF-8 | |
cd $BUILD_DIR | |
bundle exec nanoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'bundler' | |
Bundler.require | |
use Rack::ETag | |
module ::Rack | |
class TryStatic < Static | |
def initialize(app, options) | |
super | |
@try = ([''] + Array(options.delete(:try)) + ['']) | |
end | |
def call(env) | |
@next = 0 | |
while @next < @try.size && 404 == (resp = super(try_next(env)))[0] | |
@next += 1 | |
end | |
404 == resp[0] ? @app.call : resp | |
end | |
private | |
def try_next(env) | |
env.merge('PATH_INFO' => env['PATH_INFO'] + @try[@next]) | |
end | |
end | |
end | |
use Rack::TryStatic, | |
:root => "output", | |
:urls => %w[/], | |
:try => ['.html', 'index.html', '/index.html'] | |
errorFile = 'output/error/404-not_found/index.html' | |
run lambda { | |
[404, { | |
"Last-Modified" => File.mtime(errorFile).httpdate, | |
"Content-Type" => "text/html", | |
"Content-Length" => File.size(errorFile).to_s | |
}, File.read(errorFile) | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# bin/detect <build-dir> | |
# this pack is valid for apps with config.yml and Rules in the root | |
if [ -f $1/config.yaml -o -f $1/nanoc.yaml ] && [ -f $1/Rules ]; then | |
echo "Nanoc" | |
exit 0 | |
else | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
source "https://rubygems.org" | |
ruby "2.3.1" | |
gem "thin" | |
gem "nanoc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heroku buildpacks:clear | |
heroku buildpacks:add heroku/ruby | |
heroku buildpacks:add https://github.com/anthonymoralez/heroku-buildpack-nanoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ nanoc | |
Loading site… done | |
Compiling site… | |
create [0.00s] output/index.html | |
create [0.00s] output/stylesheet.css | |
Site compiled in 0.02s. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: bundle exec thin start -p $PORT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git push -u heroku master | |
Counting objects: 14, done. | |
Delta compression using up to 8 threads. | |
Compressing objects: 100% (12/12), done. | |
Writing objects: 100% (14/14), 4.34 KiB | 0 bytes/s, done. | |
Total 14 (delta 2), reused 0 (delta 0) | |
remote: Compressing source files... done. | |
remote: Building source: | |
remote: | |
remote: -----> Ruby app detected | |
remote: -----> Compiling Ruby/Rack | |
remote: -----> Using Ruby version: ruby-2.3.1 | |
remote: -----> Installing dependencies using bundler 1.13.7 | |
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment | |
remote: Fetching gem metadata from https://rubygems.org/.............. | |
remote: Fetching version metadata from https://rubygems.org/. | |
remote: Installing colored 1.2 | |
remote: Installing daemons 1.2.4 | |
remote: Installing ddplugin 1.0.1 | |
remote: Installing concurrent-ruby 1.0.5 | |
remote: Installing ref 2.0.0 | |
remote: Installing eventmachine 1.2.3 with native extensions | |
remote: Installing rack 2.0.1 | |
remote: Using bundler 1.13.7 | |
remote: Installing cri 2.8.0 | |
remote: Installing hamster 3.0.0 | |
remote: Installing nanoc 4.7.7 | |
remote: Installing thin 1.7.0 with native extensions | |
remote: Bundle complete! 2 Gemfile dependencies, 12 gems now installed. | |
remote: Gems in the groups development and test were not installed. | |
remote: Bundled gems are installed into ./vendor/bundle. | |
remote: Bundle completed (15.19s) | |
remote: Cleaning up the bundler cache. | |
remote: -----> Detecting rake tasks | |
remote: | |
remote: -----> Discovering process types | |
remote: Procfile declares types -> web | |
remote: Default types for buildpack -> console, rake | |
remote: | |
remote: -----> Compressing... | |
remote: Done: 20.6M | |
remote: -----> Launching... | |
remote: Released v4 | |
remote: https://polar-everglades-33448.herokuapp.com/ deployed to Heroku | |
remote: | |
remote: Verifying deploy.... done. | |
To https://git.heroku.com/polar-everglades-33448.git | |
* [new branch] master -> master | |
Branch master set up to track remote branch master from heroku. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git push heroku | |
Counting objects: 2, done. | |
Delta compression using up to 8 threads. | |
Compressing objects: 100% (2/2), done. | |
Writing objects: 100% (2/2), 241 bytes | 0 bytes/s, done. | |
Total 2 (delta 1), reused 0 (delta 0) | |
remote: Compressing source files... done. | |
remote: Building source: | |
remote: | |
remote: -----> Ruby app detected | |
remote: -----> Compiling Ruby/Rack | |
remote: -----> Using Ruby version: ruby-2.3.1 | |
remote: -----> Installing dependencies using bundler 1.13.7 | |
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment | |
remote: Using colored 1.2 | |
remote: Using concurrent-ruby 1.0.5 | |
remote: Using daemons 1.2.4 | |
remote: Using ddplugin 1.0.1 | |
remote: Using eventmachine 1.2.3 | |
remote: Using ref 2.0.0 | |
remote: Using rack 2.0.1 | |
remote: Using bundler 1.13.7 | |
remote: Using hamster 3.0.0 | |
remote: Using cri 2.8.0 | |
remote: Using nanoc 4.7.7 | |
remote: Using thin 1.7.0 | |
remote: Bundle complete! 2 Gemfile dependencies, 12 gems now installed. | |
remote: Gems in the groups development and test were not installed. | |
remote: Bundled gems are installed into ./vendor/bundle. | |
remote: Bundle completed (0.27s) | |
remote: Cleaning up the bundler cache. | |
remote: -----> Detecting rake tasks | |
remote: | |
remote: -----> Nanoc app detected | |
remote: -----> Compiling Nanoc Site | |
remote: Loading site… done | |
remote: Compiling site… | |
remote: create [0.00s] output/error/404-not_found/index.html | |
remote: create [0.00s] output/index.html | |
remote: create [0.00s] output/stylesheet.css | |
remote: | |
remote: Site compiled in 0.01s. | |
remote: -----> Discovering process types | |
remote: Procfile declares types -> web | |
remote: | |
remote: -----> Compressing... | |
remote: Done: 20.6M | |
remote: -----> Launching... | |
remote: Released v6 | |
remote: https://polar-everglades-33448.herokuapp.com/ deployed to Heroku | |
remote: | |
remote: Verifying deploy... done. | |
To https://git.heroku.com/polar-everglades-33448.git | |
1259baf..2e1caf7 master -> master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree | |
. | |
├── Gemfile | |
├── Gemfile.lock | |
├── Procfile | |
├── Rules | |
├── content | |
│ ├── index.html | |
│ └── stylesheet.css | |
├── layouts | |
│ └── default.html | |
├── lib | |
├── nanoc.yaml | |
├── output | |
│ ├── index.html | |
│ └── stylesheet.css | |
└── tmp | |
└── nanoc | |
└── 1029d67644815 | |
├── checksums | |
├── compiled_content | |
├── dependencies | |
├── outdatedness | |
└── rule_memory | |
7 directories, 15 files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment