Skip to content

Instantly share code, notes, and snippets.

@kardeiz
Last active August 29, 2015 14:24
Show Gist options
  • Save kardeiz/a078ca906d4c59ee10df to your computer and use it in GitHub Desktop.
Save kardeiz/a078ca906d4c59ee10df to your computer and use it in GitHub Desktop.
DSpace deployment with Capistrano 3

And then run like:

rake -f Capfile staging deploy
rake -f Capfile staging mvn:package
rake -f Capfile staging ant:update
gem 'capistrano', '~> 3.4.0'
require File.expand_path('../.env.rb', __FILE__)
require 'capistrano/all'
require 'capistrano/deploy'
include Capistrano::DSL
set :application, ENV['app_name']
set :scm, :copy
set :keep_releases, 2
set :release_id, `git log --pretty=format:'%h' -n 1 HEAD`
set :tarball_path, "/tmp/#{fetch(:application)}-#{fetch(:release_id)}.tar.gz"
task :staging do
set :stage, :staging
set :dspace_env, ENV['staging.dspace.env']
set :deploy_to, ENV['staging.deploy_to']
load 'capistrano/defaults.rb'
server ENV['staging.server'], {
user: ENV['staging.user'],
roles: [ 'app']
}
configure_backend
end
namespace :copy do
desc 'Create and upload project tarball'
task :deploy do
tarball_path = fetch(:tarball_path)
unless system("git archive --format=tar HEAD | gzip > #{tarball_path}")
raise 'Error creating tarball'
end
on roles(:app) do
execute :mkdir, '-p', release_path
upload! tarball_path, tarball_path
execute :tar, '-xzf', tarball_path, '-C', release_path
execute :rm, tarball_path
end
end
task :clean do
tarball_path = fetch(:tarball_path)
File.delete tarball_path if File.exists? tarball_path
end
after 'deploy:finished', 'copy:clean'
task :create_release => :deploy
task :check
task :set_current_revision
end
namespace :local do
task :uploads do
on roles(:app) do
props = "#{fetch(:dspace_env)}.properties"
upload!(props, release_path)
end
end
end
namespace :maven do
task :package do
on roles(:app) do
within File.join(release_path, 'dspace') do
execute :mvn, %W{ package -Denv=#{ fetch(:dspace_env) } -Ddb.name=oracle }
end
end
end
end
namespace :ant do
tasks = [ :fresh_install, :clean_database, :update, :clean_backups ]
tasks.each do |t|
task t do
on roles(:app) do
within File.join(release_path, 'dspace/target/dspace-installer') do
execute :ant, [t]
end
end
end
end
end
after 'deploy:finished', 'local:uploads'
after 'deploy:finished', 'deploy:cleanup'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment