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

OpenShift deployment #1703

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.sass-cache
.gist-cache
.pygments-cache
.ruby-version
.ruby-gemset
_deploy
public
sass.old
Expand Down
92 changes: 92 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,98 @@ multitask :push do
end
end

desc "Deploy website to OpenShift"
task :openshift do
puts "## Deploying branch to OpenShift"
puts "## Pulling any updates from OpenShift"
cd "#{deploy_dir}" do
Bundler.with_clean_env {
system "git pull origin master"
system "bundle install"
}
end
if Dir.exists? "#{public_dir}"
(Dir["#{deploy_dir}/public/*"]).each { |f| rm_rf(f) }
Rake::Task[:copydot].invoke(public_dir, deploy_dir)
puts "\n## Copying #{public_dir} to #{deploy_dir}/public"
cp_r "#{public_dir}/.", "#{deploy_dir}/public"
end
cd "#{deploy_dir}" do
system "git add -A"
message = "Site updated at #{Time.now.utc}"
puts "\n## Committing: #{message}"
system "git commit -m \"#{message}\""
puts "\n## Pushing generated #{deploy_dir} website"
Bundler.with_clean_env { system "git push -f origin master" }
puts "\n## OpenShift deploy complete"
end
end

desc "Set up _deploy folder and deploy branch for Openshift deployment"
task :setup_openshift, [:repo, :force_ssl] do |t, args|
if args.repo
repo_url = args.repo
else
puts "Enter the read/write url for your repository"
puts "(For example, 'ssh://[email protected]/~/git/example.git/')"
repo_url = get_stdin("Repository url: ")
end

url = /ssh:\/\/\w+@(?<url>\w+-\w+\.rhcloud\.com)/.match(repo_url)[:url]
jekyll_config = IO.read('_config.yml')
jekyll_config.sub!(/^url:.*$/, "url: #{url}")
File.open('_config.yml', 'w') do |f|
f.write jekyll_config
end
rm_rf deploy_dir
mkdir_p "#{deploy_dir}/public"

cd "#{deploy_dir}" do
system "git init"
system "git remote add origin #{repo_url}"
system "git pull origin master"
end

cp "config.ru", "#{deploy_dir}/"

cd "#{deploy_dir}" do
system 'echo "My Octopress Page is coming soon &hellip;" > public/index.html'

# Create Gemfile
File.open("Gemfile", "w") do |f|
f.puts "source 'https://rubygems.org'"
f.puts
f.puts "gem 'sinatra'"
unless args.force_ssl.nil?
f.puts "gem 'rack-ssl'"
end
end

unless args.force_ssl.nil?
puts "\n## Updating Static Server to force SSL in production"
file = File.readlines("config.ru")
index = file.index { |line| line =~ /class SinatraStaticServer/ }
file.insert(index+1, " configure :production do")
file.insert(index+2, " use Rack::SSL")
file.insert(index+3, " end\n\n")
file.insert(index, "require 'rack/ssl'\n\n")
File.open("config.ru", "w") do |f|
f.puts file
end
end

system "git add ."
system "git commit -m \"Octopress init\""
rakefile = IO.read(__FILE__)
rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3master\\3")
rakefile.sub!(/deploy_default(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_default\\1=\\2\\3openshift\\3")
File.open(__FILE__, 'w') do |f|
f.write rakefile
end
end
puts "\n---\n## Now you can deploy to #{repo_url} with `rake deploy` or `rake openshift` ##"
end

desc "Update configurations to support publishing to root or sub directory"
task :set_root_dir, :dir do |t, args|
puts ">>> !! Please provide a directory, eg. rake config_dir[publishing/subdirectory]" unless args.dir
Expand Down
2 changes: 0 additions & 2 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require 'sinatra/base'
$root = ::File.dirname(__FILE__)

class SinatraStaticServer < Sinatra::Base

get(/.+/) do
send_sinatra_file(request.path) {404}
end
Expand All @@ -19,7 +18,6 @@ class SinatraStaticServer < Sinatra::Base
file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
end

end

run SinatraStaticServer