سؤال

I'm writing my first Rakefile. The first things that I see in the doc is "there is no special format for a Rakefile" and "there is no special syntax in a Rakefile".

Ok, so I had to come up with something on my own, but I can see at least two problems with my creature:

1) I need to create a number of folders, five of them. The sequence of 6 directory tasks looks a bit weird. The list of 5 dependencies in deploy task looks even more weird. Can I shrink it down to one line somehow?

2) I need to repeat my directory name literals two times - when I define their deployment paths and when I copy the contents. Can I avoid that without introducing 5 more variables?

In Java Ant I would create a properties file with all name literals - can I do that with Rake?

This is what I've got:

WEBAPPSDIR = '/var/webapps/'
WEBAPPNAME = 'foo.local'
WEBAPPDIR = File.join(WEBAPPSDIR, WEBAPPNAME)
VIEWSDIR = File.join(WEBAPPDIR, 'views')
PUBLICDIR = File.join(WEBAPPDIR, 'public')
CSSDIR = File.join(PUBLICDIR, 'css')
IMAGESDIR = File.join(PUBLICDIR, 'images')
TMPDIR = File.join(WEBAPPDIR, 'tmp')
HTMLDIR = File.join(PUBLICDIR, 'html')

directory VIEWSDIR
directory CSSDIR
directory HTMLDIR
directory IMAGESDIR
directory TMPDIR

desc 'Deploy to webapps dir'
task :deploy => [VIEWSDIR, CSSDIR, IMAGESDIR, TMPDIR, HTMLDIR] do
  cp 'config.ru', WEBAPPDIR
  Dir.glob('*.rb') {|f| cp f, WEBAPPDIR}
  Dir.glob('views/*.{mab,str}') {|f| cp f, VIEWSDIR}
  Dir.glob('css/*.css') {|f| cp f, CSSDIR}
  Dir.glob('images/*.{png,jpg,gif}') {|f| cp f, IMAGESDIR}
  Dir.glob('html/*.html') {|f| cp f, VIEWSDIR}
end

desc 'Cleans webapp dir'
task :clean do
  rm_r WEBAPPDIR, {force: true}
end

Other thoughts/links/examples are welcome too.

هل كانت مفيدة؟

المحلول

This does not really answer your question - but why don't you use capistrano ? If you don't know it already, it's a ruby tool frequently used to handle deployments smoothly

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top