Guest User

Untitled

a guest
Mar 7th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. module Helpers
  3. LINE = 80
  4.  
  5. def announcing(msg)
  6. print msg
  7. yield
  8. print "." * (LINE - msg.size - 6)
  9. puts "\e[32m[DONE]\e[0m"
  10. end
  11.  
  12. def silent(command)
  13. system "#{command} &> /dev/null"
  14. end
  15.  
  16. def svn(command, *args)
  17. silent "svn #{command} #{args.join(' ')}"
  18. end
  19.  
  20. def git(command, *args)
  21. silent "git #{command} #{args.join(' ')}"
  22. end
  23.  
  24. def piston(repo)
  25. silent "piston import #{repo}"
  26. end
  27.  
  28. def rake(task, args={})
  29. args = args.map {|name,value| "#{name.to_s.upcase}=#{value}"}.join(" ")
  30. silent "rake #{task} #{args}"
  31. end
  32.  
  33. def ray(task, args={})
  34. args = args.map {|name,value| "#{name.to_s.upcase}=#{value}"}.join(" ")
  35. system "rake ray:#{task} #{args}"
  36. end
  37. end
  38.  
  39. if __FILE__ == $0
  40. include Helpers
  41.  
  42. app_name = ARGV.first || exit(1)
  43.  
  44. # Used for the Capfile.
  45. admin_password = 'your_password'
  46. db_template = 'roasters.yml'
  47. repositories_root = 'kaizer@zuurstof.openminds.be:git'
  48. repositories_password = 'your_scm_password'
  49. app_server = ARGV[1] || 'zink.openminds.be'
  50. db_host = 'kwik.openminds.be'
  51.  
  52. announcing "Creating new Radiant instance and initializing git repository" do
  53. silent "radiant #{app_name}"
  54. Dir.chdir(app_name)
  55. git "init"
  56. end
  57.  
  58. announcing "setting up development and test db" do
  59. silent "mysqladmin -u root create #{app_name}_development"
  60. silent "mysqladmin -u root create #{app_name}_test"
  61. silent "rake ADMIN_NAME='Administrator' ADMIN_USERNAME='admin' ADMIN_PASSWORD='#{admin_password}' DATABASE_TEMPLATE=#{db_template} OVERWRITE=true db:bootstrap"
  62. end
  63.  
  64. announcing "Installing plugins" do
  65. git "submodule add git://github.com/technoweenie/attachment_fu.git vendor/plugins/attachment_fu" # requirement for gallery extension
  66. end
  67.  
  68. announcing "Installing ray extension" do
  69. git "submodule add git://github.com/jomz/radiant-ray-extension.git vendor/extensions/ray"
  70. git "submodule init"
  71. git "submodule update"
  72. silent "rake ray:setup:download"
  73. silent "rake ray:setup:restart server=passenger"
  74. end
  75.  
  76. announcing "Installing default extensions" do
  77. bundle = %Q{---
  78. - name: aggregation
  79. - name: comments
  80. hub: jomz
  81. fullname: radiant-comments
  82. - name: copy-move
  83. - name: enkodertags
  84. - name: first-reorder
  85. - name: gallery
  86. hub: jomz
  87. fullname: radiant-gallery
  88. - name: gmaps
  89. - name: gorillafy
  90. hub: jomz
  91. - name: gorilla-blog
  92. - name: index-page
  93. - name: mailer
  94. hub: jomz
  95. - name: navigation_tags
  96. hub: jomz
  97. - name: nested-layouts
  98. - name: paperclipped
  99. hub: jomz
  100. - name: search
  101. - name: settings
  102. hub: jomz
  103. fullname: radiant-settings-extension
  104. - name: share-layouts
  105. - name: tags
  106. - name: trike-tags
  107. - name: wym-editor-filter
  108. }
  109. system "touch config/extensions.yml"
  110. system "echo \"#{bundle}\" > config/extensions.yml"
  111. ray "extension:bundle"
  112. end
  113.  
  114. announcing "Tweaking mailer ext." do
  115. silent "cd vendor/extensions/mailer"
  116. silent "git pull origin clientside-validation"
  117. silent "git pull origin with_mailbuild_signups"
  118. silent "cd ../../.."
  119. silent "rake radiant:extensions:mailer:update"
  120. end
  121.  
  122. announcing "capify'ing" do
  123. system "touch Capfile"
  124. capfile = %Q{load "deploy" if respond_to?(:namespace) # cap2 differentiator
  125.  
  126. require "capistrano/deepmodules"
  127.  
  128. set :use_sudo, false
  129. set :group_writable, false
  130. set :keep_releases, 4
  131.  
  132. set :application, "default"
  133. set :user, "#{app_name}"
  134.  
  135. default_run_options[:pty] = true
  136.  
  137. set :scm, "git"
  138. set :repository, "#{repositories_root}/\#{user}.git"
  139. set :password, "updateme"
  140. set :scm_password, "#{repositories_password}"
  141. set :git_enable_submodules,1
  142.  
  143. set :branch, "master"
  144. set :deploy_via, :remote_cache
  145. set :deploy_to, "/home/\#{user}/apps/\#{application}"
  146. ssh_options[:forward_agent] = true
  147.  
  148. server "#{app_server}", :app, :web, :db, :primary => true
  149.  
  150. DatabaseYml = %Q{# By capistrano
  151. production:
  152. adapter: mysql
  153. database: #{app_name}
  154. username: #{app_name}
  155. password: updateme
  156. host: #{db_host}
  157. }
  158.  
  159. # passenger config
  160. namespace :passenger do
  161. desc "Restart the web server"
  162. task :restart, :roles => :app do
  163. run "touch \#{current_release}/tmp/restart.txt"
  164. end
  165.  
  166. [:start, :stop].each do |t|
  167. desc "\#{t} task is a no-op with passenger"
  168. task t, :roles => :app do ; end
  169. end
  170. end
  171.  
  172. namespace :deploy do
  173. desc "Restart your application"
  174. task :restart do
  175. passenger::restart
  176. end
  177.  
  178. desc "Start your application"
  179. task :start do
  180. passenger::start
  181. end
  182.  
  183. desc "Stop your application"
  184. task :stop do
  185. passenger::stop
  186. end
  187. end
  188.  
  189. namespace :configs do
  190. desc "Create all config files in shared/config"
  191. task :copy_database_config do
  192. run "mkdir -p \#{shared_path}/config"
  193. put DatabaseYml, "\#{shared_path}/config/database.yml"
  194. end
  195.  
  196. desc "Link in the shared config files"
  197. task :link do
  198. run "ln -nfs \#{shared_path}/config/database.yml \#{release_path}/config/database.yml"
  199. end
  200. end
  201.  
  202. namespace :public_files do
  203. desc "Create shared assets dir"
  204. task :create_shared_assets do
  205. run "mkdir -p \#{shared_path}/public/assets"
  206. end
  207.  
  208. desc "Create shared galleries dir"
  209. task :create_shared_galleries do
  210. run "mkdir -p \#{shared_path}/public/galleries"
  211. end
  212.  
  213. desc "Link public/assets to shared/public/assets"
  214. task :link_assets do
  215. run "ln -nfs \#{shared_path}/public/assets \#{release_path}/public/assets"
  216. end
  217.  
  218. desc "Link public/galleries to shared/public/galleries"
  219. task :link_galleries do
  220. run "ln -nfs \#{shared_path}/public/galleries \#{release_path}/public/galleries"
  221. end
  222. end
  223.  
  224. namespace :deploy do
  225. desc "Keep only 3 releases"
  226. task :after_default do
  227. cleanup
  228. end
  229.  
  230. after "deploy:migrate", "deploy:radiant:migrate:extensions"
  231.  
  232. desc "Overridden deploy:cold for Radiant."
  233. task :cold do
  234. update
  235. radiant::bootstrap
  236. start
  237. end
  238.  
  239. namespace :radiant do
  240. desc "Radiant Bootstrap with empty template and default values."
  241. task :bootstrap do
  242. rake = fetch(:rake, "rake")
  243. rails_env = fetch(:rails_env, "production")
  244.  
  245. run "cd \#{current_release}; \#{rake} RAILS_ENV=\#{rails_env} ADMIN_NAME=Administrator ADMIN_USERNAME=admin ADMIN_PASSWORD=radiant DATABASE_TEMPLATE=empty.yml OVERWRITE=true db:bootstrap"
  246. end
  247.  
  248. namespace :migrate do
  249. desc "Runs migrations on extensions."
  250. task :extensions do
  251. rake = fetch(:rake, "rake")
  252. rails_env = fetch(:rails_env, "production")
  253. run "cd \#{current_release}; \#{rake} RAILS_ENV=\#{rails_env} db:migrate:extensions"
  254. end
  255. end
  256.  
  257. end
  258. end
  259.  
  260. desc "After Code Update"
  261. task :after_update_code do
  262. configs::link
  263. public_files::link_assets
  264. public_files::link_galleries
  265. end
  266.  
  267. desc "After setup"
  268. task :after_setup do
  269. configs::copy_database_config
  270. public_files::create_shared_assets
  271. public_files::create_shared_galleries
  272. end
  273. }
  274. system "echo '#{capfile}' > Capfile"
  275. end
  276.  
  277. announcing "committing kickstart" do
  278. git "add ."
  279. git "commit -m 'kickstarted'"
  280. end
  281.  
  282. announcing "setting ignore rules" do
  283. system "touch .gitignore"
  284. ignores = %Q{.DS_Store
  285. log/*.log
  286. db/schema.rb
  287. db/*.sqlite3
  288. config/database.yml
  289. cache
  290. tmp
  291. }
  292. system "echo \"#{ignores}\" > .gitignore"
  293. git "add .gitignore"
  294. git "commit -m 'setting ignore rules'"
  295. end
  296. end
Add Comment
Please, Sign In to add comment