blazing 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ *.swp
5
+ *.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in blazing.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,11 @@
1
+ == Yet another deployment utility
2
+
3
+ But why? Well, Capistrano was bloated for our use-cases, to much stuff bolted on. Inploy looked really interesting, but does not have multistage support from what I could tell. So I did what any reasonable developer would do and befell to the "Not Invented here syndrome".
4
+
5
+ Top Design goals, ideas:
6
+
7
+ - deploy is just a push to another remote. all that must be done is triggered by pre and post receveie git hooks.
8
+ - initial setup done by ruby script
9
+ - the stuff that gets executed is defined in recipes, which are handled kind of like chef recipes with vendor branches
10
+
11
+ Also, I just wanted to play around with instance_eval and such :-)
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/TODO ADDED
@@ -0,0 +1,11 @@
1
+ o deploy static site
2
+ o deploy static site with maintenance page
3
+ o deploy rails apps from SC
4
+
5
+ o customizable and modular
6
+ o multistage
7
+ o sync fs and db flavours
8
+
9
+ o recipes should live in git submodules
10
+
11
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'thor'
5
+ require 'blazing'
6
+ require 'blazing/cli'
7
+
8
+ Blazing::CLI.start
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "blazing/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "blazing"
7
+ s.version = Blazing::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Felipe Kaufmann"]
10
+ s.email = ["felipekaufmann@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{blazing fast deployment}
13
+ s.description = %q{git push style deployments for the masses}
14
+
15
+ s.rubyforge_project = "blazing"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "thor", ">= 0.14.6"
23
+ end
@@ -0,0 +1,5 @@
1
+ module Blazing
2
+ 'blazing/base'
3
+ 'blazing/cli'
4
+ 'blazing/version'
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'blazing/cli'
2
+ require 'blazing/config'
3
+
4
+ module Blazing::Base
5
+
6
+ end
@@ -0,0 +1,46 @@
1
+ require 'blazing/config'
2
+
3
+ class Blazing::CLI < Thor
4
+
5
+ # TODO: optional project directory
6
+ desc 'init', 'initialize blazing in project'
7
+ def init
8
+ username = ask "Deploy User: "
9
+ hostname = ask "Target hostname: "
10
+ path = ask "Deploy path on server: "
11
+ repository = ask "Enter is this projects repository: "
12
+ invoke 'blazing:config:create', [username, hostname, path, repository]
13
+ end
14
+
15
+
16
+ desc 'setup TARGET', 'bootstrap or update blazing setup on remote host and do a first deploy'
17
+ def setup(target = nil)
18
+
19
+ # Load config file
20
+ config = Blazing::Config.read do |blazing|
21
+ blazing.instance_eval(File.read blazing.file)
22
+ end
23
+
24
+ # Check if target can be found in config file
25
+ if target
26
+ target = config.targets.find { |t| t.name == target.to_sym }
27
+ end
28
+
29
+ target = target || config.determine_target
30
+
31
+ if target
32
+ say "[BLAZING] -- SETTING UP #{ target.location }", :yellow
33
+ invoke 'blazing:target:setup:setup_repository', [target]
34
+ else
35
+ say 'no target specified and no default found in config', :red
36
+ end
37
+
38
+ end
39
+
40
+ desc 'deploy TARGET', 'deploy project with blazing'
41
+ def deploy
42
+ # TODO: check if deployed setup is still uptodate, if not, run setup
43
+ # tag and push
44
+ end
45
+
46
+ end
@@ -0,0 +1,72 @@
1
+ require 'thor/group'
2
+ require 'blazing/target'
3
+
4
+ class Blazing::Config
5
+
6
+ attr_accessor :targets, :file
7
+
8
+ def initialize
9
+ @targets = []
10
+ @file = File.open('deploy/blazing.rb')
11
+ end
12
+
13
+ def self.read(&block)
14
+ config = Blazing::Config.new
15
+ block.arity < 1 ? config.instance_eval(&block) : block.call(config)
16
+ return config
17
+ end
18
+
19
+ def target(name, &block)
20
+ @targets << Blazing::Target.new(name, @repository, &block)
21
+ end
22
+
23
+ def repository(url)
24
+ @repository = url
25
+ end
26
+
27
+ def determine_target
28
+ target = case
29
+ when self.targets.size == 1 && !self.targets.first.location.nil?
30
+ self.targets.first
31
+
32
+ when !self.default.default_target.nil?
33
+ self.targets.find { |t| t.name == self.default.default_target }
34
+
35
+ when self.default && !self.default.hostname.nil?
36
+ self.default
37
+ end
38
+
39
+ return target
40
+ end
41
+
42
+ def default
43
+ self.targets.find { |t| t.name == :blazing}
44
+ end
45
+
46
+ # TODO: Why does thor break when this is put into an external file config folder?
47
+ class Create < Thor::Group
48
+
49
+ desc 'creates a blazing config file'
50
+
51
+ include Thor::Actions
52
+
53
+ argument :username
54
+ argument :hostname
55
+ argument :path
56
+ argument :repository
57
+
58
+ def self.source_root
59
+ File.dirname(__FILE__)
60
+ end
61
+
62
+ def create_blazing_dir
63
+ empty_directory 'deploy'
64
+ end
65
+
66
+ def create_config_file
67
+ template('templates/blazing.tt', "deploy/blazing.rb")
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,8 @@
1
+ #
2
+ # Stuff that runs on remote machine
3
+ #
4
+ class Blazing::Remote < Thor
5
+
6
+
7
+
8
+ end
@@ -0,0 +1,87 @@
1
+ class Blazing::Target
2
+
3
+ attr_accessor :name, :user, :hostname, :path, :recipes, :target_name, :default_target, :repository
4
+
5
+ def initialize(name, repository, &block)
6
+ @name = name
7
+ @repository = repository
8
+ instance_eval &block
9
+ end
10
+
11
+ def deploy_to(location)
12
+ @user = location.match('(.*)@')[1]
13
+ @hostname = location.match('@(.*):')[1]
14
+ @path = location.match(':(.*)')[1]
15
+ end
16
+
17
+ def location
18
+ # TODO: build this together more carefully, checking for emtpy hostname etc...
19
+ @location ||= "#{ @user }@#{ @hostname }:#{ @path }"
20
+ end
21
+
22
+ # Only used in global target for setting default target
23
+ # TODO: extract into other class, inherit
24
+ def set_default_target(target_name)
25
+ @default_target = target_name
26
+ end
27
+
28
+ class Setup < Thor
29
+
30
+ include Thor::Actions
31
+
32
+ def self.source_root
33
+ File.dirname(__FILE__)
34
+ end
35
+
36
+ argument :target
37
+
38
+ desc 'setup:setup_repository TARGET', 'sets up a target for blazing deployments'
39
+ def setup_repository
40
+
41
+ # TODO: Extract into helper
42
+ # remote_with_condition()
43
+
44
+ command = "if [ -e ~/sites/blazingoverride.ch/ ]; then echo 'repository has been cloned already'; else git clone #{ target.repository } #{ target.path }; fi"
45
+ system "ssh #{ target.user }@#{ target.hostname } '#{ command }'"
46
+ if $? == 0
47
+ say '--> [ok]', :green
48
+ invoke 'add_pre_receive_hook', target
49
+ else
50
+ say '--> [FAILED]', :red
51
+ say '[BLAZING] -- ROLLING BACK', :blue
52
+ return
53
+ end
54
+ end
55
+
56
+ desc 'setup:clone_repository TARGET', 'sets up a target for blazing deployments'
57
+
58
+ def add_pre_receive_hook
59
+ say 'adding pre-receive hook'
60
+ pre_hook = "deploy/pre-receive"
61
+ template('templates/pre-hook.tt', pre_hook)
62
+ system "chmod +x #{ pre_hook }"
63
+ system "scp #{ pre_hook } #{ target.user }@#{ target.hostname }:#{ target.path }/.git/hooks/"
64
+ say '--> [ok]', :green
65
+ invoke 'add_post_receive_hook', target
66
+ end
67
+
68
+ desc 'setup:clone_repository TARGET', 'sets up a target for blazing deployments'
69
+ def add_post_receive_hook
70
+ say 'adding post-receive hook'
71
+ post_hook = "deploy/post-receive"
72
+ template('templates/post-hook.tt', post_hook)
73
+ system "chmod +x #{ post_hook }"
74
+ system "scp #{ post_hook } #{ target.user }@#{ target.hostname }:#{ target.path }/.git/hooks/"
75
+ say '--> [ok]', :green
76
+ invoke 'add_remote', target
77
+ end
78
+
79
+ desc 'setup:add_remote TARGET', 'adds a git remote for the given target'
80
+ def add_remote
81
+ say 'adding target as remote to repository'
82
+ system "git remote add #{ target.name } #{ target.user }@#{ target.hostname }:#{ target.path }"
83
+ end
84
+
85
+ end
86
+
87
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # blazing config file -- generated on <%= Time.now %>
3
+ #
4
+
5
+ blazing.repository '<%= repository %>'
6
+
7
+ blazing.target :global do
8
+
9
+ # recipes [:rvm, :bundler, :maintenance_page]
10
+ deploy_to '<%= username %>@<%= hostname %>:<%= path %>'
11
+
12
+ # default_target :somethingelsethandefault
13
+ # sync dirs
14
+
15
+ end
16
+
17
+ # Above sample setup is for deploying on a single host. Below is how a multi stage/multi host setup might look like
18
+ # target specific configuration, overrides global configuration
19
+ # target :sometarget do
20
+ # ...
21
+ #
22
+ # end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'blazing'
5
+
6
+ Blazing::Remote.post_receive(<%= target.name %>)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'blazing'
5
+
6
+ Blazing::Remote.pre_receive(<%= target.name %>)
@@ -0,0 +1,3 @@
1
+ module Blazing
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blazing
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Felipe Kaufmann
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-10 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thor
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 14
31
+ - 6
32
+ version: 0.14.6
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: git push style deployments for the masses
36
+ email:
37
+ - felipekaufmann@gmail.com
38
+ executables:
39
+ - blazing
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - README
48
+ - Rakefile
49
+ - TODO
50
+ - bin/blazing
51
+ - blazing.gemspec
52
+ - lib/blazing.rb
53
+ - lib/blazing/base.rb
54
+ - lib/blazing/cli.rb
55
+ - lib/blazing/config.rb
56
+ - lib/blazing/remote.rb
57
+ - lib/blazing/target.rb
58
+ - lib/blazing/templates/blazing.tt
59
+ - lib/blazing/templates/post-hook.tt
60
+ - lib/blazing/templates/pre-hook.tt
61
+ - lib/blazing/version.rb
62
+ has_rdoc: true
63
+ homepage: ""
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project: blazing
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: blazing fast deployment
94
+ test_files: []
95
+