Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add poor-man's CD pipeline

- Remove S3 stuff from Rakefile
- Add script to build and deploy from a given commit
- Add script to 'promote' from preprod to prod

This uses git branches as markers for what's currently in preprod and
prod.
  • Loading branch information...
commit d882ac8c69cccc19cf8b97890329c3e4209f7142 1 parent a3aacfd
@moredip authored
View
8 Rakefile
@@ -10,8 +10,6 @@ document_root = "~/website.com/"
rsync_delete = true
deploy_default = "rsync"
-s3_bucket = "blog.thepete.net"
-
# This will be configured for you when you run config_deploy
deploy_branch = "gh-pages"
@@ -208,12 +206,6 @@ end
# Deploying #
##############
-desc "Generate and then deploy website via s3cmd"
-task :gen_deploy_s3 => [:integrate, :generate] do
- puts "## Deploying website via s3cmd"
- ok_failed system("s3cmd sync --acl-public --no-delete-removed --reduced-redundancy public/* s3://#{s3_bucket}/")
-end
-
desc "add blogger-style permalinks"
task :blogger_permalinks do
Dir["#{public_dir}/blog/20*/*/**/index.html"].each do |path|
View
59 scripts/deploy
@@ -1,59 +0,0 @@
-#! /usr/bin/env ruby
-
-require 'fileutils'
-require 'tmpdir'
-
-def deploy_to_bucket_from_commit( bucket_name, commit_sha )
- using_a_temporary_dir do |temp_dir|
- extract_commit_into_dir( commit_sha, temp_dir )
- prep_gems_in_dir( temp_dir )
- Dir.chdir temp_dir do
- generate_site
- deploy_site_to_bucket( bucket_name )
- end
- end
-end
-
-def using_a_temporary_dir &block
- Dir.mktmpdir("octopress_deployment",&block)
- #temp_dir = Dir.mktmpdir
- #puts "temp dir is #{temp_dir}"
- #yield temp_dir
-end
-
-def extract_commit_into_dir( commit_sha, dir )
- `git archive --format=tar #{commit_sha} | tar -x -C #{dir}`
- raise 'git archive failed' unless $?.success?
-end
-
-def prep_gems_in_dir( dir )
- FileUtils.cp_r( '.bundle', dir )
- FileUtils.cp_r( 'vendor', dir )
-end
-
-def generate_site
- success = system 'bundle exec rake generate'
- raise 'rake generate failed' unless success
-end
-
-def deploy_site_to_bucket( bucket_name )
- success = system "s3cmd sync --acl-public --no-delete-removed --reduced-redundancy public/* s3://#{bucket_name}/"
- raise 'deploy failed' unless success
-end
-
-
-case ARGV.count
-when 0
- puts 'you need to specify an s3 bucket to deploy to (and optionally a commit SHA to deploy from'
- exit 1
-when 1,2
- bucket_name,commit_sha = ARGV
- commit_sha ||= 'HEAD'
-else
- puts 'this command only takes a maximum of two arguments (bucket name and commit SHA)'
- exit 1
-end
-
-puts "\ndeploying to #{bucket_name} from #{commit_sha}...\n\n"
-
-deploy_to_bucket_from_commit( bucket_name, commit_sha )
View
50 scripts/deployer.rb
@@ -0,0 +1,50 @@
+require 'fileutils'
+require 'tmpdir'
+
+class Deployer
+
+ def self.deploy_to_bucket_from_commit( *args )
+ new.deploy_to_bucket_from_commit( *args )
+ end
+
+ def deploy_to_bucket_from_commit( bucket_name, commit_sha )
+ using_a_temporary_dir do |temp_dir|
+ extract_commit_into_dir( commit_sha, temp_dir )
+ prep_gems_in_dir( temp_dir )
+ Dir.chdir temp_dir do
+ generate_site
+ deploy_site_to_bucket( bucket_name )
+ end
+ end
+ end
+
+ private
+
+ def using_a_temporary_dir &block
+ Dir.mktmpdir("octopress_deployment",&block)
+ #temp_dir = Dir.mktmpdir
+ #puts "temp dir is #{temp_dir}"
+ #yield temp_dir
+ end
+
+ def extract_commit_into_dir( commit_sha, dir )
+ `git archive --format=tar #{commit_sha} | tar -x -C #{dir}`
+ raise 'git archive failed' unless $?.success?
+ end
+
+ def prep_gems_in_dir( dir )
+ FileUtils.cp_r( '.bundle', dir )
+ FileUtils.cp_r( 'vendor', dir )
+ end
+
+ def generate_site
+ success = system 'bundle exec rake generate'
+ raise 'rake generate failed' unless success
+ end
+
+ def deploy_site_to_bucket( bucket_name )
+ success = system "s3cmd sync --acl-public --no-delete-removed --reduced-redundancy public/* s3://#{bucket_name}/"
+ raise 'deploy failed' unless success
+ end
+
+end
View
17 scripts/git_helper.rb
@@ -0,0 +1,17 @@
+module GitHelper
+ class << self
+ def distance_between_revs( old_rev, new_rev )
+ output = `git rev-list #{old_rev}..#{new_rev}`
+ unless $?.success?
+ puts output
+ raise "couldn't figure out the relationship between the preprod marker branch and the rev you want to deploy"
+ end
+
+ output.split("\n").count
+ end
+
+ def is_fast_forward( old_rev, new_rev )
+ distance_between_revs( new_rev, old_rev ) == 0
+ end
+ end
+end
View
28 scripts/promote_preprod_to_prod
@@ -0,0 +1,28 @@
+#! /usr/bin/env ruby
+
+require_relative( 'git_helper' )
+require_relative( 'deployer' )
+
+BUCKET_NAME='blog.thepete.net'
+PREPROD_MARKER_BRANCH='pre-blog'
+PROD_MARKER_BRANCH='live-blog'
+
+unless GitHelper.is_fast_forward( PROD_MARKER_BRANCH, PREPROD_MARKER_BRANCH )
+ puts <<-EOS
+Sorry, what's live on blog.thepete.net now can't be cleanly fast-forwarded into what's
+currently on preblog.thepete.net. Get your pre-blog branch fixed up first and then try again."
+ EOS
+ exit 1
+end
+
+distance = GitHelper.distance_between_revs( PROD_MARKER_BRANCH, PREPROD_MARKER_BRANCH )
+if distance == 0
+ puts "Looks like preprod and prod are already in sync. Nothing to be done."
+ exit 2
+else
+ puts "There are #{distance} new commits in pre-prod which will now be promoted to prod."
+end
+
+Deployer.deploy_to_bucket_from_commit( BUCKET_NAME, PREPROD_MARKER_BRANCH )
+`git branch -f #{PROD_MARKER_BRANCH} #{PREPROD_MARKER_BRANCH}`
+`git push origin #{PROD_MARKER_BRANCH}:#{PROD_MARKER_BRANCH}`
View
27 scripts/push_preprod
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby
+
+require_relative( 'git_helper' )
+require_relative( 'deployer' )
+
+BUCKET_NAME='preblog.thepete.net'
+PREPROD_MARKER_BRANCH='pre-blog'
+
+candidate_rev = ARGV[0] || 'HEAD'
+
+unless GitHelper.is_fast_forward( PREPROD_MARKER_BRANCH, candidate_rev )
+ puts "sorry, #{PREPROD_MARKER_BRANCH} can't be fast-forwarded to #{candidate_rev}"
+ exit 1
+end
+
+distance = GitHelper.distance_between_revs( PREPROD_MARKER_BRANCH, candidate_rev )
+if distance == 0
+ puts "#{candidate_rev} appears to be what's currently in preprod. No point in deploying."
+ exit 2
+else
+ puts "There have been #{distance} commits since your last push to preprod"
+end
+
+
+Deployer.deploy_to_bucket_from_commit( BUCKET_NAME, candidate_rev )
+`git branch -f #{PREPROD_MARKER_BRANCH} #{candidate_rev}`
+`git push origin #{PREPROD_MARKER_BRANCH}:#{PREPROD_MARKER_BRANCH}`
Please sign in to comment.
Something went wrong with that request. Please try again.