Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit of magentify gem

Create a gem package for the Magento specific capistrano functionality.
Extending the core deploy recipe.
  • Loading branch information...
commit 933a4dcd2c9f4a5a380adedb9e0a7e5c1e0c0b9e 0 parents
@alistairstead authored
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
4 Gemfile
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in magentify.gemspec
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Alistair Stead
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 README.md
@@ -0,0 +1,29 @@
+# Magentify
+
+TODO: Write a gem description
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'magentify'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install magentify
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
2  Rakefile
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
84 bin/magentify
@@ -0,0 +1,84 @@
+#!/usr/bin/env ruby
+
+require 'optparse'
+require 'fileutils'
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: #{File.basename($0)} [path]"
+
+ opts.on("-h", "--help", "Displays this help info") do
+ puts opts
+ exit 0
+ end
+
+ begin
+ opts.parse!(ARGV)
+ rescue OptionParser::ParseError => e
+ warn e.message
+ puts opts
+ exit 1
+ end
+end
+
+if ARGV.empty?
+ abort "Please specify the directory to capifony, e.g. `#{File.basename($0)} .'"
+elsif !File.exists?(ARGV.first)
+ abort "`#{ARGV.first}' does not exist."
+elsif !File.directory?(ARGV.first)
+ abort "`#{ARGV.first}' is not a directory."
+elsif ARGV.length > 1
+ abort "Too many arguments; please specify only the directory to magentify."
+end
+
+def unindent(string)
+ indentation = string[/\A\s*/]
+ string.strip.gsub(/^#{indentation}/, "")
+end
+
+base = ARGV.shift
+
+files = {
+ "Capfile" => unindent(<<-FILE),
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
+ Dir['plugins/*/lib/recipes/*.rb'].each { |plugin| load(plugin) }
+ load Gem.find_files('mage.rb').last.to_s
+ load 'config/deploy'
+ FILE
+
+ "config/deploy.rb" => 'set :application, "set your application name here"
+set :domain, "#{application}.com"
+set :deploy_to, "/var/www/#{domain}"
+
+set :repository, "#{domain}:/var/repos/#{application}.git"
+set :scm, :git
+# Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, `subversion` or `none`
+
+role :web, domain # Your HTTP server, Apache/etc
+role :app, domain # This may be the same as your `Web` server
+role :db, domain, :primary => true # This is where Rails migrations will run
+
+set :keep_releases, 3
+
+set :app_symlinks, ["/media", "/var", "/sitemaps", "/staging"]
+set :app_shared_dirs, ["/app/etc", "/sitemaps", "/media", "/var", "/staging"]
+set :app_shared_files, ["/app/etc/local.xml"]'
+
+}
+
+files.each do |file, content|
+ file = File.join(base, file)
+ if File.exists?(file)
+ warn "[skip] '#{file}' already exists"
+ elsif File.exists?(file.downcase)
+ warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'"
+ else
+ unless File.exists?(File.dirname(file))
+ puts "[add] making directory '#{File.dirname(file)}'"
+ FileUtils.mkdir(File.dirname(file))
+ end
+ puts "[add] writing '#{file}'"
+ File.open(file, "w") { |f| f.write(content) }
+ end
+end
+
+puts "[done] Magento project capified with magentify!"
112 lib/mage.rb
@@ -0,0 +1,112 @@
+set :app_symlinks, ["/media", "/var", "/sitemaps", "/staging"]
+set :app_shared_dirs, ["/app/etc", "/sitemaps", "/media", "/var", "/staging"]
+set :app_shared_files, ["/app/etc/local.xml"]
+
+namespace :mage do
+ desc <<-DESC
+ Prepares one or more servers for deployment of Magento. Before you can use any \
+ of the Capistrano deployment tasks with your project, you will need to \
+ make sure all of your servers have been prepared with `cap deploy:setup'. When \
+ you add a new server to your cluster, you can easily run the setup task \
+ on just that server by specifying the HOSTS environment variable:
+
+ $ cap HOSTS=new.server.com mage:setup
+
+ It is safe to run this task on servers that have already been set up; it \
+ will not destroy any deployed revisions or data.
+ DESC
+ task :setup, :roles => :web, :except => { :no_release => true } do
+ if app_shared_dirs
+ app_shared_dirs.each { |link| run "#{try_sudo} mkdir -p #{shared_path}#{link} && chmod 777 #{shared_path}#{link}"}
+ end
+ if app_shared_files
+ app_shared_files.each { |link| run "#{try_sudo} touch #{shared_path}#{link} && chmod 777 #{shared_path}#{link}" }
+ end
+ end
+
+ desc <<-DESC
+ Touches up the released code. This is called by update_code \
+ after the basic deploy finishes.
+
+ Any directories deployed from the SCM are first removed and then replaced with \
+ symlinks to the same directories within the shared location.
+ DESC
+ task :finalize_update, :roles => :web, :except => { :no_release => true } do
+ run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
+
+ if app_symlinks
+ # Remove the contents of the shared directories if they were deployed from SCM
+ app_symlinks.each { |link| run "#{try_sudo} rm -rf #{latest_release}#{link}" }
+ # Add symlinks the directoris in the shared location
+ app_symlinks.each { |link| run "ln -nfs #{shared_path}#{link} #{latest_release}#{link}" }
+ end
+
+ if app_shared_files
+ # Remove the contents of the shared directories if they were deployed from SCM
+ app_shared_files.each { |link| run "#{try_sudo} rm -rf #{latest_release}/#{link}" }
+ # Add symlinks the directoris in the shared location
+ app_shared_files.each { |link| run "ln -s #{shared_path}#{link} #{latest_release}#{link}" }
+ end
+ # TODO should add configoration for this happening post deployment.
+ compiler
+ end
+
+ desc <<-DESC
+ Clear the Magento Cache
+ DESC
+ task :cc, :roles => :web do
+ run "cd #{current_path} && rm -rf var/cache/*"
+ end
+
+ desc <<-DESC
+ Disable the Magento install by creating the maintenance.flag in the web root.
+ DESC
+ task :disable, :roles => :web do
+ run "cd #{current_path} && touch maintenance.flag"
+ end
+
+ desc <<-DESC
+ Enable the Magento stores by removing the maintenance.flag in the web root.
+ DESC
+ task :enable, :roles => :web do
+ run "cd #{current_path} && rm -f maintenance.flag"
+ end
+
+ desc <<-DESC
+ Run the Magento compiler
+ DESC
+ task :compiler, :roles => :web do
+ run "cd #{current_path}/shell && php -f compiler.php -- compile"
+ end
+
+ desc <<-DESC
+ Enable the Magento compiler
+ DESC
+ task :enable_compiler, :roles => :web do
+ run "cd #{current_path}/shell && php -f compiler.php -- enable"
+ end
+
+ desc <<-DESC
+ Disable the Magento compiler
+ DESC
+ task :disable_compiler, :roles => :web do
+ run "cd #{current_path}/shell && php -f compiler.php -- disable"
+ end
+
+ desc <<-DESC
+ Run the Magento indexer
+ DESC
+ task :indexer, :roles => :app do
+ run "cd #{current_path}/shell && php -f indexer.php -- reindexall"
+ end
+
+ desc <<-DESC
+ Clean the Magento logs
+ DESC
+ task :clean_logs, :roles => :web do
+ run "cd #{current_path}/shell && php -f log.php -- clean"
+ end
+end
+
+after 'deploy:setup', 'mage:setup'
+after 'deploy:finalize_update', 'mage:finalize_update'
5 lib/magentify.rb
@@ -0,0 +1,5 @@
+require "magentify/version"
+
+module Magentify
+ # Your code goes here...
+end
3  lib/magentify/version.rb
@@ -0,0 +1,3 @@
+module Magentify
+ VERSION = "0.0.1"
+end
20 magentify.gemspec
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/magentify/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Alistair Stead"]
+ gem.email = ["alistair.stead@designdisclosure.com"]
+ gem.description = %q{TODO: Write a gem description}
+ gem.summary = %q{Deploying Magento PHP applications with Capistrano.}
+ gem.homepage = ""
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "magentify"
+ gem.require_paths = ["lib"]
+ gem.version = Magentify::VERSION
+
+ gem.add_dependency 'capistrano', ">= 2.5.10"
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.