popo 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +5 -0
- data/README +1 -0
- data/Rakefile +1 -0
- data/bin/envy +16 -0
- data/bin/popo +6 -0
- data/config/envy.yml.sample +4 -0
- data/config/popo_config.yml.sample +15 -0
- data/lib/hash.rb +23 -0
- data/lib/popo.rb +18 -0
- data/lib/popo/constants.rb +9 -0
- data/lib/popo/database.rb +23 -0
- data/lib/popo/git_utils.rb +60 -0
- data/lib/popo/initializer.rb +60 -0
- data/lib/popo/runner.rb +139 -0
- data/lib/popo/rvm.rb +59 -0
- data/lib/popo/sync.rb +67 -0
- data/lib/popo/utils.rb +46 -0
- data/lib/templates/envy.yml +4 -0
- data/popo.gemspec +27 -0
- data/script/Rakefile +60 -0
- data/script/envy +24 -0
- data/script/envyrc +45 -0
- data/script/poporc +61 -0
- data/targets/beta.rb +1 -0
- data/targets/common.rb +1 -0
- data/targets/development.rb +1 -0
- data/targets/production.rb +1 -0
- data/targets/staging.rb +1 -0
- data/targets/test.rb +1 -0
- metadata +133 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
popo rails repo tool
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/envy
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
5
|
+
BASH_PATH = `which bash`.strip
|
6
|
+
ENV_PATH = `which env`.strip
|
7
|
+
POPO_PATH = ENV['popo_path'] if ENV.include?('popo_path')
|
8
|
+
POPO_TARGET = ENV['popo_target'] if ENV.include?('popo_target')
|
9
|
+
POPO_WORK_PATH = '.manifest'
|
10
|
+
ENVYRC = File.join(POPO_PATH, POPO_WORK_PATH, 'script/envyrc')
|
11
|
+
|
12
|
+
cmd = ARGV.join(' ')
|
13
|
+
|
14
|
+
finale = "#{ENV_PATH} popo_path=#{POPO_PATH} popo_target=#{POPO_TARGET} #{BASH_PATH} -c 'source #{ENVYRC}; cd #{POPO_PATH}; #{cmd}'"
|
15
|
+
system(finale)
|
16
|
+
|
data/bin/popo
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
repo:
|
2
|
+
popo: jan@localhost:/opt/popo.git
|
3
|
+
rvm: jan@git.caresharing:popo/rvm.git
|
4
|
+
tools: jan@git.caresharing:popo/tools.git
|
5
|
+
manifest:
|
6
|
+
source: https://popo.caresharing.eu
|
7
|
+
rvm:
|
8
|
+
rubies: [ree-1.8.7-2010.01, ruby-1.9.2]
|
9
|
+
default: ree-1.8.7-2010.01
|
10
|
+
popo:
|
11
|
+
tree: [ 'apps', 'assets', 'frameworks', 'plugins', 'helpers', 'external', 'configs', 'out/logs', 'out/tmp/pids', 'out/tmp/caches', 'libwww']
|
12
|
+
default_target: development
|
13
|
+
gems:
|
14
|
+
source: http://gems.caresharing.eu
|
15
|
+
|
data/lib/hash.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Hash
|
2
|
+
def deep_merge(hash)
|
3
|
+
target = dup
|
4
|
+
hash.keys.each do |key|
|
5
|
+
if hash[key].is_a? Hash and self[key].is_a? Hash
|
6
|
+
target[key] = target[key].deep_merge(hash[key])
|
7
|
+
next
|
8
|
+
end
|
9
|
+
target[key] = hash[key]
|
10
|
+
end
|
11
|
+
target
|
12
|
+
end
|
13
|
+
|
14
|
+
def deep_merge!(second)
|
15
|
+
second.each_pair do |k,v|
|
16
|
+
if self[k].is_a?(Hash) and second[k].is_a?(Hash)
|
17
|
+
self[k].deep_merge!(second[k])
|
18
|
+
else
|
19
|
+
self[k] = second[k]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/popo.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'palmade/cableguy'
|
3
|
+
require 'optparse'
|
4
|
+
require 'yaml'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
module Popo
|
8
|
+
POPO_LIB_ROOT = File.join(File.dirname(__FILE__), 'popo')
|
9
|
+
|
10
|
+
autoload :Constants, (File.join(POPO_LIB_ROOT, 'constants'))
|
11
|
+
autoload :Database, (File.join(POPO_LIB_ROOT, 'database'))
|
12
|
+
autoload :GitUtils, (File.join(POPO_LIB_ROOT, 'git_utils'))
|
13
|
+
autoload :Initializer, (File.join(POPO_LIB_ROOT, 'initializer'))
|
14
|
+
autoload :Runner, (File.join(POPO_LIB_ROOT, 'runner'))
|
15
|
+
autoload :RVM, (File.join(POPO_LIB_ROOT, 'rvm'))
|
16
|
+
autoload :Sync, (File.join(POPO_LIB_ROOT, 'sync'))
|
17
|
+
autoload :Utils, (File.join(POPO_LIB_ROOT, 'utils'))
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Popo
|
2
|
+
class Database
|
3
|
+
def initialize(app_root, options)
|
4
|
+
@cabler = Palmade::Cableguy::Cabler.new(app_root, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def boot_database
|
8
|
+
@cabler.boot
|
9
|
+
end
|
10
|
+
|
11
|
+
def migrate_database
|
12
|
+
@cabler.migrate
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(key, group = 'manifest')
|
16
|
+
@cabler.db.get(key, group)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_children(key, group = 'manifest')
|
20
|
+
@cabler.db.get_children(key, group)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Popo
|
2
|
+
module GitUtils
|
3
|
+
include Constants
|
4
|
+
|
5
|
+
def self.git_clone(repo, clone_path, branch)
|
6
|
+
clone_path ||= nil
|
7
|
+
branch = 'master' if branch.nil?
|
8
|
+
|
9
|
+
if clone_path.nil?
|
10
|
+
cmd = "#{GIT_CMD} clone -b #{branch} #{repo}"
|
11
|
+
else
|
12
|
+
cmd = "#{GIT_CMD} clone -b #{branch} #{repo} #{clone_path}"
|
13
|
+
end
|
14
|
+
|
15
|
+
clone_msg = "Cloning branch #{branch} from #{repo}" +
|
16
|
+
" to #{clone_path}"
|
17
|
+
|
18
|
+
Utils.say_with_time clone_msg do
|
19
|
+
`#{cmd}`
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.git_update(repo, branch)
|
24
|
+
Utils.say_with_time "Updating #{repo}" do
|
25
|
+
Dir.chdir(repo) do
|
26
|
+
`#{GIT_CMD} fetch`
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
git_stash(repo)
|
31
|
+
git_checkout(repo, branch)
|
32
|
+
git_reset(repo, branch)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.git_stash(repo)
|
36
|
+
Utils.say_with_time "Stashing changes for #{repo}" do
|
37
|
+
Dir.chdir(repo) do
|
38
|
+
`#{GIT_CMD} stash`
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.git_reset(repo, branch)
|
44
|
+
Utils.say_with_time "Doing a hard reset for #{repo}" do
|
45
|
+
Dir.chdir(repo) do
|
46
|
+
`#{GIT_CMD} reset --hard origin/#{branch}`
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.git_checkout(repo, branch)
|
52
|
+
Utils.say_with_time "Switching to #{branch} branch" do
|
53
|
+
Dir.chdir(repo) do
|
54
|
+
`#{GIT_CMD} checkout #{branch}`
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Popo
|
2
|
+
class Initializer
|
3
|
+
include Constants
|
4
|
+
|
5
|
+
def self.boot(config, options)
|
6
|
+
self.new(config, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(config, options)
|
10
|
+
@repos = {}
|
11
|
+
|
12
|
+
config['repos'].each do |k, v|
|
13
|
+
@repos[k] = v
|
14
|
+
end
|
15
|
+
|
16
|
+
@options = options
|
17
|
+
@default_target = @options[:target] || 'development'
|
18
|
+
@deploy_path = File.absolute_path(@options[:path])
|
19
|
+
@location = @options[:location] || nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def print_variables
|
23
|
+
instance_variables.each do |i|
|
24
|
+
say instance_variable_get(i)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup
|
29
|
+
print_variables if @options[:verbose]
|
30
|
+
|
31
|
+
@repos.each do |k, v|
|
32
|
+
basename = File.basename(v['git'])
|
33
|
+
|
34
|
+
if k == POPO_WORK_PATH.delete('.')
|
35
|
+
clone_path = File.join(@deploy_path, POPO_WORK_PATH)
|
36
|
+
else
|
37
|
+
clone_path = File.join(@deploy_path, basename)
|
38
|
+
end
|
39
|
+
|
40
|
+
GitUtils.git_clone(v['git'], clone_path, v['branch'])
|
41
|
+
end
|
42
|
+
|
43
|
+
write_config
|
44
|
+
end
|
45
|
+
|
46
|
+
def write_config
|
47
|
+
popo = {}
|
48
|
+
popo['target'] = @default_target
|
49
|
+
popo['path'] = @deploy_path
|
50
|
+
popo['location'] = @location if !@location.nil?
|
51
|
+
|
52
|
+
yml_path = File.join(@deploy_path, POPO_WORK_PATH, POPO_YML_FILE)
|
53
|
+
|
54
|
+
File.open(yml_path, "w") do |f|
|
55
|
+
YAML.dump(popo, f)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/lib/popo/runner.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
module Popo
|
2
|
+
class Runner
|
3
|
+
include Constants
|
4
|
+
|
5
|
+
def self.boot(args)
|
6
|
+
Popo::Constants.const_set("BASH_CMD", `which bash`.strip)
|
7
|
+
Popo::Constants.const_set("ENV_CMD", `which env`.strip)
|
8
|
+
Popo::Constants.const_set("GIT_CMD", `which git`.strip)
|
9
|
+
|
10
|
+
self.new(args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(args)
|
14
|
+
@popo_path = ENV['popo_path'] || Dir.pwd
|
15
|
+
@options = {}
|
16
|
+
@cabler_options = {}
|
17
|
+
@options[:verbose] = false
|
18
|
+
|
19
|
+
optparse = OptionParser.new do |opts|
|
20
|
+
opts.banner = "Popo tool."
|
21
|
+
opts.separator "Options:"
|
22
|
+
|
23
|
+
opts.on('-p', '--path PATH', 'Target path') do |path|
|
24
|
+
@options[:path] = path
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on('-t', '--target TARGET', 'Deployment target') do |target|
|
28
|
+
@options[:target] = target
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('-u', '--user USER', 'Username') do |user|
|
32
|
+
@options[:user] = user
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on('-l', '--location LOCATION', 'Location') do |location|
|
36
|
+
@options[:location] = location
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('-v', '--verbose', 'Verbose') do
|
40
|
+
@options[:verbose] = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('-h', '--help', 'Display this screen') do
|
44
|
+
puts opts
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
optparse.parse!
|
50
|
+
|
51
|
+
if args.length == 0
|
52
|
+
Utils.say optparse.help
|
53
|
+
else
|
54
|
+
@cabler_options = { :path => File.join(@popo_path, POPO_WORK_PATH),
|
55
|
+
:target => ENV['CABLING_TARGET'],
|
56
|
+
:location => ENV['CABLING_LOCATION'],
|
57
|
+
:verbose => @options[:verbose] }
|
58
|
+
|
59
|
+
run(args)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def run(args)
|
64
|
+
case args.shift
|
65
|
+
when 'init'
|
66
|
+
if !@options[:path].nil?
|
67
|
+
if !File.exist?(File.join(@popo_path, @options[:path]))
|
68
|
+
Initializer.boot(get_config!, @options).setup
|
69
|
+
else
|
70
|
+
raise "Path already exists!"
|
71
|
+
end
|
72
|
+
else
|
73
|
+
raise "Supply a path with the -p option!"
|
74
|
+
end
|
75
|
+
when 'sync'
|
76
|
+
if Utils.in_popo?(@popo_path)
|
77
|
+
db = Database.new(@popo_path, @cabler_options)
|
78
|
+
db.boot_database
|
79
|
+
|
80
|
+
Sync.new(@popo_path, args, db).gather
|
81
|
+
end
|
82
|
+
when 'rvminstall'
|
83
|
+
if Utils.in_popo?(@popo_path)
|
84
|
+
print "Install all rubies?(y/N): "
|
85
|
+
|
86
|
+
ok = $stdin.gets.chomp!
|
87
|
+
if ok == 'y'
|
88
|
+
db = Database.new(@popo_path, @cabler_options)
|
89
|
+
db.boot_database
|
90
|
+
RVM.new(@popo_path, args, db).setup
|
91
|
+
else
|
92
|
+
Utils.say "y/N only!"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
when 'migrate'
|
96
|
+
if Utils.in_popo?(@popo_path)
|
97
|
+
db = Database.new(@popo_path, @cabler_options)
|
98
|
+
db.boot_database
|
99
|
+
db.migrate_database
|
100
|
+
end
|
101
|
+
when 'status'
|
102
|
+
Utils.say `cat #{File.join(@popo_path, POPO_WORK_PATH, POPO_YML_FILE)}`
|
103
|
+
when 'upload'
|
104
|
+
puts "Pushing!"
|
105
|
+
when 'bash'
|
106
|
+
bash!
|
107
|
+
else
|
108
|
+
puts "I don't know what to do."
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def bash!
|
113
|
+
Utils.require_relative_work_popo(Dir.pwd)
|
114
|
+
|
115
|
+
poporc_path = File.join(Dir.pwd, POPO_WORK_PATH, POPORC)
|
116
|
+
target = POPO_CONFIG['target']
|
117
|
+
path = POPO_CONFIG['path']
|
118
|
+
location = POPO_CONFIG['location']
|
119
|
+
|
120
|
+
bashcmd = "%s popo_target=%s popo_path=%s \
|
121
|
+
popo_location=%s %s --rcfile %s" \
|
122
|
+
% [ENV_CMD, target, path, location, BASH_CMD, poporc_path]
|
123
|
+
|
124
|
+
exec(bashcmd)
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_config!
|
128
|
+
if File.exist?(File.join(ENV['HOME'], ".#{DEFAULT_CONFIG_FILE}"))
|
129
|
+
config_file_path = File.join(ENV['HOME'], ".#{DEFAULT_CONFIG_FILE}")
|
130
|
+
elsif File.exist?(File.join('/etc', DEFAULT_CONFIG_FILE))
|
131
|
+
config_file_path = "/etc/#{DEFAULT_CONFIG_FILE}"
|
132
|
+
else
|
133
|
+
raise "No popo_config.yml found in #{ENV['HOME']} or /etc"
|
134
|
+
end
|
135
|
+
|
136
|
+
config_hash = YAML.load_file(config_file_path)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/popo/rvm.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Popo
|
2
|
+
class RVM
|
3
|
+
def initialize(app_root, args, db)
|
4
|
+
@db = db
|
5
|
+
@app_root = app_root
|
6
|
+
@rvm_bin = File.join(@app_root, 'rvm/bin/rvm')
|
7
|
+
@repos = args
|
8
|
+
|
9
|
+
@rubies = @db.get("rvm.rubies").split(",")
|
10
|
+
@default_ruby = @db.get("rvm.ruby.default")
|
11
|
+
@default_gems = @db.get("rvm.gems.default").split(",")
|
12
|
+
@gem_source = @db.get("rvm.gems.source")
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
Utils.say "Rubies to be installed #{@rubies}...\n\n"
|
17
|
+
|
18
|
+
@rubies.each do |r|
|
19
|
+
patch = File.join(@app_root, 'rvm', "#{r}.patch")
|
20
|
+
|
21
|
+
if File.exists?(patch)
|
22
|
+
Utils.say("Patch for #{r} is found at #{patch}")
|
23
|
+
cmd = "#{@rvm_bin} install #{r} --patch #{patch} --force"
|
24
|
+
else
|
25
|
+
cmd = "#{@rvm_bin} install #{r} --force"
|
26
|
+
end
|
27
|
+
|
28
|
+
system(cmd)
|
29
|
+
end
|
30
|
+
|
31
|
+
Utils.say_with_time "Setting #{@default_ruby} as default ruby..." do
|
32
|
+
`#{@rvm_bin} --default #{@default_ruby}`
|
33
|
+
end
|
34
|
+
|
35
|
+
Utils.say(POST_INSTALL_NOTE)
|
36
|
+
|
37
|
+
# Utils.say_with_time "Reloading rvm..." do
|
38
|
+
# `#{@rvm_bin} reload`
|
39
|
+
# end
|
40
|
+
|
41
|
+
# @default_gems.each do |g|
|
42
|
+
# Utils.say_with_time "Installing gem #{g}" do
|
43
|
+
# `gem install #{g} --source #{@gem_source}`
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
POST_INSTALL_NOTE = <<NOTE
|
50
|
+
You're almost done!\n\n
|
51
|
+
Do the following inside popo:\n
|
52
|
+
1. rvm reload\n
|
53
|
+
2. gem install cableguy popo dbget_client --source http://gems.caresharing.eu --no-ri --no-rdoc\n\n
|
54
|
+
OPTIONAL: (If you use another ruby version). In this example, ree.\n
|
55
|
+
1. rvm use ree-1.8.7-2011.03\n
|
56
|
+
2. gem install cableguy popo dbget_client --source http://gems.caresharing.eu --no-ri --no-rdoc\n
|
57
|
+
NOTE
|
58
|
+
|
59
|
+
end
|
data/lib/popo/sync.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Popo
|
2
|
+
class Sync
|
3
|
+
def initialize(app_root, args, db)
|
4
|
+
@db = db
|
5
|
+
@current_dir = File.basename(Dir.pwd)
|
6
|
+
@app_root = app_root
|
7
|
+
@cwd = Dir.pwd
|
8
|
+
@repos = args
|
9
|
+
@info = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def gather
|
13
|
+
@repos.each do |repo|
|
14
|
+
if repo =~ /\//
|
15
|
+
r = repo.split('/')
|
16
|
+
@info[:parent], @info[:name] = r
|
17
|
+
@info[:key] = [@info[:parent], @info[:name]].join('.')
|
18
|
+
@info[:path] = File.join(@app_root, @info[:parent], @info[:name])
|
19
|
+
|
20
|
+
get_repo_values(@info[:key])
|
21
|
+
|
22
|
+
clone_or_update
|
23
|
+
else
|
24
|
+
gather_many(repo)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if @repos.empty?
|
29
|
+
if @cwd.eql? @app_root
|
30
|
+
popo_folders = @db.get("popo_folders").split(',')
|
31
|
+
popo_folders.each { |p| gather_many(p) }
|
32
|
+
else
|
33
|
+
repo = File.basename(@cwd)
|
34
|
+
gather_many(repo)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def gather_many(repo)
|
40
|
+
children = @db.get_children(repo)
|
41
|
+
|
42
|
+
raise "No values for parent key \'#{repo}\'." if children.empty?
|
43
|
+
|
44
|
+
children.each do |c|
|
45
|
+
@info[:key] = [repo, c].join('.')
|
46
|
+
get_repo_values(@info[:key])
|
47
|
+
@info[:path] = File.join(@app_root, repo, c)
|
48
|
+
|
49
|
+
clone_or_update
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def clone_or_update
|
54
|
+
if !File.exists?(@info[:path])
|
55
|
+
GitUtils.git_clone(@info[:host], @info[:path], @info[:branch])
|
56
|
+
else
|
57
|
+
GitUtils.git_update(@info[:path], @info[:branch])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def get_repo_values(key)
|
63
|
+
@info[:branch] = @db.get("#{key}.branch")
|
64
|
+
@info[:host] = @db.get("#{key}.repo")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/popo/utils.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
module Popo
|
4
|
+
module Utils
|
5
|
+
include Constants
|
6
|
+
|
7
|
+
def self.say(message, subitem = false)
|
8
|
+
puts "#{subitem ? " ->" : "--"} #{message}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.say_with_time(message)
|
12
|
+
say(message)
|
13
|
+
result = nil
|
14
|
+
time = Benchmark.measure { result = yield }
|
15
|
+
say "%.4fs" % time.real, :subitem
|
16
|
+
say("#{result} rows", :subitem) if result.is_a?(Integer)
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.in_popo?(root_path)
|
21
|
+
if !ENV.include?('popo_path')
|
22
|
+
raise "You must be inside popo!"
|
23
|
+
end
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.require_relative_work_popo(root_path)
|
28
|
+
popo_work_path = File.expand_path(File.join(root_path, POPO_WORK_PATH))
|
29
|
+
|
30
|
+
popo_yml = File.expand_path(File.join(popo_work_path, POPO_YML_FILE))
|
31
|
+
|
32
|
+
if File.exists?(popo_yml)
|
33
|
+
popo_config = YAML.load_file(popo_yml)
|
34
|
+
|
35
|
+
if popo_config.is_a?(Hash)
|
36
|
+
POPO_CONFIG.update(popo_config)
|
37
|
+
else
|
38
|
+
raise "#{POPO_WORK_PATH}/#{POPO_YML_FILE} seems to be wrong."
|
39
|
+
end
|
40
|
+
else
|
41
|
+
raise "#{POPO_YML_FILE} not found."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/popo.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
VERSION = "0.1.1"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "popo"
|
7
|
+
s.version = VERSION
|
8
|
+
s.authors = ["Jan Mendoza"]
|
9
|
+
s.email = ["poymode@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Popo ruby and rails repo tool}
|
12
|
+
s.description = %q{Ruby and rails repo tool}
|
13
|
+
|
14
|
+
s.rubyforge_project = "popo"
|
15
|
+
s.add_dependency "sequel"
|
16
|
+
s.add_dependency "sqlite3"
|
17
|
+
s.add_dependency "cableguy"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
# specify any dependencies here; for example:
|
25
|
+
# s.add_development_dependency "rspec"
|
26
|
+
# s.add_runtime_dependency "rest-client"
|
27
|
+
end
|
data/script/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
POPO_VERSION = 1.2
|
2
|
+
POPO_PACKAGE_VERSION = 1
|
3
|
+
POPO_PACKAGE_NAME = "popo-#{POPO_VERSION}-#{POPO_PACKAGE_VERSION}_all"
|
4
|
+
|
5
|
+
def control_file
|
6
|
+
"Package: popo\n" +
|
7
|
+
"Version: #{POPO_VERSION}-#{POPO_PACKAGE_VERSION}\n" +
|
8
|
+
"Section: Caresharing Tools\n" +
|
9
|
+
"Priority: optional\n" +
|
10
|
+
"Architecture: all\n" +
|
11
|
+
"Depends: ruby, git-core, curl, g++\n" +
|
12
|
+
"Maintainer: Caresharing Framework Team <framework@caresharing.eu>\n" +
|
13
|
+
"Description: Popo utilities\n" +
|
14
|
+
" Popo allows you to easily deploy and configure Caresharing applications"
|
15
|
+
end
|
16
|
+
|
17
|
+
def popo_puts(message)
|
18
|
+
puts "\e[33m#{message}\e[0;0m"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Creates a debian package of popo"
|
22
|
+
task :deb do
|
23
|
+
popo_puts "Packaging popo version #{POPO_VERSION} as deb..."
|
24
|
+
|
25
|
+
system "mkdir -p #{POPO_PACKAGE_NAME}/usr/local/bin"
|
26
|
+
system "cp popo #{POPO_PACKAGE_NAME}/usr/local/bin"
|
27
|
+
system "cp -r ../../popo /tmp/.popo"
|
28
|
+
system "mv /tmp/.popo #{POPO_PACKAGE_NAME}/usr/local/bin"
|
29
|
+
|
30
|
+
# system "mkdir -p #{POPO_PACKAGE_NAME}/etc"
|
31
|
+
# system "cp popo_config.yml #{POPO_PACKAGE_NAME}/etc"
|
32
|
+
|
33
|
+
system "mkdir -p #{POPO_PACKAGE_NAME}/DEBIAN"
|
34
|
+
system "echo \"#{control_file}\" > #{POPO_PACKAGE_NAME}/DEBIAN/control"
|
35
|
+
|
36
|
+
system "dpkg-deb -b #{POPO_PACKAGE_NAME}"
|
37
|
+
system "rm -rf #{POPO_PACKAGE_NAME}"
|
38
|
+
|
39
|
+
popo_puts "Done!"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Deploys debian package to remote deb repository"
|
43
|
+
task :deploy do
|
44
|
+
popo_puts "Copying deb package to remote server..."
|
45
|
+
system "scp #{POPO_PACKAGE_NAME}.deb root@styx.caresharing:/var/www/caresharing/"
|
46
|
+
popo_puts "Done!"
|
47
|
+
|
48
|
+
popo_puts "Generating index on deb repo..."
|
49
|
+
system "ssh root@styx.caresharing \"cd /var/www/caresharing; ./generate_index\""
|
50
|
+
popo_puts "Done!"
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Cleans up the working directory"
|
54
|
+
task :clean do
|
55
|
+
popo_puts "Cleaning up... "
|
56
|
+
system "rm #{POPO_PACKAGE_NAME}.deb"
|
57
|
+
popo_puts "Done!"
|
58
|
+
end
|
59
|
+
|
60
|
+
task :default => "deb"
|
data/script/envy
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
5
|
+
BASH_PATH = `which bash`.strip
|
6
|
+
ENV_PATH = `which env`.strip
|
7
|
+
|
8
|
+
env_config_file = File.join(ROOT_PATH, 'config/envy.yml')
|
9
|
+
|
10
|
+
if File.exists? env_config_file
|
11
|
+
env_conf = YAML.load_file(env_config_file)
|
12
|
+
popo_path = env_conf['popo_path']
|
13
|
+
popo_target = env_conf['popo_target']
|
14
|
+
envyrc = "#{ROOT_PATH}/#{env_conf['envyrc_path']}"
|
15
|
+
else
|
16
|
+
puts "envyrc file not found. Byebye!"
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
cmd = ARGV.join(' ')
|
21
|
+
|
22
|
+
finale = "#{ENV_PATH} popo_path=#{popo_path} popo_target=#{popo_target} #{BASH_PATH} -c 'source #{envyrc}; cd #{popo_path}; #{cmd}'"
|
23
|
+
system(finale)
|
24
|
+
exit $?.exitstatus
|
data/script/envyrc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# Let's unload system installed rvm and move path prefix to popo
|
4
|
+
unset $(env | awk -F= '/^rvm_/{print $1" "}')
|
5
|
+
export rvm_reload_flag=1
|
6
|
+
export rvm_prefix=$popo_path
|
7
|
+
|
8
|
+
|
9
|
+
# Now let's load rvm inside popo
|
10
|
+
source $rvm_prefix/rvm/scripts/rvm
|
11
|
+
|
12
|
+
# Load default rvm
|
13
|
+
rvm default 1>/dev/null 2>&1
|
14
|
+
unset PALMADE_GEMS_DIR
|
15
|
+
export PATH="$popo_path/rvm/bin:$popo_path/tools:$PATH"
|
16
|
+
export CABLING_PATH=$popo_path/.popo/cabling.yml
|
17
|
+
export CABLING_TARGET=$popo_target
|
18
|
+
|
19
|
+
# this section is for backup
|
20
|
+
#unset PALMADE_GEMS_DIR
|
21
|
+
#unset rvm_loaded_flag
|
22
|
+
#rvm_loaded_flag=1
|
23
|
+
#export PATH="$popo_path/rvm/bin:$popo_path/tools:$PATH"
|
24
|
+
#export rvm_prefix=$popo_path
|
25
|
+
#export rvm_path=$popo_path/rvm
|
26
|
+
#export rvm_scripts_path=$rvm_path/scripts
|
27
|
+
#export rvm_archives_path=$rvm_path/archives
|
28
|
+
#export rvm_src_path=$rvm_path/src
|
29
|
+
#export rvm_log_path=$rvm_path/log
|
30
|
+
#export rvm_bin_path=$rvm_path/bin
|
31
|
+
#export rvm_gems_path=$rvm_path/gems
|
32
|
+
#export rvm_hooks_path=$rvm_path/hooks
|
33
|
+
#export rvm_tmp_path=$rvm_path/tmp
|
34
|
+
#export rvm_gemsets_path=$rvm_path/gemsets
|
35
|
+
#export rvm_bin_path=$rvm_path/bin
|
36
|
+
#export rvm_patchsets_path=$rvm_path/patchsets
|
37
|
+
#export rvm_patches_path=$rvm_path/patches
|
38
|
+
#export rvm_gems_cache_path=$rvm_path/gems/cache
|
39
|
+
#export rvm_config_path=$rvm_path/config
|
40
|
+
#export rvm_rubies_path=$rvm_path/rubies
|
41
|
+
#export rvm_gems_path=$rvm_path/gems
|
42
|
+
#export rvm_repo_path=$rvm_path/repos
|
43
|
+
#unset rvm_loaded_flag
|
44
|
+
#source $rvm_scripts_path/rvm
|
45
|
+
#rvm default 1>/dev/null 2>&1
|
data/script/poporc
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
if [[ -z "$popo_path" ]] ; then
|
4
|
+
echo "FAIL Please set the popo_path environment var"
|
5
|
+
exit -1
|
6
|
+
fi
|
7
|
+
|
8
|
+
if [[ -z "$popo_target" ]] ; then
|
9
|
+
echo "FAIL Please set the popo_target environment var"
|
10
|
+
exit -1
|
11
|
+
fi
|
12
|
+
|
13
|
+
SHIT="\[\033[33m\]"
|
14
|
+
NORMAL="\[\033[0;0m\]"
|
15
|
+
BASEPATH=`which basename`
|
16
|
+
BASENAME=`$BASEPATH $popo_path`
|
17
|
+
|
18
|
+
if [[ $PS1 != "" ]] ; then
|
19
|
+
if [[ -f /etc/bash.bashrc ]] ; then
|
20
|
+
source /etc/bash.bashrc
|
21
|
+
fi
|
22
|
+
|
23
|
+
if [[ -f $HOME/.bashrc ]] ; then
|
24
|
+
source $HOME/.bashrc
|
25
|
+
fi
|
26
|
+
|
27
|
+
if [[ $BASENAME != $popo_target ]] ; then
|
28
|
+
export PS1="$SHIT(popo $popo_target/$BASENAME) $NORMAL$PS1"
|
29
|
+
else
|
30
|
+
export PS1="$SHIT(popo $popo_target) $NORMAL$PS1"
|
31
|
+
fi
|
32
|
+
fi
|
33
|
+
|
34
|
+
# Let's unload system installed rvm and move path prefix to popo
|
35
|
+
unset $(env | awk -F= '/^rvm_/{print $1" "}')
|
36
|
+
export rvm_reload_flag=1
|
37
|
+
export rvm_prefix=$popo_path
|
38
|
+
export CABLING_PATH=$popo_path/.popo/cabling.yml
|
39
|
+
export CABLING_TARGET=$popo_target
|
40
|
+
source $rvm_prefix/rvm/scripts/rvm
|
41
|
+
|
42
|
+
# Load default rvm
|
43
|
+
rvm default 1>/dev/null 2>&1
|
44
|
+
unset PALMADE_GEMS_DIR
|
45
|
+
export PATH="$popo_path/rvm/bin:$popo_path/tools:$PATH"
|
46
|
+
export rvm_path=$popo_path/rvm
|
47
|
+
if [[ -z "$PS1" ]] ; then
|
48
|
+
rvm $*
|
49
|
+
else
|
50
|
+
echo ""
|
51
|
+
echo "Welcome to the popoed bash environment, where you can play with your very own popo."
|
52
|
+
echo ""
|
53
|
+
echo " popo path: $popo_path"
|
54
|
+
echo " popo target: $popo_target"
|
55
|
+
echo ""
|
56
|
+
echo "Remember to keep things clean and civil around here."
|
57
|
+
echo "To go back to your normal world, just hit exit."
|
58
|
+
echo ""
|
59
|
+
echo "But wait, you ask, who needs popo? Baahh, popo's for n00bs!"
|
60
|
+
echo ""
|
61
|
+
fi
|
data/targets/beta.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# BETA target
|
data/targets/common.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# COMMON TARGET
|
@@ -0,0 +1 @@
|
|
1
|
+
# DEVELOPMENT TARGET
|
@@ -0,0 +1 @@
|
|
1
|
+
# PRODUCTION TARGET
|
data/targets/staging.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# STAGING TARGET
|
data/targets/test.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# TEST TARGET
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: popo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jan Mendoza
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-01-01 00:00:00 +08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: sequel
|
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
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sqlite3
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: cableguy
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id003
|
59
|
+
description: Ruby and rails repo tool
|
60
|
+
email:
|
61
|
+
- poymode@gmail.com
|
62
|
+
executables:
|
63
|
+
- envy
|
64
|
+
- popo
|
65
|
+
extensions: []
|
66
|
+
|
67
|
+
extra_rdoc_files: []
|
68
|
+
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- README
|
73
|
+
- Rakefile
|
74
|
+
- bin/envy
|
75
|
+
- bin/popo
|
76
|
+
- config/envy.yml.sample
|
77
|
+
- config/popo_config.yml.sample
|
78
|
+
- lib/hash.rb
|
79
|
+
- lib/popo.rb
|
80
|
+
- lib/popo/constants.rb
|
81
|
+
- lib/popo/database.rb
|
82
|
+
- lib/popo/git_utils.rb
|
83
|
+
- lib/popo/initializer.rb
|
84
|
+
- lib/popo/runner.rb
|
85
|
+
- lib/popo/rvm.rb
|
86
|
+
- lib/popo/sync.rb
|
87
|
+
- lib/popo/utils.rb
|
88
|
+
- lib/templates/envy.yml
|
89
|
+
- popo.gemspec
|
90
|
+
- script/Rakefile
|
91
|
+
- script/envy
|
92
|
+
- script/envyrc
|
93
|
+
- script/poporc
|
94
|
+
- targets/beta.rb
|
95
|
+
- targets/common.rb
|
96
|
+
- targets/development.rb
|
97
|
+
- targets/production.rb
|
98
|
+
- targets/staging.rb
|
99
|
+
- targets/test.rb
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: ""
|
102
|
+
licenses: []
|
103
|
+
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project: popo
|
128
|
+
rubygems_version: 1.3.7
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: Popo ruby and rails repo tool
|
132
|
+
test_files: []
|
133
|
+
|