Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Rakefile mode switch #330

Closed
wants to merge 4 commits into from

2 participants

@jpravetz

Added a rakefile switch to allow deployment to production or development servers.

  • Generates _config.yml from source files (config-default.yml + config-MODE.yml) (task :gen_config)
  • Can specify different deploy document_root for different modes.
  • Defaults to development (rake task names backward compatible)
  • Added rake task options, eg. rake generate['production']

Pull request submitted in case someone else finds this useful. Or please tell me if I duplicated some work that was already done. There is a Jekyll pull request for a config switch on the command line (jekyll/jekyll#393). If this existed then presumably the _config.yml would not need to be generated, but the octopress rakefile would still need a MODE option.

Jim Pravetz added some commits
Jim Pravetz Added comment to compass config file
Added mode (development or production) to Rakefile. Now generate _config.yml dependent on which mode.
9eec210
Jim Pravetz Added Rakefile tasks for generating config file based on mode, and de…
…ploying based on mode, where mode is one of development or production.
78c43c5
Jim Pravetz Replaced site-specific data in config files with generic data as per …
…imathis settings
e440bf3
Jim Pravetz Removing _config.yml since it is generated. 6aa12da
@imathis
Owner

I've been thinking about this for a while because yeah it'd be nice if there was this capability. We're working through some major changes in configuration right now so that may change the way this feature would be implemented and we may or may not end up merging this in. Regardless, thanks for the submission.

@jpravetz
@imathis imathis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 17, 2011
  1. Added comment to compass config file

    Jim Pravetz authored
    Added mode (development or production) to Rakefile. Now generate _config.yml dependent on which mode.
  2. Added Rakefile tasks for generating config file based on mode, and de…

    Jim Pravetz authored
    …ploying based on mode, where mode is one of development or production.
  3. Replaced site-specific data in config files with generic data as per …

    Jim Pravetz authored
    …imathis settings
  4. Removing _config.yml since it is generated.

    Jim Pravetz authored
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -3,6 +3,7 @@
.sass-cache
.gist-cache
.pygments-cache
+_config.yml
_deploy
public
sass.old
View
57 Rakefile
@@ -1,13 +1,17 @@
require "rubygems"
require "bundler/setup"
require "stringex"
+require 'yaml'
## -- Rsync Deploy config -- ##
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
ssh_user = "user@domain.com"
ssh_port = "22"
-document_root = "~/website.com/"
+document_root = {
+ 'development' => "~/sandbox.website.com/",
+ 'production' => "~/website.com/" }
deploy_default = "rsync"
+deploy_mode = 'development' # One of 'development' or 'production'
# This will be configured for you when you run config_deploy
deploy_branch = "gh-pages"
@@ -16,10 +20,11 @@ deploy_branch = "gh-pages"
public_dir = "public" # compiled site directory
source_dir = "source" # source file directory
-blog_index_dir = 'source' # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')
+blog_index_dir = 'source/blog' # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')
deploy_dir = "_deploy" # deploy directory (for Github pages deployment)
stash_dir = "_stash" # directory to stash posts for speedy generation
posts_dir = "_posts" # directory for blog files
+data_dir = '_data' # directory where database equivalent files are kept (eg. products JSON file)
themes_dir = ".themes" # directory for blog files
new_post_ext = "markdown" # default new post file extension when using the new_post task
new_page_ext = "markdown" # default new page file extension when using the new_page task
@@ -47,9 +52,10 @@ end
#######################
desc "Generate jekyll site"
-task :generate do
+task :generate, [:mode] => [:gen_config] do |t,args|
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
- puts "## Generating Site with Jekyll"
+ args.with_defaults( :mode => 'development' )
+ puts "## Generating #{args[:mode]} site using Jekyll"
system "compass compile --css-dir #{source_dir}/stylesheets"
system "jekyll"
end
@@ -194,18 +200,37 @@ task :update_source, :theme do |t, args|
puts "## Updated #{source_dir} ##"
end
+desc "Generate _config.yml file from _config_default.yml and _config_MODE.yml."
+task :gen_config, :mode do |t,args|
+ args.with_defaults( :mode => 'development' )
+ ofile = '_config.yml'
+ dfile = 'config-default.yml'
+ mfile = "config-#{args['mode']}.yml"
+ puts "## Generating #{ofile} from #{dfile} and #{mfile}"
+ config = YAML::load( File.open(dfile) )
+ config_mode = YAML::load( File.open(mfile) )
+ config.merge!( config_mode )
+ File.open( ofile, 'w') do |f|
+ f.puts("# Generated file. Do not edit")
+ f.write(config.to_yaml)
+ end
+end
+
##############
# Deploying #
##############
desc "Default deploy task"
-task :deploy do
+task :deploy, :mode do |t,args|
+ args.with_defaults( :mode => 'development' )
+ puts "## Deployment mode: #{args[:mode]}"
Rake::Task[:copydot].invoke(source_dir, public_dir)
- Rake::Task["#{deploy_default}"].execute
+ Rake::Task["#{deploy_default}"].execute(args)
end
desc "Generate website and deploy"
-task :gen_deploy => [:integrate, :generate, :deploy] do
+task :gen_deploy, [:mode] => [:integrate, :generate, :deploy] do
+ args.with_defaults( :mode => 'development' )
end
desc "copy dot files for deployment"
@@ -219,9 +244,10 @@ task :copydot, :source, :dest do |t, args|
end
desc "Deploy website via rsync"
-task :rsync do
- puts "## Deploying website via Rsync"
- ok_failed system("rsync -avze 'ssh -p #{ssh_port}' --delete #{public_dir}/ #{ssh_user}:#{document_root}")
+task :rsync, :mode do |t,args|
+ raise "### You must specify rsync mode: choose development or production." unless args[:mode]
+ puts "## Deploying #{args[:mode]} website via Rsync"
+ ok_failed system("rsync -avze 'ssh -p #{ssh_port}' --delete #{public_dir}/ #{ssh_user}:#{document_root[args[:mode]]}")
end
desc "deploy public directory to github pages"
@@ -265,11 +291,11 @@ task :set_root_dir, :dir do |t, args|
File.open('config.rb', 'w') do |f|
f.write compass_config
end
- jekyll_config = IO.read('_config.yml')
+ jekyll_config = IO.read('config-default.yml')
jekyll_config.sub!(/^destination:.+$/, "destination: public#{dir}")
jekyll_config.sub!(/^subscribe_rss:\s*\/.+$/, "subscribe_rss: #{dir}/atom.xml")
jekyll_config.sub!(/^root:.*$/, "root: /#{dir.sub(/^\//, '')}")
- File.open('_config.yml', 'w') do |f|
+ File.open('config-default.yml', 'w') do |f|
f.write jekyll_config
end
rm_rf public_dir
@@ -304,9 +330,9 @@ task :setup_github_pages do
end
url = "http://#{user}.github.com"
url += "/#{project}" unless project == ''
- jekyll_config = IO.read('_config.yml')
+ jekyll_config = IO.read('config-default.yml')
jekyll_config.sub!(/^url:.*$/, "url: #{url}")
- File.open('_config.yml', 'w') do |f|
+ File.open('config-default.yml', 'w') do |f|
f.write jekyll_config
end
rm_rf deploy_dir
@@ -343,7 +369,8 @@ end
def ask(message, valid_options)
if valid_options
- answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
+ tva = valid_options.to_s.gsub(/\"/, '').gsub(/, /,'/')
+ answer = get_stdin("#{message} #{tva} ") while !valid_options.include?(answer)
else
answer = get_stdin(message)
end
View
15 _config.yml → config-default.yml
@@ -1,3 +1,6 @@
+## config-default.yml Jekyll configuration file
+## This is merged with the mode-specific file to generate _config.yml
+
# ----------------------- #
# Main Configs #
# ----------------------- #
@@ -7,6 +10,7 @@ title: My Octopress Blog
subtitle: A blogging framework for hackers.
author: Your Name
simple_search: http://google.com/search
+description:
# Default date format is "ordinal" (resulting in "July 22nd 2007")
# You can customize the format as defined in
@@ -31,7 +35,6 @@ source: source
destination: public
plugins: plugins
code_dir: downloads/code
-category_dir: blog/categories
markdown: rdiscount
pygments: false # default python pygments have been replaced by pygments.rb
@@ -44,7 +47,7 @@ titlecase: true # Converts page and post titles to tilecase
# list each of the sidebar modules you want to include, in the order you want them to appear.
# To add custom asides, create files in /source/_includes/custom/asides/ and add them to the list like 'custom/asides/custom_aside_name.html'
-default_asides: [asides/recent_posts.html, asides/github.html, asides/twitter.html, asides/delicious.html, asides/pinboard.html, asides/googleplus.html]
+default_asides: [ asides/recent_posts.html, asides/github.html, asides/twitter.html, asides/delicious.html, asides/pinboard.html, asides/googleplus.html ]
# Each layout uses the default asides, but they can have their own asides instead. Simply uncomment the lines below
# and add an array with the asides you want to use.
@@ -76,7 +79,7 @@ google_plus_one_size: medium
# Google Plus Profile
# Hidden: No visible button, just add author information to search results
-googleplus_user:
+googleplus_user:
googleplus_hidden: false
# Pinboard
@@ -88,11 +91,11 @@ delicious_user:
delicious_count: 3
# Disqus Comments
-disqus_short_name:
+disqus_short_name:
disqus_show_comment_count: false
-# Google Analytics
-google_analytics_tracking_id:
+# Google Analytics. Recomend using different tracking numbers for development and production.
+google_analytics_tracking_id:
# Facebook Like
facebook_like: false
View
4 config-development.yml
@@ -0,0 +1,4 @@
+## config-development.yml Jekyll configuration file
+## This is merged with config-default to generate _config.yml
+
+url: http://sandbox.yoursite.com
View
4 config-production.yml
@@ -0,0 +1,4 @@
+## config-production.yml Jekyll configuration file
+## This is merged with config-default to generate _config.yml
+
+url: http://yoursite.com
View
2  config.rb
@@ -1,3 +1,5 @@
+## Compass configuration file
+
# Require any additional compass plugins here.
project_type = :stand_alone
Something went wrong with that request. Please try again.