lib/alchemy/capistrano.rb in alchemy_cms-2.9.1 vs lib/alchemy/capistrano.rb in alchemy_cms-3.0.0.rc5
- old
+ new
@@ -1,9 +1,12 @@
-# This recipe contains Capistrano recipes for handling the uploads, ferret index and picture cache files while deploying your application.
-# It also contains a ferret:rebuild_index task to rebuild the index after deploying your application.
+# This recipe contains Capistrano recipes for handling the uploads and picture cache files while deploying your application.
+#
require 'fileutils'
require 'alchemy/tasks/helpers'
+# Loading the current Rails app's env, so we can get the Alchemy mount point.
+require './config/environment.rb'
+require 'alchemy/mount_point'
include Alchemy::Tasks::Helpers
::Capistrano::Configuration.instance(:must_exist).load do
@@ -13,31 +16,42 @@
namespace :alchemy do
namespace :shared_folders do
- # This task creates the shared folders for uploads, picture cache and ferret index while setting up your server.
- # Call after deploy:setup like +after "deploy:setup", "alchemy:create_shared_folders"+ in your +deploy.rb+.
- desc "Creates the uploads and picture cache directory in the shared folder. Call after deploy:setup"
+ # This task creates the shared folders for uploads, assets and picture cache while setting up your server.
+ desc "Creates the uploads and picture cache directory in the shared folder. Called after deploy:setup"
task :create, :roles => :app do
- run "mkdir -p #{shared_path}/index"
run "mkdir -p #{shared_path}/uploads/pictures"
run "mkdir -p #{shared_path}/uploads/attachments"
- run "mkdir -p #{File.join(shared_path, 'cache', Capistrano::CLI.ui.ask("\nWhere is Alchemy CMS mounted at? ('/'): "), 'pictures')}"
+ run "mkdir -p #{shared_picture_cache_path}"
+ run "mkdir -p #{shared_path}/cache/assets"
end
- # This task sets the symlinks for uploads, picture cache and ferret index folder.
- # Call after deploy:symlink like +after "deploy:symlink", "alchemy:symlink_folders"+ in your +deploy.rb+.
- desc "Sets the symlinks for uploads, picture cache and ferret index folder. Call after deploy:symlink"
+ # This task sets the symlinks for uploads, assets and picture cache folder.
+ desc "Sets the symlinks for uploads and picture cache folder. Called after deploy:finalize_update"
task :symlink, :roles => :app do
run "rm -rf #{release_path}/uploads"
run "ln -nfs #{shared_path}/uploads #{release_path}/"
- run "ln -nfs #{shared_path}/cache/* #{release_path}/public/"
- run "rm -rf #{release_path}/index"
- run "ln -nfs #{shared_path}/index #{release_path}/"
+ run "mkdir -p #{public_path_with_mountpoint}"
+ run "ln -nfs #{shared_picture_cache_path} #{public_path_with_mountpoint('pictures')}"
+ run "mkdir -p #{release_path}/tmp/cache"
+ run "ln -nfs #{shared_path}/cache/assets #{release_path}/tmp/cache/assets"
end
+ def shared_picture_cache_path
+ @shared_picture_cache_path ||= begin
+ File.join(shared_path, 'cache', Alchemy::MountPoint.get, 'pictures')
+ end
+ end
+
+ def public_path_with_mountpoint(suffix = '')
+ @release_picture_cache_path ||= begin
+ File.join(release_path, 'public', Alchemy::MountPoint.get, suffix)
+ end
+ end
+
end
desc "Upgrades production database to current Alchemy CMS version"
task :upgrade do
run "cd #{current_path} && #{rake} RAILS_ENV=#{fetch(:rails_env, 'production')} alchemy:upgrade"
@@ -48,11 +62,11 @@
desc "Creates the database.yml file"
task :create do
environment = Capistrano::CLI.ui.ask("\nPlease enter the environment (Default: #{fetch(:rails_env, 'production')})")
environment = fetch(:rails_env, 'production') if environment.empty?
db_adapter = Capistrano::CLI.ui.ask("Please enter database adapter (Options: mysql2, or postgresql. Default mysql2): ")
- db_adapter = db_adapter.empty? ? 'mysql2' : db_adapter.gsub(/^mysql$/, 'mysql2')
+ db_adapter = db_adapter.empty? ? 'mysql2' : db_adapter.gsub(/\Amysql\z/, 'mysql2')
db_name = Capistrano::CLI.ui.ask("Please enter database name: ")
db_username = Capistrano::CLI.ui.ask("Please enter database username: ")
db_password = Capistrano::CLI.password_prompt("Please enter database password: ")
default_db_host = db_adapter == 'mysql2' ? 'localhost' : '127.0.0.1'
db_host = Capistrano::CLI.ui.ask("Please enter database host (Default: #{default_db_host}): ")
@@ -133,38 +147,14 @@
else
raise "No server found"
end
end
- def database_config
- raise "database.yml not found!" if !File.exists?("./config/database.yml")
- @database_config ||= begin
- config_file = YAML.load_file("./config/database.yml")
- if config = config_file.fetch(ENV['RAILS_ENV'] || 'development')
- config
- else
- raise "Database configuration for #{ENV['RAILS_ENV'] || 'development'} not found!"
- end
- end
- end
-
def db_import_cmd(server)
dump_cmd = "cd #{current_path} && #{rake} RAILS_ENV=#{fetch(:rails_env, 'production')} alchemy:db:dump"
sql_stream = "ssh -p #{fetch(:port, 22)} #{user}@#{server} '#{dump_cmd}'"
"#{sql_stream} | #{database_import_command(database_config['adapter'])} 1>/dev/null 2>&1"
end
- end
-
- end
-
- namespace :ferret do
-
- # This task rebuilds the ferret index for the EssenceText and EssenceRichtext Models.
- # Call it before deploy:restart like +before "deploy:restart", "alchemy:rebuild_index"+ in your +deploy.rb+.
- # It uses the +alchemy:rebuild_index+ rake task found in +vendor/plugins/alchemy/lib/tasks+.
- desc "Rebuild the ferret index. Call before deploy:restart"
- task :rebuild_index, :roles => :app do
- run "cd #{current_path} && #{rake} RAILS_ENV=#{fetch(:rails_env, 'production')} ferret:rebuild_index"
end
end
end