Permalink
Browse files

Added route /sync for synchronizing data directory by Github post com…

…mit URL hook
  • Loading branch information...
1 parent c786267 commit 33d436004231512ae87886fbf3bfeadfe0fcc405 @karmi committed Nov 9, 2008
Showing with 21 additions and 2 deletions.
  1. +1 −1 README.rdoc
  2. +7 −1 app/marley.rb
  3. +3 −0 config/config.example.yml
  4. +10 −0 config/deploy.example.rb
View
@@ -63,7 +63,7 @@ There are several ways how to do that:
* You can implement some sane practice and start versioning your writing with Git. (What else?) This way, you can setup remote repository on your server, just <tt>push</tt>-ing changes whenever you feel like you want to say something in public. A <i>post-commit hook</i> is completely neccessary in this case, of course. (It isn't paramount of convenience having to SSH on your server to run <tt>git pull origin master</tt> in some folder.) You can use Capistrano task <tt>cap sync:setup</tt> for setting this up!
-* When you already use Git, you can push to Github (where else?), and have Github call Marley by it's Post-Receive Hooks (http://github.com/guides/post-receive-hooks). See the <tt>get "/sync"</tt> route dangling towards the end of the marley.rb? You get the picture.
+* When you already use Git, you can push to Github (where else?), and have Github call Marley by it's Post-Receive Hooks (http://github.com/guides/post-receive-hooks). Github then calls Marley's <tt>/sync</tt> and it will <tt>git pull</tt> changes from Github. How is this authenticated? Good question. By setting up a (possibly long and secure) token in the config file. OMG! Could be overheard in the internets! If you're worried or prudent, do not use this. (Use Capistrano task <tt>cap sync:setup:github</tt> for adding remote Github repo on the server.)
Of course, put other ideas in the Marley Wiki (http://github.com/karmi/marley/wikis)
View
@@ -125,7 +125,13 @@ def error
post '/sync' do
- puts params
+ throw :halt, 404 and return if not CONFIG['github_token'] or CONFIG['github_token'].nil?
+ unless params[:token] && params[:token] == CONFIG['github_token']
+ throw :halt, [500, "You did wrong.\n"] and return
+ else
+ # Synchronize articles in data directory to Github repo
+ system "cd #{CONFIG['data_directory']}; git pull github master"
+ end
end
get '/about' do
@@ -8,6 +8,9 @@ ga_code: "{REPLACE WITH YOUR GOOGLE ANALYTICS CODE OR LEAVE EMPTY}"
# Set this relatively to application main ("marley") directory
data_directory: "../../data"
+# If you want to add synchronizing via Github post-receive hooks, insert some secure password here
+# Then set a "Post-Receive URL" in Github administration to http://{YOUR SERVER}/sync?token={WHAT YOU SET BELOW}
+github_token: ~
# See http://soakedandsoaped.com/articles/2006/10/01/how-to-protect-a-rails-application-against-spam-with-akismet
akismet:
View
@@ -52,6 +52,13 @@
`cd #{CONFIG['data_directory']}; git remote add sync #{user}@#{roles[:app].instance_variable_get(:@static_servers).first.instance_variable_get(:@host)}:#{deploy_to}/articles.git`
puts "--- Added remote repository 'sync' for data. Use 'git push sync' to synchronize your content.\n"
end
+ desc "Add Github remote repo in your data directory"
+ task :github do
+ remote_data_directory = File.join(deploy_to, CONFIG['data_directory'].split('/').last)
+ url = Capistrano::CLI.ui.ask "Enter Github clone URL (you need to setup deploy keys for private repo):"
+ run "cd #{remote_data_directory}; git clone #{url} ."
+ run "cd #{remote_data_directory}; git remote add github #{url}"
+ end
end
end
@@ -69,6 +76,9 @@
before "deploy:cold" do
app.upload_config
+end
+
+after "deploy:cold" do
app.create_database_for_comments
end

0 comments on commit 33d4360

Please sign in to comment.